Java Booklet Oct-Nov2019
Java Booklet Oct-Nov2019
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.
H/W Assignment:
Tip: Trainers will not assist for these questions.
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.
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 2 3 45
2345
345
45
5
45
345
2345
1 2 3 45
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
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
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
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:
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.
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.
Interview QUEstions:
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).
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
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.
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.
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).
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:
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.
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).
8. WAPtoprintouterelementsof2DarrayofnXn..
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.
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.
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)
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]
41|Page
Take 10 integer inputs from user and print the following: number of positive numbers
4.
Interview QUEstions:
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.
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.
InterviewQUestions:
1) What are Strings in Java? Is string a data type?
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.
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
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
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
13) ENUMeration
16) Iterator-IntroDUCTion
H/W Assignment:
Tip:Trainers will not assist for these questions.
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
Interview QUEstions:
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.
H/W Assignment:
Tip:Trainers will not assist for these questions.
Interview QUEstions:
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: