Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
67 views

Java Booklet Oct-Nov2019

This document provides an overview of topics to be covered in an introduction to programming languages course, including introductions to programming languages, assemblers, compilers, interpreters, C, C++, Java, and the Java development kit. It outlines subtopics such as program structure, data types, control flow statements, and iterations. It includes examples of homework, in-class, and interview questions related to these topics.

Uploaded by

Sarthak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Java Booklet Oct-Nov2019

This document provides an overview of topics to be covered in an introduction to programming languages course, including introductions to programming languages, assemblers, compilers, interpreters, C, C++, Java, and the Java development kit. It outlines subtopics such as program structure, data types, control flow statements, and iterations. It includes examples of homework, in-class, and interview questions related to these topics.

Uploaded by

Sarthak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

Topic: Introduction

SUbtopics:
1) IntroDUCTion to Programming LANGUAges
2) Need to learn Programming LANGUAges
3) Concept of Assembler, Compiler, Interpreter
4) C vs C++ vs Java
5) What is Java
6) History of Java
7) JDK,JRE,JVM
8) How To set Path
9) Installation of Eclipse

C/W Assignments:
Tip: Trainers will assist for these questions.

1. Installation of Eclipse.
2. How to Use Notepad, Eclipse Editor
3. How to set path.
H/W Assignments:
Tip: Trainers will not assist for these questions.
1. Installation of Eclipse.
2. How to set path.
Interview QUESTions:
1) What are Programming languages?
2) What is the difference between compiler and interpreter?
3) What are the differences between C, C++ and Java?
4) What do you know about Java?
5) When and by whom was Java Developed?
6) What is the difference between JDK, JRE, and JVM?

1|Page
Topic: Basics Of Java

SUbtopics:
1) FeatUREs of Java
2) What is a program
3) Comments, Data Types
4) Literals, Identifiers
5) Operators
6) Program strUCTURE
7) Hello world program

C/W Assignment:
Tip: Trainers will assist for these questions.

1. Write a program to two numbers and perform sum of two numbers.


2. Write a program to calculate Simple Interest.
3. Write a program to convert days into years, weeks and days.{Hint: Input-373 days
Output-1Year,1Weak,1day}
4. Write a program to calculate Compound Interest.
5. Find the output of following series (Feb Monthly)
int k = 2;
System.out.println(k++ - ++k + k-- - k++ + ++k -k-- + --k + k+ k--- k + --k+k++);

H/W Assignment:
Tip: Trainers will not assist for these questions.

1. Write a program to calculate area of an equilateral triangle.


2. Write a program to enter marks of five subjects and calculate total, average and
percentage.
Interview QUEstions:
1) What gives Java its 'write once and run any where' nature?
2) Why is Java platform independent?
3) Explain the structure of a program.
4) Why comments are used in a program?
5) What are data types?
6) What are variables? What are the rules to name a variable?
7) What are keywords? Name few.
8) What are identifiers and literals?
9) What are operators?
10) Name different types of operators.
11) Explain public static void main (String args[]).
12) Can we execute a program without main ()method?
13) What are the types of relational operators in Java?
14) What are the logical operators in Java?
15) What are called as Arithmetic operators?
16) State the name of / and % operator and explain how will you use this?
17) Which are the two relational operators that are called as equality operators? Give an
example.
18) How will you represent increment and decrement operators?
19) What is a ternary operator? Give an example.
20) State the use of instance of operator. Give an example.
21) Discuss the significance of the Java language.
22) Elaborate briefly upon the evolution of Java.
23) Compare in brief C/C++, C#, and Java.
24) Elaborate on the main features of Java.
25) What is the difference between the prefix increment ++x and the postfix increment x++?
26) What is a Byte code?
27) What are the various Operators used in Java?
28) What is a White space in Java?
Topic: Control Statements

SUb-Topics:
1) Types of Control statements
2) IntroDUCTion to Conditional Statements
3) Use of Scanner class.
4) Conditional statements:
i. If
ii. If-else
iii. Nested if-else
iv. If-else if
v. Switch
5) Ternary operator
C/W Assignment:
Tip:Trainers will assist for these questions.
1) How to accept different types of data using Scanner class.
2) Write a program to input week number and print weekday.
3) Write a program to input basic salary of an employee and calculate its Gross salary
according to following:
a. Basic Salary <= 10000 : HRA = 20%, DA =80%
b. Basic Salary <= 20000 : HRA = 25%, DA =90%
c. Basic Salary > 20000 : HRA = 30%, DA =95%
4) Write a program to input electricity unit charges and calculate total electricity bill
according to the given condition:
a. For first 50 units Rs. 0.50/unit
b. For next 100 units Rs.0.75/unit
c. For next 100 units Rs. 1.20/unit
d. For unit above 250 Rs.1.50/unit
e. An additional surcharge of 20% is added to the bill
H/W Assignment:
Tip: Trainers will not assist for these questions.

1) Write a program to find maximum among three numbers.


2) Write a program to check whether a number is even or odd.
3) Write a program to check whether a number is negative, positive or zero.

4|Page
4) Write a program to find maximum and minimum between two numbers.
5) Write a program to input any alphabet and check whether it is vowel or consonant.
6) Write a program to check whether a character is uppercase or lowercase alphabet.
7) Write a program to check whether the triangle is equilateral, isosceles or scalene
triangle.
8) Write a program to calculate profit or loss.
9) Write a program to find all roots of a quadratic equation.
10) Write a program to create simple calculator using switch case.
11) Write a program to input any character and check whether it is alphabet, digit or
special character.
12) Write a program to check whether a year is leap year or not.
13) Write a program to input marks of five subjects Physics, Chemistry, Biology,
Mathematics and Computer. Calculate percentage and grade according to following:
a. Percentage >= 90% : Grade A
b. Percentage >= 80% : Grade B
c. Percentage >= 70% : Grade C
d. Percentage >= 60% : Grade D
e. Percentage >= 40% : Grade E
f. Percentage < 40% : Grade F

Interview QUEstions:
1) What are control statements?
2) What are conditional statements?
3) Explain different types of conditional statements.
4) What is the difference between if else if and switch?
5) Explain the use of break.
6) What is ternary operator? Give an example.
7) What are called Decision statements in Java?
8) How will you legally define "if else" statement. Give an example.
9) What is the use of "break" and "continue" statements?
10) What do the break and continue statements do?
Topic: Iterations

SUb-Topics:
1) IntroDUCTion to Iterations
2) While
3) Do-while
4) For
5) Break
6) ContINUe
C/W Assignment:
Tip:Trainers will assist for these questions.

1) WAP to print Fibonacci series in forward and reverse order.


Example: Series for8termswillbeasfollows:0,1,1,2,3,5,8,13 and 13,8,5,3,2,1,1,0 (Feb
Monthly).
2) Write a Java program to find power of any number x ^y.
3) WAP to print following Pattern
*****
****
***
**
*
4) WAP to print following
Pattern

1 2 3 45
2345
345
45
5
45
345
2345
1 2 3 45

5) Write a program print series of n numbers .1,2,5,8,13,18,25,32(Feb


Monthly)
6) WAP to print following

ABCDEFGFEDCBA

ABCDE FEDCBA

ABCDE EDCBA

ABCD DCBA

ABC CBA

AB BA
A A

7) Write a Java program that prints 1 to 20. The numbers should be displayed as: a)For
multiples of 3 print "Fast" instead of the number

b) Forthe multiples of five print "Slow".

c) For numbers which are multiples of both three and five print "Fast & Slow".

Also print count of how many times “Fast” was printed, “slow” was printed and "Fast &
Slow “was printed.(Feb Monhly)

H/W Assignment:
Tip:Trainers will not assist for these questions.
1) Display numbers from 1 to 100 using different loops.
2) Write a program to create table of a number.
3) Find if given number is prime or not.
4) Calculate factorial of a number.
5) Count number of digits of any number.
6) Find sum of all digits of a number.
7) Display all even and odd numbers from 1 to100.
8) Find out given number is palindrome or not.
9) Display all elements between 400 to 500 (both numbers excluded) ending with
seven.{Hint: output-407,417,427….}
10) Write a menu driven program to find all prime, even and odd numbers between 1 to 100
using switch case
11) WAP to print following Pattern

*
**
***
7|Page
****
*****
12) Write a java program to generate a following
triangle.
1
12
123
1234
12345
13) WriteaprograminJavatomakesuchapatternlikeapyramidwithanumberwhichwillrepeatthen
umber in the same row.
1
22
333
4444
55555
14) WAP to print following Pattern

A
A
B
AB C
A B CD
ABCDE
A B C D EF
15) WAP to print following
Pattern

1
21
321
4321
54321

16) WAP to print following Pattern


1
23
456

8|Page
7 8 9 10

9|Page
11 12 13 14 15
17) WAP to print following
Pattern

1 0 1 01
0 1 0 10
1 0 1 01
0 1 0 10
1 0 1 01
18) Write a program in Java to print the Floyd's
Triangle.
1
01
101
0101
10101

18) Write a java program to generate following pattern.


*
***
*****
*******
*********
*******
*****
***
*

19) WAP to print following Pattern


1
10
101
1010
10101

20) Write a Java program to display the pattern


1
212
32123
4321234
21) Given a number, the task is to check if it is Kaprekar number or not. A Kaprekar
number is a number whose square when divided into two parts and such that sum of
parts is equal to the original number.[5M](April Monthly).
22)WAP to print the following pattern: (Feb Monthly).
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Good To Have:
1. Write a Java program to print the first 15 numbers of the Pell series. In mathematics, the
Pell numbers are an infinite sequence of integers. The sequence of Pell numbers starts
with 0 and 1, and then each Pell number is the sum of twice the previous Pell number
and the Pell number before that.: The first few terms of the
sequence are : 0, 1, 2, 5, 12, 29, 70, 169, 408, 985, 2378, 5741, 13860,… (Feb
Monthly).
2) Write a java program to print the following Series is :
1 -3 -5 -7 9 -11 -13 15 - 17 -1921 (Feb Monthly).
3) Write a java program or function to check Harshad number (or Niven number). Your
program should take one positive integer from the user as input and check whether this
integer is Harshad number (Niven number) or not.Harshad number or Niven number is
a number which is divisible by the sum of its digits. For example,21 is a Harshad
number because it is divisible by the sum ofits digits.21 –
> sum of digits –> 2+1 = 3 and 21 is divisible by 3 –> 21/3 = 7.(Jun Monthly).

4) Write a Java program to display the following pattern


1
12
123
1234
12345
123456
1234567
123456
12345
1234
123
12
1

Interview
QUESTions:
1) What are different types of loops?
2) What is the difference between while and do-while loop?
3) What are the looping constructs in Java?
4) Can you create a 'for 'loop without any conditional expressions?
Topic: OOPs

SUb-Topics:
1) IntroDUCTion
2) Classes &Objects
3) Creation of class and conventions for creating a class
4) Elements of classes
5) Local, instance and static variables
6) Creating objects
7) IntroDUCTion to OOPs methodologies
8) Wrapper classes

C/W Assignment:

Tip:Trainers will assist for these questions.


1) WAP to display how to create a class and create different elements of a class(data
members and member functions etc).
Also create objects of that class for accessing different elements to explain the concept
of classes and objects.
2) Create a class AdditionDemo having 3 instance variables number1 ,number2 and
result. Create 4 methods as a) addition b)subtraction c)multiplication d) division.
Calculate different operations as per the methods determined above. Create objects of
AdditionDemo from main method of another class Addition.

H/W Assignment:
Tip: Trainers will not assist for these questions.
1) Write a program to enter temperature in °Celsius and convert it into °Fahrenheit and vice
versa.
2) A company provides bonus of 20% to their employees if his/her year of service is
more than 3 years. Create a class and its respective methods to enter the data from
the user and calculate net salary of the employee based on the year of service of the
employee served in that company.
3) A kids laptop manufacturer company needs to develop a laptop for kids which will
display a message first,
Enter Option:
a. Add-1
b. Subtract-2
c. Multiply-3
d. Quit-4
i) The kid should be allowed to enter an option. If the kid enters 1, a
message needs to be displayed,
ii) “Enter two numbers to be added”.
a. The kid should be allowed to enter two numbers (In two separate lines).
b. Based on the numbers entered, the program should add and display the
result as below
c. “The result is<result>”
d. After the result is displayed, the program should loop back and ask for
the next menu entry. If the kid enters 4, the program should quit. (The
program needs to be executed and do either one of the options until
the kid enters the option4)

Interview QUEstions:
1) What is the difference between object oriented programming language and object
based programming language?
2) What are the Oops methodologies?
3) What is a Class?
4) What is an Object?
5) What is Scanner class?
14|Page
6) What is new?
7) What is the purpose of wrapper classes?
8) What are the wrapper classes available in Java?
9) What do you mean by autoboxing andauto-unboxing?

15|Page
Topic: Access Modifiers

SUbtopics:
1) Introduction to access modifiers
2) Public
3) Private
4) Default
5) Protected
C/w Assignments:
1. Problem Statement:
2. Follow the instructions:
a) Create a class EmployeeDemo
b) Create 4 variables with the modifier as
emp_id(protected),emp_name(public),emp_salary(private),emp
_dept(deault).
c) Create 4 methods with the signatures as
Public void doPublic(),default void doDefault(),protected void
doProtected(),private void doPrivate().
d) Initialize these variables by entering data from the user and
display the data of the employee.
e) Access all the variables from these 4 methods to check the
visibility and scope of variables.
f) Perform the above tasks in same package,same class and in
different package in different class.
Topic: Methods

SUb-Topics:
1) IntroDUCTion
2) STRUCtURE of method
3) Non-parameterised method with noretUR Type
4) Non-parameterised method with retURN Type
5) Parameterised method with no retURN Type
6) Parameterised method with return Type
7) Conventions in methods
8) Method overloading
9) Static methods
C/W Assignment:
Tip:Trainers will assist for these questions.

1) Write a program to create a class Student and do the following:


a) Create a method to input data (rollNo, Name, contactNo, Total marks)
b) Create another method to display the data of Student class.
c) Create object of Student class and access these methods main method
of a new class –StudentDemo.java.
2) Write a program to show method overloading by performing following steps:
Create a class to print the area of a square, a rectangle and a triangle. The class
has3 methods with the same name but different number of parameters. The method
for printing area of rectangle has two parameters which are length and breadth
respectively, for printing the area of triangle method has 3 parameters and while
the other method for printing area of square has one parameter which is side of
square.

3) Write a program to copy values of one object to another object and assign the
values of one object to an other.
4) Create a class Account containing
following methods : insert() to insert
accountdata
display() to display account
information deposit() to deposit
amount
withdraw() to withdraw
amount checkbalance()to
check balancee.g.
class Account{
intacc_no;
String
name;
float
amount;
}
H/W Assignment:
Tip: Trainers will not assist for these questions.
1) Create Mydate class which have 3 instance variables (day, month, and year).Create two
methods setDate() and displayDate() for Mydate class where write a logic for assigning
some values to instance variable in setDate and display logic in displayDate()method.
2) Create one class Cube having instance variables (height, width, depth). Add one
method to calculate volume of the cube with return type void .
3) Write a progam to create Calculator class which have methods addition(int
num1,int num2),subtraction(int num1,intnum2), multiplication(int num1, int
num2), division(int num1, int num2) with return type double .Create a menu
driven program and do perform these operations of a calculator by creating an
object of this class and execute these methods from main method of another
class.
4) Write a program to find the smallest number among three numbers using method
5) Create 4 overloaded methods for “test ()” and invoke all versions of the overloaded
methods.
a. Create another class Overload.java which has a main method to call the
overloaded methods inOverloadDemo.java
6) Create one class Box having instance variables (height, width, depth). Addone method to
calculate volume with double returntype.
7) Perform thefollowing:
Class Name:-Calculator
Method Name:- CalculateSum
Method Description:-Calculates the sum of two Numbers
Argument:-int number1, int number
Return Type:- int – Sum
Logic:-Calculate the sum of the two numbers number1 nad number2 and
return the sum.

Method Name:-Calculate Difference


Method Description:-Calculates the difference between two numbers
Argument:-int number1 , int number2
Return Type:-int – difference
Logic:-Calculate the difference between the numbers number1 and number2 and return the
difference.
17 | P a g e
8) Perform thefollowing:
Class Name:-MessagePrinter
Method Name:-printMessage
Method Description:-Prints the message
Argument:-String name
Return Type:-Void
Logic:-Print the message using the console
output command.

9) Create a Java class “Square.java” with a method “calculateArea”


This method should accept length as an argument, calculate the area and return the area.
The main method should invoke the Square objects “calculateArea” method by
passing a value for the length, say 20.
The main method should also print the area (result).

Interview QUEstions:

1) What are methods?

What is meant by MethodOverloading?


What are Method Overloadingrules?
Is java Pass by Reference or Pass byValue?
What are the features we need to know while invoking
overloaded

18|Page
Topic: Constructors

SUb-Topics:
1) IntroDUCTion
2) STRUCtURE and Use of constrUCTors
3) Difference between methods &constrUCTors
4) Parameterised constrUCtors
5) Non-Parameterised constructors
6) Polymorphism
7) ConstrUCTor overloading
8) Use of this
9) Encapsulation
10) Inner Classes
C/W Assignment:
Tip: Trainers will assist for these questions.
1) Create a class Vehicle with member variables: String Color, int noOfWheels,int
noOfGears. Initialize these variables by giving values. Create another constructor which
takes 2 arguments(Color and noOfGears), calls the default constructor using this () and
hasaSOPinit“Iam a constructor calling constructor 1”.Inmainmethod,createanobjectoftype
Vehicle by using default constructor. Note the output. Create another object of type
Vehicle by using the parameterized constructor. Note the sequence of data indicating that
inner most constructors are called first.
2) Declaring and using constructors
Create a class Circle.java in a package “com.HefShine.shapes” , add a float
instance variable radius and add a default constructor (Constructor 1) for the class.
This constructor should initialize the radius to a default value 1.5f.
The above constructor should be invoked from a main method from another class,
Shape.java (in different package com.HefShine. geometry).
3) Create a class Test with constructors to initialize the variables and methods to
perform the following tasks. Give appropriate args to methods. Methods should
perform following programs:
a. Even odd
b. Factorial of a number using do-while loop.
c. Find sum of all digits of a number
4) Write a demo program for different types of Inner Classes.

H/W Assignment:
Tip: Trainers will not assist for these questions.
1) Create class Employee with constructors (default and parameterized), methods (1
with return type (calculating salary), 1 without return type (displaying employee data)).
2) Create a class named 'Rectangle 'with two data members- length and breadth and a
method to calculate the area which is 'length*breadth'. The class has three constructors
which are:
1 - having no parameter - values of both length and breadth are assigned zero.
2 - Having two numbers as parameters - the two numbers are assigned as length and
breadth respectively. 3 - Having one number as parameter - both length and breadth
are assigned that number.
Now, create objects of the 'Rectangle' class having none, one and two parameters and
print their areas.
3) Create a class Bank .Initialize an instance variable ” amount” with an initial amount
of Rs.5000 and assume you have to add some more amount to it. Now make two
constructors of this class as follows:
1 - without any parameter - no amount will be added to the Bank
2 - having a parameter which is the amount that will be added to
Bank Create object of the 'AddAmount' class and display the final
amount in Bank

20 | P a g e
4) Create a class named 'Programming'. While creating an object of the class, if nothing is
passed to it, then the message "I love programming languages" should be printed. If
some String is passed it, then in place of "programming languages" the name of that
String variable should be printed. For example, while
creating object if we pass "Java", then "I love Java" should be printed.

5) Create a class Employee with int id and String name as member variables. Initialize
these variables using getter and setter methods by taking data from the user. Create
object of this class and access these methods from the main method of another class.
Also provide different values to observe the changes.
10 ) Create a class ShapeCircle.java and do the following steps:
a) Add an instance float variable pi and create two overloaded constructors.
Constructor 1- with a float argument name radius. The constructor should
initialize the class variable radius with the method argument radius. The
instance variable and the method argument should be named same as “radius”.

b) Constructor 2- with two float arguments radius and pi. Default the class pi value to
3.5 and set the instance variable with the radius method argument.
c) The constructor “constructor 2” should be invoked from a main method from class,
Area.java (in a packagecom.HefShine.shapes).

d) In Circle.java, invoke the Constructor 2 created in the previous step from


Constructor 1.
6) Create two methods and calculate area and
circumference of a Circle In the Circle.javaclass,
create two methods as listed below
a. Method 1 – calculate CircleArea should accept the float radius as parameter
and calculate the area (pi*r*r). It should return the result value to the main

21|Page
method where it should be printed in the console.
b. Method 2 – calculate Circumference should accept float radius as parameter and
calculate the circumference (2 * pi * r). It should return the result value to the main
method where it should be printed in the console.
Call these two methods from the main method in Circle.java by passing appropriate
parameters.
7) WAP to demonstrate different types of Inner Classes .Create class College as
a Outer Class and Department as a Inner Class. Use appropriate Variables and
Methods.
Interview QUEstions:
1) What are constructors?
2) What is the difference between methods and constructors?
3) Explain default constructors.
4) Can a class have multiple constructors?
5) What are the rules to define a constructor?
6) Explain the use of ‘this’ keyword.
7) What is an Inner class?
8) What are the types of classes available in Java?
9) Write two lines of code which will instantiate the inner class from the outer class.
10) Write two lines of code and explain how will you implement an anonymous inner class.
11) Explain about Static Nested classes.
12) What are the valid modifiers of an inner class?
13) How will you define a constructor? Give an example.
14) What is the benefit of reference variable? Give an example.
15) What are the possible access modifiers for a constructor?
Topic: Inheritance

SUb-Topics:
1) IntroDUCTion
2) Single inheritance
3) MULtilevel inheritance
4) MULtiple inheritance
5) Hierarchical inheritance
6) Hybrid inheritance
7) Use of SUPEr ,final

C/W Assignment:
Tip: Trainers will assist for these questions.
1) Write a Meaningful program displaying the concept of different types of inheritance.
2) Create a class named ‘Worker’ having the following members: Sname, Sage, Sphone number ,Saddress,Ssalary.It also has a method named
'displaySalary' which displays the salary of the members. Two classes 'Employee' and 'Manager' inherit the ‘Worker’ class. The 'Employee' and 'Manager'
classes have data members 'Work specialization' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee
and a manager by making an object of both of these classes and print the same.
3) Show use of Multi Level Trainers in case of library Management System(Feb Monthly).

H/W Assignment:
Tip: Trainers will not assist for these questions.
1. Create Parent class having method which prints "This is parent class",Create subclass "This is child
class". Call

a)- method of parent class by object of parent class


b) - method of child class by object of child class
c) - method of parent class by object of child class
2. Test any 3 Examples of MultiLevel Trainers.
3. WAP for Department class having id, name. Create Student class having roll, name and Department
to object should have id and name. Assign and print individual values in main method

4. Explain one example of hierarchical Trainers.


5. Create Class Laptop having variables noOfUSBPort, processorSpeed of type int. Generate getter,
setter methods for the variables.In main method, create Laptopobject set values ofvariables
noOfUSBPort, processorSpeed using setter methods. Display noOfUSBPort, processorSpeed using
getter methods.
6. Create class IPLTeam having play (). Create child classes of IPLTeam called asCSK, RCB. Inmain,
call methods of parent class from child classobjects.
7. WAP to create a class KidBook with method readBook() and another method readBook () with 2
parameters. The method readBook here is over-loaded.Create a class BigKidBook which extends
KidBook created above. Implement readBook() differently in BigKidBook class. Here the method
readBook() hasbeenover-ridden in the child class BigKidBook.
8. WAP for final class, final variable and final method

9. WAP to check whether you can inherit static variable of Parent class in Child class
10. Scenario:In a company there are employees with two designations Manager and Trainee.
Bothemployees share the same set of attributes and basic salary calculation logic is same but the basic
salary of trainee and manager are different.
The Manager has a travel allowance equal to 15% of the basic salary, whereas all the other employees
the travel allowance is 10% of the basic salary. Write a program to maintain the entities using
Trainers.
11. Problem Statement on above scenario
a. Create a class Employee with the following instance variables.
Instance variables Data type
employeeId Long
employeeName String
employee Address String
employee Phone Long
basicSalary Double
specialAllowance double default value-
250.80
Hra double, default value-
1000.50

b. Create an overloaded constructor in the employee class, which takes the below constructor
parameters and initializes them to their respective instance variables.
Constructor Instance Variable
parameter
Id employeeId
Name employeeName
Address employeeAddress
Phone employeePhone

c. Create a method calculateSalary in which the basic salary needs to be calculated as below. salary =
basicSalary + (basicSalary *specialAllowance/100) + (basicSalary *hra/100); The calculated salary
shouldbedisplayed in theconsole.
NOTE: salary is a local variable.
d. Create the sub classes Manager and Trainee with base class Employee. Create overloaded
constructors which takes the below parameters and initializes them to the irrespective variables in the
super class
Constructor Instance Variable
parameter
Id employeeId
Name employeeName
Address employeeAddress
Phone employeePhone
Salary basicSalary

e. Create a class “TrainersActivity.java” with a main method which performs the below functions
12. Problem Statement on above scenario
a. Add a method called calculateTransportAllowance in Employee class which shouldcalculate the
transport allowance by calculating 10% (default allowance)ofthe salary. Print the salary after
calculating.
transportAllowance = 10/100*basicSalary.
b. Fora manager, the transportation allowance is 15%ofthe basic salary. So override the calculate
Transport Allowance method in Manager class which should calculate the transport allowance as
15%ofthe base salary. Print the salary after calculating.

transport Allowance = 15*basicSalary /100.


c. Fora trainee, the transport allowance is same as the default allowance; the method calculate
Transport Allowance in the base class can be used.
d. Invoke the calculate Transport Allowance for the manager and trainee class in the main method
ofTrainersActivity.java.

24 page
Interview QUEstions:
1) Explain difference between single and multilevel inheritance.
2) Why java does not support multiple inheritance?
3) What is final?
4) What is hierarchal inheritance?
5) What do you understand by the keyword super?
6) What are the benefits of inheritance?
7) Write a code that uses inheritance concept.
8) What are the types of inheritance relationships
9) Is it possible to extend more than one class? State the reasons.
10) How does a subclass call a constructor defined. in its super class?
11) In what order are constructors called in a: class hierarchy?.
Topic: Containment (Object under object)

SUbtopics:

1. Structure &Need
2. Difference

C/W Assignment:
Tip:Trainers will assist for these questions.
1. WAP to having Department class with id, name . Student class has roll, name and Department
object should have id and name. Assign and print individual values in main method
2. WAP to use containment for following hierarchy.

College: college_id name


Departents: dept_id name
Subject:sub_id name
Topic: topic_id name
SubTopic:subtopic_id name
Question:question_id name

H/W Assignment:
Tip:Trainers will not assist for these questions.
1. Create class Person having FullName, Address,gender, age.FullName is class having
firstname,middlename,surname. Address is class which having city, state, country. Display Persons
data Note. Containment using constructor .
2. Create Employee class which has attributes (id, name, salary, Dept, Date).

Where dept class(dept_id,dept_name) and Date(day,manth,year)


Display Employee information.
Topic: Abstraction& Interfaces
SUb-Topics:
1) IntroDUCTion
2) Abstract methods
3) STRUCtURE& need of abstract classes
4) Abstract classes
5) STRUCtURE& need of interfaces
6) Difference between abstract classes &interfaces
7) Extending Interfaces
8) Interface Java 8featUREs
9) Packages
C/W Assignment:
Tip: Trainers will assist for these questions.
1) Explain any example of abstract class.
2) WAP to create a class Machine with method rotate() and an abstract crush(). Class Juicer is child
class of Machine and implements method crush. Add another filter() in the class Juicer. In main
method,
a. Using Juicer Object calls its crush, rotate and filter methods.
b. Using Juicer Object with reference variable of Machine I.e Machine m = new Juicer().Check the
methods available to m.
3) Create abstract class Mixer which extends the abstract class Machine, having method crush
implemented and additional concrete method blend. Using Mixer Object, Call rotate(), blend() and
crush().
4) Show one example of interface.
5) WAP to create and use classes from different Packages.

H/W Assignment:
Tip: Trainers will not assist for these questions.
1. Create 2 abstract classes Abstract1and Abstract2 each with different implemented methods
doAbstract1() and doAbstract2() respectively. Check if you can create a class Demo which extends
both the abstract classes. (Note- A class cannot extend 2 classes simultaneously)
2. Check following scenario.
a. Check Can we create an object of an abstract class?
b. Check Can we declare a class abstract with no methods in it?
c. Check Can we declare a class abstract even if it does not have any abstract method?
d. Check Can we declare an abstract class which has both abstract as well as implemented methods?
e. Check Can a class extend 2ormore abstract classes?
f. Check Can an abstract class extend 2ormore abstract classes?
g. Check Can an interface extend 1ormany abstract classes?
h. Check Can an abstract class implements 1ormanyinterface?
3. WAP to create an abstract class Parent. Add an abstract method1()in it which has only definition
and one method method2() which has implementation. Create non abstract Child class which extends
Parent and add the missing method implementation. In main, use both the methods by creating
instance of the concrete class.
4. Using super keyword invokes parent’s parameterized constructor from Child class constructor.
5. Create interface Cake with a method declared as bake. Create 2 classes Strawberry, BlackForest
both implementing Cake interface Create interface IceCream with method eat and Juice with method
drink. Create class Mango which implements both interfaces.
6. A library needs to develop an online application for two types of users/roles, Adults and children.
Both of these users should be able to register an account. Any user who is less than 12 years of age
will be registered as a child and they can borrow a “Kids” category book for 10days,whereas an adult
can borrow “Fiction” category books which need to be returned within 7days.
Note: In future, more users/roles might be added to the library where similar rules will been forced.
Develop Interfaces and classes for the categories mentioned above.
a. Create an interface Library User with the following methods declared
Method Name
registerAccount
requestBook

The methods in the KidUser class should perform the following logic.
i. registerAccount : if age < 12, a message displaying “You have successfully registered under a Kids
Account” should be displayed in the console.
If(age>12), a message displaying, “Sorry, Age must be less than 12 to register as a kid” should be
displayed in the console.
ii. requestBook: if book Type is “Kids”, a message displaying “Book Issued successfully, please return
the book within 10days”shouldbedisplayed in the console. else, a message displaying, “Oops, you are
allowed to take only kids books” should be displayed in the console.
e. The methods in the Adult User class should perform the following logic.
i. registerAccount : if age > 12, a message displaying“ You have successfully registered under an
Adult Account” should be displayed in the console.

If age<12, a message displaying, “Sorry, Age must be greater than 12 to register as an adult” should be
displayed in the console.
ii. request Book: if book Type is “Fiction”, a message displaying “Book Issued successfully, please
return the book within 7days”shouldbedisplayed in the console.

else, a message displaying, “Oops, you are allowed to take only adult Fiction books” should be
displayed in the console.
f. Create a class “LibraryInterfaceDemo.java” with a main method which performs the below
functions
7. WAP to create Package arithmetic having classes Addition, Subtraction, Division ,Multiplication
with appropriate methods .Use this Classes outside the package.
Interview QUEstions:

1. What do understand by abstraction?


2. What are abstract classes and abstract methods?
3. Explain interfaces?
4. How multiple Trainers is achieved using interfaces?
5. What is the difference between abstract class and an interface?
6. Does an abstract class contain non-abstract methods?
7. Can we use default when we override methods of an interface?
8. Can an abstract method have a body?
9. Can you create an object of an abstract class using ne
Topic: Arrays

SUb-Topics:
1. IntroDUCTion
2. Declaration, initialization of array
3. Single dimensional array
4. for each
5. Operations on array: searching, sorting
6. Two-dimensional array
7. Array of objects
C/W Assignment:
Tip:Trainers will assist for these questions.

1. Write a program to enter elements and perform binary search.


2. WAP sort array elements in ascending order using selection sort.
3. Create class Dept(did, dname), class MyDate(day, month,year)
Class Employee(emp_id, emp_name, salary, MyDate (object), dept(object)). Create
array of Employee and display the array elements.
4. WAP to print minimum in columns. Means e.g. arr[][]={{22, 31, 9}, {12, 5,16}, {34, 42,
2}} output is: 12, 5,2.
5. Write a Java program to arrange the elements of an given array of integers where
all positive integers appear before all the negative integers.
6. WAP to create transpose of a matrix (transpose is converting rows to columns)and print
it.

7. Number of unique pairs in an array. Give nan array of N elements , thet ask is to
find all the unique pairs that can be formed using the elements of a given
array.(March Monthly).

Examples: Input: arr[] = {1, 1, 2}


Output: 4
(1, 1), (1, 2), (2, 1), (2, 2) are the only possible pairs.

Input: arr[] = {1, 2, 3}


Output: 9

8. WAPtoprintouterelementsof2DarrayofnXn..

9. WAP to find the average of the inner most elements of an array

10. Create or implement stack in java using array as underlying data


structure. (Jun Monthly)
H/W Assignment:
Tip:Trainers will not assist for these questions.
1. WAP to create 1D array and accept data in that array. Calculate the average value of array
elements.
2. WAP to insert an element in a specific position into an array.
3. WAP to merge 2 arrays to 3rd array.
4. WAP to print reverse of an array using temp variable.
5. WAP to print reverse of an array without using temp variable.
6. WAP sort array elements in ascending order using bubble sort.
7. WAP to print all negative elements in an array and also count total number of
negative elements in an array.

8. WAP to put even and odd elements of array in two separate arrays.
9. WAP to find the maximum and minimum value in an array.
10. WAP to find the second smallest element in
an array.

11. Write a Java program to test the equality of


two arrays.
12. WAP to print the details of employees from Employee[] array who has same salary
(Create Employee class which has 3 attributes id, name, salary and add employee
objects to your array)

13. WAP to replace all the 0’s with 1’s in your array. Your array is [26, 0, 67, 45, 0,78,
54, 34, 10, 0, 34].
14. Write a Java program to get the difference between the largest and smallest values in an
array of integers.
15. Write a Java program to separate even and odd numbers of an given array of integers. Put
all even numbers first, and then odd numbers.
15. WAP to accept data in 2D array and print the data.

16. WAP to sum two matrices.


17. Wap to sow the subtraction of two matrices.
18. WAP to show multiplication of two matrices.
19. WAP to print maximum in row wise in 2D array. Means e.g. arr[][] = {{22, 31, 9},{12,
25, 16}} output is: 31 and25.
20. Create Student class having rollno, name, marks. Create 10 objects . Using Array of
Objects display information of student who got highest marks .
Create Class Employee (id,name,Salary).Craete 5 Employess Objects. Display Employee information in
21.

descending order of Salary using Array Of Objects


22. Given an integer array and size of subarray,find the first subarray with leasts average in
single loop. Print first index of subarray and average. (Mindstix) Method signature
Find Firstsub(int arr[], int arr_len, int sub_arr_len)
{
//Your code
}
Exampl
e:
Input:
int arr={3,7,90,20,5,50,40}, k=3
Find Firstsub(arr,7
,3) Output:
Index:3 Avg:25
23. Given 2 character arrays s1 and s2 and another empty character array s3.
Populate s3 by interleaving characters from both s1 and s1(Mindstix)
Method signature
Void interleaved (char[] s1, char[]s2, char[]s1, int s1_len, int s2_len)
{
// Your Code
}
Example:
S1={‘a’,’b’,’c’,’d’};
S2={‘w’,’x’,’y’,’z’};
Output:
S1={‘a’,’w’’b’,’x’’c’,’y’,’d’,’z’}.
24. Write a java program or function to find saddle point of a matrix. Your program
should take input matrix from the user, display the matrix and find the saddle point of
that matrix.Saddle point of a matrix is an element in the matrix whichis smallest in its
row and largest in its column. A matrix can have many or no saddle points.
For example,

6 3 1
9 7 8
2 4 5
In this matrix, 7 is the saddle point. Because it is the smallest in its row (2 nd row) and largest in its
column (2nd column).
25. Given an array of N distinct integer and a sum value S.WAP to find out count of
triplets with sum smaller than given sum value.
Examples:
Array=[5,1,3,4,
7] S=12.
Output :4
Explaination: Below are triplets with sum less than 12
(1,3,4),(1,3,5),(1,3,7),(1,4,5)

26. .WAP to find sum of main diagonal elements


of a matrix. WAP to left rotate anarray.
27. How to pass array as a parameter to method in
java?
28. Find the minimum distance between 2 seeds( m and n) provided in an integer array arr[] of
given length. Array can contain duplicates and negative integers. Assume that both m and n
are different and be present in arr[].
Method Signatue
FindMinDist(int arr[],int arr_length,int m,int n)
{

//your code here


}

Constraints:
1.Do not use any additional data structures. You may use as many as primitive
variables.

Good To Have:
1. Write a Java program to find all the unique triplets such that sum of all the three
elements is equal to a specified number.(April Monthly).
Input-2.
Output- [[1,5,-4],[-2,5,-1]]
Reason: 1+5-4=2& -2+5-1=2 2 is Target ...
3. To Find unique Pair Of Integers in Array whose Sum is Given Number[4M]

Given array : [2, 4, 3, 5, 6, -2, 4, 7, 8, 9]


Given sum : 7
Integer numbers, whose sum is equal to value : (2, 5) (4, 3) (-2, 9) . .(April Monthly).
40|Page

41|Page
Take 10 integer inputs from user and print the following: number of positive numbers
4.

number of negative numbers number of odd numbers number of even numbers


5. Split array arr[] into strictly increasing and decreasing sequences in single loop and without

changing the original order.


Method Signature void splitArray(int arr[]
{
//Your code goes here
}
Example 1 Input: aryl]_ [5, 1, 3, 6, 8, 2, 9, 0, 10]
Output: [1, 3, 6, 8, 9, 10] [5, 2, 0]
Example 2 Input: arr[j = [1, 2, 4, 0, 2]
Output: -1
//No such sequences possible.

Interview QUEstions:

1. What are arrays?


2. What is one dimensional array?
3. How to create and access elements in java?
4. What are two dimensional arrays?
5. What are applications of an array?
6. What are advantages & disadvantages of arrays?

42|Page
Topic: Strings

SUb-Topics:
1) IntroDUCTion
2) ImmUTAble Strings
3) Methods of strings
4) String bUffer class
5) Methods of String BUffer
6) String bUIlder
7) Methods of String BUIlder
8) String vs String bUffer vs String BUilder

C/W Assignment:
Tip:Trainers will assist for these questions.

1) WAP to create strings using new and using literal.


2) Compare string using new operator when.
3) Write a Java program to find length of a string.
4) Write a Java program to concatenate two strings.
5) Write a Java program to compare two strings.
6) Write a Java program to convert lowercase string to uppercase.
7) Write a Java program to copy one string to another string.
8) WAP to split string into 2 tokens where string is “HELLO@WORLD”
9) Write a Java program to find first occurrence of a character in a given string.
10) Write a Java program to trim trailing white space characters in a string
11) WAP to find longest word in the given sentence
12) How do you swap two string variables without using third or temp variable in java
13) Write a Java program to remove all extra blank spaces from a given string.
14) Write a Java program to toggle case of each character of a string.
15) Write a program which creates a String Buffer “This is String Buffer” and performs the
following.
i. Adds the string ”- This is a sample program” to existing string and
display it.
st
ii. Inserts the string “Object” into the existing string at 21 postion and
display it.
iii. Reverses the entire string and displays it.
iv. Replaces the word “Buffer” with “Builder” and display it.

16) Exchange Cipher (String & char)This simple cipher exchanges 'A' and 'Z', 'B' and 'Y',
'C' and 'X', and so on. Write a program called Exchange Cipher that prompts user for a
plaintext string consisting of mix-case letters only. Your program shall
compute the cipher text; and print the cipher text in uppercase. For examples, Enter a
plaintext string: abcXYZ The cipher text string is: ZYXCBA (March Monthly)
H/W Assignment:
Tip: Trainers will assist for these questions.

1) Create String with new operator and without new.


2) Compare string using==.
3) Write a Java program to count occurrences of a character in given string.
4) Write a Java program to trim leading white space characters in a string.
5) Write a Java program to count total number of words in a string.
6) Write a Java program to find first occurrence of a word in a given string.
7) Write a Java program to search all occurrences of a character in given string.
8) Write a Java program to remove all occurrences of a character from string.
9) Returns the lowercase of the string and display it.
10) Write a Java program to remove all repeated characters from a given string .
11) Accept email_id from user and check valid or not(should contain@,.)
12) Accept sentence replace each vowel by next consecutive character.
13) Write a Java program to count frequency of each character in a string
14) Write a Java program to find lowest frequency character in a string.
15) Write a Java program to toggle case of each character of a string
16) Write a Java program to repeat every character twice in the original string.
17) WriteaJavaprogramtogetthecharacteratthegivenindexwithintheString
18) Write a Java program to trim both leading and trailing white space characters in a
string.
19) Add 10 StringBuffer objects in an Array , Count no. Of Palindrome Strings, Display in
Ascending order such Strings
20) Problem Statement1:
Write a program which creates a String “Welcome to Java World” and performs
the following Returns the character at 5th position and display it.
Compares the above String with “Welcome” lexicographically ignoring case differences
and display the result. Concatenates “- Let us learn” to the above string and display it.
Returns the position of the first occurrence of character ‘a’
and display it. Replaces all the occurrences of ‘a’ character
with the new ‘e’ and display it. Returns string between 4 th
position and 10th position and display it.

21) Write a Java program to test methods of String Buffer.

22) 22)Write a Java program to test methods of String Builder.


23)Write a program to sort numbers from String. Also output should be in String.
E.g. if number in String is “2713” output should be “1237”. [3M](April Monthly)

InterviewQUestions:
1) What are Strings in Java? Is string a data type?

2) What are different ways to create string objects?

3) What is String pool?


4) What do you mean by mutable and immutable strings?

5) Why String Buffer is called mutable?

6) Can you create mutable string objects?

7) What is the difference between String Buffer and String Builder class?

8) Why String Buffer and String Builder classes are introduced in java when
there already exist string class to represent the set of characters?
9) What are the various ways of assigning a string literal to a String variable?
10) Which method is used to append a string literal to a String variable?
11) What are the most widely used methods of String class?
12) When will you use String class and when will you use String Buffer?
13) How will you add string to a String Buffer? Give an example.
14) Which class is preferred :String Buffer or String Builder? Why?
15) Is it possible to invoke chained methods in Java? If so, how will you invoke?

44 | P a g e
16) Can you point out the main difference between C/C++ strings and Java strings?
17) Can the contents of strings in Java be changed?

45|Page
Topic: Exception Handling

SUb-Topics:
1) IntroDUCTion
2) Types of Exceptions
3) Using try-catch
4) MULtiple catch claUSes
5) Exception Hierarchy
6) RUntime stack Mechanism
7) DeFAUlt Exception handler
8) Types of exceptions
9) Checked exceptions
10) Partially checked exceptions
11) FUlly checked exceptions
12) Unchecked exceptions
13) Creating own exceptions
14) Throws vs Throw
15) Nested try statements
16) Use of throw, throws &finally
C/W Assignment:
Tip: Trainers will assist for these questions.
1) Show Example of runtime stack mechanism using Arithmetic Exception.
2) Show Example of un time stack mechanism using Arithmetic Exception and handle it using try
catch.
3) Show example on unchecked exception and use multiple catch blocks.
4) Show Example to check whether Unchecked Exception is propagated in calling stack
5) Show the use of finally block.
6) Generate exception to check if still finally block get executed.
7) Generate checked exception and use multiple catch block with Exception handler.
8) Show the usage of throw and throws for checked exceptions.
9) Show the usage of throw and throws for unchecked exception.
10) Show the usage of throw by creating a user defined exception and handle it using try catch.

H/W Assignment
Tip:Trainers will not assist for these questions.
1) Show example to generate any one Exception
2) Show example where only try and finally block is used.
3) Show any one Exception and catch that Exception.
4) WAP to check can we have write an empty catch block?
5) WAP to handle ArrayIndexOutOfBound Exception.
6) WAP to check what happen when Exception is thrown by main method.
7) WAP to check whether checked Exception is propagated in calling stack.
8) Create a class, Demo with a method, division with two int parameters

a. Dividend b. Divisor
This method should divide the dividend by divisor and return the result.
9) This method should also throw an Arithmetic Exception to the calling method.

10) Step 2: Create a class, Throws Demo with a main method

11) The main method should invoke the division method in Demo class.

12) The main method should also catch the Arithmetic Exception thrown by the division method and
print the Exception “Arithmetic Exception is Thrown”

13) The try/catch block should also have a finally block which prints a message “The result
is”<Result>

14) Step 1:Inthe Demo class division method perform the following logic.
a. If Divisor is zero throw a Arithmetic Exception with message “Divisor cannot be zero”
b. This method should throw this Arithmetic Exception.
c. Step 2: The exception thrown needs to be handled in Throws Demo.
d. The main method should catch the Arithmetic Exception thrown by the division method and print
the Exception and print the message in the exception Object.
e. The try/catch block should also have a finally block which prints a message “The result is”

<Result>
15) Scenario: A shopping portal provides users to register their profile. During registration thes ystem
needs to validate the user age above 18 and should be placed in India. If not the system should throw
an appropriate error.
a. Create a user defined exception classes named “InvalidCountryException” &
“InvalidAgeException”
b. Overload the respective constructors.
c. Create a main class “User Registration” , add the following method,
i. registerProfile -The parameter are String userName , int age, Stringcountry.Add the followinglogic
d. if country is not equal to “India” throw a invalidCountryExceptionwitherror

If age < 18 throw a InvalidAgeException with error message“ Useris a Minor”

f. Invoke the method register Profile from the main method with the data specified and see how the
program behaves:

16) Create a menu driven program 1. Try Catch demo 2.Try Multi Catch 3.Try Finally 4.Try Catch
Finally 5. Throw 6.Throws
Interview QUEstions:
1) What is an Exception?
2) What is the difference between error and exception?
3) What is the use of the finally block? Is finally block in java guaranteed to be
called? When finally block is not called?
4) What do you mean by Checked Exceptions?
5) Explain Runtime Exceptions?
6) Which are the two subclasses under Exception class?
7) When throws keyword is used?
8) What things should be kept in mind while creating your own exceptions in Java?
9) What are the exception handling keywords in java?
10) What is an Exception Hierarchy?
11) Which is the parent class of Exception?
12) In which package throwable interface is present?
13) How does Default Exception Handler works.
14) What are different types of exceptions?
15) What are unchecked exceptions?
16) What is the difference between checked and unchecked exceptions?
17) Explain fully checked exceptions?
18) What are partially unchecked exceptions?
19) What is the main use of keyword throw?
20) What is the use of the finally block?
21) How will you define Exception Handling?
22) What are the different types of Exceptions?
23) How will you handle Exception in Java?
24) Write a compilable code using "try"," catch", and" finally"?
25) What is the use of "finally" clause? Give an example.
26) What are the exception types that can be thrown using the "throw" keyword?
27) How will you write a compilable code block using "throw" keyword?
28) Give a one line definition of an exception. What do you mean by checked and unchecked
exceptions?
29) Which class is at the top of the exception hierarchy?
30) Which are the two important sub classes of Throwable?
31) Can you name the all important subclass of Exception?
32) What does the throws clause do?
33) Can you create your own custom exceptions in Java?
34) What do you understand by chained exceptions?
Topic: Multithreading

SUb-Topics:
1) IntroDUCTion
2) Thread lifecycle
3) Creation of threads USing class
4) Creation of thread USing interface
5) Creating mULTiple threads
6) Thread scheDULEr
7) Synchronization
8) Thread priorities
9) Garbage Collection
10) Daemon Thread
11) Methods of thread-Join(),Sleep(),yield()
C/W Assignment:
Tip: Trainor’s will assist for these questions.
1) Display values of MIN_PRIORITY, NORM_PRIORITY and MAX_PRIORITY. Change priorities
of thread
2) WAP to show use of sleep method.
3) WAP to set & get priorities of a thread.
4) WAP to give example of daemon thread.
5) WAP to give the implementation of a thread and pausing of a thread till completion of main thread
using yield ().
6) WAP to execute displaying that main thread calls join() and wait() for the child thread to get
executed first and then gets completed by writing two threads main and child thread
7) What is deadlock? Give one example of deadlock.
8) A consumer threads consumes chocolates from a basket, producer thread produces fixed number of
chocolates at a time. Write a program in which consumer thread checks for sufficient chocolates in
basket, it waits for producer to produce if sufficient chocolates are not available in the basket and then
consumes given number of chocolates. Producer thread will notify consumer thread after it finishes
producing chocolates.

9) Create a class Item which has sell and buy method when one thread is updating the item the other
thread should not execute on same item.[5M](April Monthly).

H/W Assignment:
Tip: Trainers will not assist for these questions.
1) Extend class Thread and create thread.
2) implement runnable interface and create thread
3) First thread displays days of a week. Second thread display stable of 5.Third thread displays

Fibonacci series by creating 3 threads.


4) Thread b1 prints numbers 1 to 10. Thread b2 prints characters a to h. Ensure that always characters
are printed first and then numbers using join method.
5) Give use of all 3 join methods of thread class.
6) Give example of synchronized method in which 2 threads are trying to update same thread. Give
use of synchronization if 2 threads are sharing same objects.
7) If thread b1 is accessing static synchronized method a1, can thread b2 access synchronized method
a2 at same time
8)
WAP to which contain 1) normal static method 2) synchronized instance method 3)normal instance
method 4)static synchronized method . check when a thread executes static synchronized method
remaining threads will wait till this thread completes its execution. But remaining threads executes
following method simultaneously 1. Normal static methods 2. Synchronized instance
methods3.Normal instance methods.
9) Create Circle class having setRadius(),area(). One thread is calling setRadius(),another thread is
calling area(). Using wait () and notify () implements this program.
Interview QUEstions:
1) What is multithreading?
2) Explain the life cycle of a thread.
3) What is the difference between multi-processing and multithreading?
4) What are the different ways to create a thread?
5) What are the advantages of multithreading?
6) What is thread scheduler?
7) What is synchronization?
8) What do you understand by Garbage collection?
9) How will you define Garbage Collection?
10) When does the garbage collection get executed?
11) Is there any chance that the Java application can throw "out of
memory" error? Why?
12) Explain with a code sample when an object is ready for garbage collection.
13) What are the situations in which JVM triggers garbage collection?
14) What are the lines of code you need to write to programmatically
15) trigger garbage collection?
16) What are the concepts that come to your mind about finalize()method?
17) How will you define a Thread?
18) How will you create Threads in Java? What are the methods of Thread class that are
mainly used to manage threads?
19) How does a thread get executed in Java?
20) What are the thread states?
21) Write a compilable Java code that creates a child thread using "Thread" class.
22) What are the methods of Objects that are used while managing threads?
23) Is it possible to create more than one thread in a Java application? If so,
how will the threads communicate with each other?
24) How will you define Synchronization?
25) How will you make a thread to pause for ten minutes?
26) How will you use the "synchronized" keyword? Give code examples.
27) What happens when a synchronized method is invoked?
28) How will you make the thread to wait and start its execution a gain so
that certain process gets executed?
29) Write a Java code and implement "wait" and "notify" methods.
30) What are the methods that belong to "Runnable" interface?
31) What is the use of join () and yield ()methods?
Topic: Input-Output

SUb-Topics:
1) IntroDUCTion
2) InPUTstream
3) OUTPUTstream

C/W Assignment:
Tip: Trainers will assist for these questions.

1) Write a program to read contents from file and store reverse contents in another file.
2) Write a program to input data (numbers, characters), store in a.txt file, read it
andseparatethecontentsintwodifferentfilesnamelychar.txtandnumber.txt.
3) Write a program copy file contents into an other file.

H/W Assignment:
Tip:Trainers will not assist for these questions.
1) Write a program to accept input from console in write contents in file.
2) Write a program to read data from File.
3) Write a program to write data in file.
4) Write a program to read string names from file and sort and write those names in an
other file.
5) Write a program to accept input from user. Append the contents to the existing file.
6) Write a Java program to find the longest word in a text file.(AprilMonthly)
Topic: Collections -list

SUb-Topics:
1) IntroDUCTion
2) Lists
3) Array List- IntroDUCTioon
4) ConstrUCTors & methods of Array List
5) Linked List-IntroDUCTion
6) ConstrUCTors & methods of Linked List
7) Difference between Array List & Linked List
8) Vector–IntroDUCTion
9) ConstrUCTors & Methods of Vectors
10) Stack-IntroDUCTion

11) ConstrUCTors & Methods of Vectors


12) CURSORs-IntroDUCTion

13) ENUMeration

14) ConstrUCTors & Methods of ENUMeration

15) Limitations of ENUMerations

16) Iterator-IntroDUCTion

17) ConstrUCTors & Methods of Iterator

18) Limitations of Iterator


19) List Iterator
20) ConstrUCTors & Methods of List Iterator
21) Difference between EnUM, Iterator and ListIterator
C/W Assignment:
Tip: Trainers will assist for these questions.

1) WAP to add an element at a particular index using Add().


2) WAP to empty Array List
3) WAP to search an element from Array List
4) WAP to search the specified collection in this collection
5) WAP to retrieve an element (at a specified index) from a given ArrayList
6) WAP to print all the elements of an ArrayList using the position of the elements
7) WAP to get an element of a particular Index.
8) WAP to set or replace an element using set().
9) WAP to use add operation of ArrayList
10) WAP to print all elements of ArrayList using iterator
11) WAP to iterate through all elements in an ArrayList using for loop
12) WAP to iterate a linked list in reverse order.
13) WAP to insert the specified element at the specified position in the linked list.
14) WAP to create Emp (id,name,sal) object and add 2objects to ArrayList. Sysout and
see both variable memory space is printed. This is because to String is not overriden
but if you would have done this for Integer then beautiful output would have been
printed.
 A .Now override to String for earlier assignment and now sysout and see
values are printed
 b.WAP to print Emp whose salary is >10000
 c.WAP to print Emp who have name "Sachin"

d.WAP to print Emp who have highest number of salary

H/W Assignment:
Tip:Trainers will not assist for these questions.

1) WAP to Add elements in anArrayList.


2) WAP to Remove an element in anArrayList
3) WAP to check if the ArrayList is empty ornot.
4) WAP to check if an element is present in ArrayList using Contains().
5) WAP to clear all objects fromArrayList.
6) WAP to insert an element into the ArrayList at the first position
7) WAPtoadd1to 50numbersinArrayListandprintonlyevennumbers(usingiterator)
8) WAP to match two collections
9) WAP to check if collection is empty
10) WAP to convert collection into array
11) WAP of swap two elements in an ArrayList
12) WAP to append the specified element to the end of a linked list.
13) WAP to iterate through all elements in a linked list.
14) WAP to iterate through all elements in a linked list starting at the specified position.
15) WAP to replace the second element of an ArrayList with the specified element
16) WAP to use add all elements to ArrayList
17) WAP to sort a given ArrayList
18) WAP to copy one ArrayList into another
19) WAP to compare two ArrayLists print if equal?
20) WAP to empty an ArrayList

56 |Page
21) WAP to trim the capacity of an ArrayList the current list size
22) WAP to increase the size of anArray List
23) WAP to update specific array element by given element
24) WAP to remove the third element from an ArrayList
25) WAP to insert elements into the linked list at the first and last position.
26) WAP to insert the specified element at the front of a linked list.
27) WAP to insert the specified element at the end of a linkedlist.
28) WAP to insert some elements at the specified position into a linkedlist.
29) WAP to get the first and last occurrence of the specified elements in a linkedlist.
30) WAP to display the elements and their positions in a linked list.
31) WAP to remove a specified element from a linkedlist.
32) WAP to remove first and last element from a linkedlist.
33) WAP to remove all the elements from a linkedlist.
34) WAP to shuffle elements in anArrayList
35) WAP to reverse elements in an ArrayList

36) WAP to extract a portion of anArrayList


37) WAP to iterate through all elements in an ArrayList using foreach
38) WAP to create a new ArrayList, add some colors (string) and print the collection.
39) WAP to remove element from ArrayList
40) WAP to join two linked lists.
41) WAP to clone a linked list to another linked list.
42) WAP to remove and return the first element of a linked list.
43) WAP to retrieve but does not remove, the first element of a linked list.
44) WAP to retrieve but does not remove, the last element of a linked list.
45) WAP to check if a particular element exists in a linked list.
46) WAP to convert a linked list to array list.
47) WAP to compare two linked lists.
48) WAP to test a linked list is empty or not.
49) WAP to replace an element in a linked list
50) WAP to remove all elements fromArray List
51) WAP to retain all elements from ArrayList
52) WAP to know how many elements in ArrayList
57 |Page
53) WAP to join two ArrayLists
54) WAP to clone an ArrayList to another ArrayList
55) WAP to shuffle the elements in a linkedlist.
56) Write a method that receives an array of int and returns the sum of every element in the
array.

Interview QUEstions:

Explain Collections hierarchy?


Explain Difference between Vector and
Array List? What is the difference between
array and array list? How to sort array list?
How to create and initialize array list?

6) What is a linkedlist?
7) How to reverse a linkedlist
8) What is singly linkedlist?
9) What is the difference between Array and linkedlist?
10) Which collection would you choose if you want no duplicates and if objects are not
stored in an order?
11) How will you use the Comparator interface in your class file?
12) What are the activities that can be performed in collection API?
13) In collection, which method is used to remove the head of the queue?
14) Which collection class method is not synchronized but allows
15) growing or shrinking its size and provides indexed access to its elements?
16) How will you extract elements from a collection with out knowing
17) how the collection is implemented?
18) What are the different Collection Interfaces in Java collection framework?
Distinguish them.
19) What is Hashtable? What is its significance in Java?

58 |Page
Topic: Collections Set

SUb-Topics:
1) IntroDUCTion
2) Hash Set-declaration, constructors ,methods
3) Sorted Set
4) Tree Set
Linked Hash Set
5)

C/W Assignment:
Tip:Trainers will assist for these questions.

1) WAP to retrieve and remove the lowest element of a TreeSet using a single
method call. Repeat the same using 2 different method calls.
2) WAP to convert a HashSet to an array.
3) WAP to remove all of the elements from a Hash Set.
4) WAP to add user defined objects of type Employee in a Hash Set using duplicate
Employeeobject.

H/W Assignment :
Tip:Trainers will not assist for these questions.
1) WAP to iterate through all elements in a TreeSet.
2) WAP to create a Hash Set with Integer objects without using generics
3) WAP to create a Hash Set with some colors(String)
4) WAP to create a HashSet from anArrayList
5) WAP to iterate through all elements in a HashSet and print the elements. Observe the
order of elements.
6) WAP to get the number of elements in a HashSet.
7) WAP to get the first and last elements in a TreeSet.
8) WAP to get the number of elements in a TreeSet.
9) WAP to create a reverse order view of the elements contained in a given TreeSet.
10) WAP to remove a given element from a TreeSet.
11) WAP to empty a HashSet.
12) WAP to test if a HashSet is empty or not.
13) WAP to create a TreeSet from a HashSet.
14) WAP to create a new TreeSet, add Strings and print the TreeSet.

59 |Page
15) WAP to get the first and last elements in a Linked HashSet
16) WAP to iterate through all elements in a Linked Hash Set and print the
elements. Observe the order of elements.
17) WAP to add user defined objects of type Employee in a HashSet. Print the contents in the
Set.

60|Page
Topic: Queue

SUb-Topics:
1) IntroDUCTion
2) QUEUE-declarations, ConstrUCTors ,methods
3) Priority QUEUE-declarations, ConstrUCTors, methods
C/W Assignment:
Tip:Trainers will assist for these questions.

1) Use 2 different method calls to add elements to a queue.


2) WAP to check if a queue has values
3) WAP to create a Queue with Integer objects
4) WAP to attempt to remove non-existing elements from a queue
5) WAP to implement your own implementation of Queue using an array internally

H/W Assignment:
Tip:Trainers will not assist for these questions.

1) WAP to create a Queue with Integer objects


2) WAP to check the top element in a queue
3) WAP to create a Queue with user defined class objects & amp;
4) WAP to remove an element from a queue
5) Use 2 different method calls to remove elements from a queue

Interview QUEstions:

1) Explain Difference between HashMap and HashTable?


2) Explain Difference between Iterator andList Iterator?
3) Why Map interface does not extend Collection interface?
4) How HashSet store elements?
5) Difference between iterator and ListIterator?
6) Can a null element added to a TreeSet orHashSet?
7) What are Identity HashMap and Weak HashMap?
8) When to use HashMap or TreeMap?
9) How to make a collection read only?
10) How to make a collection thread safe?
11) What is difference between fail-fast andfail-safe?
12) What is Comparable and Comparatorinterface?
13) What are Collections and Arraysclass?
14) What is Queue and Stack? List their differences?
Topic: Collections Sorting

SUb-Topics:
1) IntroDUCTion
2) Sorting in collection
3) String objects
4) User-defined class objects
5) Comparable interface
6) Comparator interface
Comparable vs Comparator
7)

C/W Assignment:
Tip: Trainers will assist for these questions.

1) WAP to create a class Student with (rollNo, name and age). Create 3 Comparator
implementations for each Student attribute (i.e. rollNo, name andage)
2) Sort arraylist of employees in ascending order of their salaries .If salary is same
, list should be in descending order of name.

H/W Assignment:
Tip:Trainers will not assist for these questions.

1) What will happen if compare method returns only +1. Show example.
2) What will happen if compare method always returns -1. Show example
3) What will happen if compare method always returns 0; Show example.
4) Reverse an array list of 10integers.
5) WAP to sort the elements of List that contains String objects. Print Array List. Sort
using Collections. sort(list)method
6) Sort array list of integers without using sort method.
7) Create class Employee having name, age ,salary as variables .Add data of 5
Employees in any Collection Class. Print the values of the object by sorting on the
basis of name and salary. (March Monthly).
Topic: Collections Map

SUb-Topics:
1) IntroDUCTion
2) Methods-PUT, PUT All, get etc.
3) Hash Map
4) Sorted Map
5) Tree Map
6) Hash Table vs Hash Map

C/W Assignment:
Tip: Trainers will assist for these questions.
1) WAP to add elements to a Hash Map without using generics (i.e. do not use <>)and
print content of it. Use Integer as Key and String as Value. In second Hash Map add
elements of String type as Key and Integer as Value.
2) WAP add elements to Hash Map without using generics, 0th location use String as key
and Integer as value, on 1st location use String as key String and Integer as value.
3) WAP to get a key-value mapping associated with the greatest key less than or equal to
the given key
4) WAP to get a reverse order view of the keys contained in a given map Tree Map

H/W Assignment:
Tip: Trainers will not assist for these questions.
1) WAP to create a Tree map which contains Strings
2) WAP to create a Tree map which contains Integers
3) WAP to search a key in a Tree Map
4) WAP to search a value in a Tree Map
5) WAP to get all keys from the given a Tree Map
6) WAP to get only the Keys from a Hash Map
7) WAP to get only the Values from a Hash Map
8) WAP to delete all elements from a given Tree Map
9) WAP to copy a Tree Map content to another Tree Map
10) WAP to get all the entries from a Hash Map. Iterate the entries and print the Key& Value
values
11) WAP to create a Tree Map with Integer as key and get a key-value mapping
associated with the greatest key and the least key in a map
12) WAPtogetthefirst(lowest)keyandthelast(highest)keycurrentlyinaTreeMap
13) WAP to sort keys in Tree Map by using comparator
14) There is a hash map which has student object as key and marks as integer. Create two
array lists from this hash map. In one array list called ‘pass Students’ Insert all
students who has marks > 35 and in another array list ‘failed Students’ add all
students who has less than 35 marks.(Jun Monthly).

Interview QUEstions:

1) Why we use map interface?


2) What are the main classes implementing Map interface?
3) How Hash map works?
4) When to use Hash Map or Tree Map?

You might also like