0% found this document useful (0 votes)
22 views

Java Question Bank

The document outlines various questions related to Java programming, categorized into 2, 5, and 10 marks questions. It covers topics such as object-oriented programming concepts, Java architecture, method overloading and overriding, exception handling, and the significance of Java's features. The reference materials include chapters from E. Balaguruswami's 'Programming with Java'.

Uploaded by

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

Java Question Bank

The document outlines various questions related to Java programming, categorized into 2, 5, and 10 marks questions. It covers topics such as object-oriented programming concepts, Java architecture, method overloading and overriding, exception handling, and the significance of Java's features. The reference materials include chapters from E. Balaguruswami's 'Programming with Java'.

Uploaded by

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

Module 1

2 Marks Questions

REFERENCE: STUDY MATRERIAL

[1] Differentiate between Procedural and Object Oriented Programming.


[2] Why Java is called Robust Programming Language?
[3] Why Java is called Architectural?
[4] Define bytecode
[5] Give any four differences between C and Java.
[6] Why Java is considered a hybrid programming language?
[7] Draw the relationship among JVM, JRE & JDK using Venn diagram.
[8] Why Java is platform independent?
[9] Why main() method needs to declare as public?
[10] Explain each term of the following: public static void main(String [] args).
[11] Discus JDK.
[12] Explain the installation of JDK.
[13] What is Unicode? Explain the advantage of using Unicode [14] Explain JIT
compiler in Java.
[15] Why is the main method static?
[16] Differentiate between Procedural and Object Oriented Programming. [17]
What is JRE?
[18] What is JVM?
[19] How does Java provide high performance?
[20] What is the relationship between JavaScript and Java?

5 Marks Questions

REFERENCE: STUDY MATRERIAL


[1] (QN27)Develop a diagram illustrating the process of compiling and interpreting
Java code, highlighting the role of the Just-In-Time Compiler (JIT) and its
significance in this process.
[2] "Java is truely object oriented programming language"- Justify.
[3] Discuss difference between C++ and Java.
[4] Describe the features of Java with real-world examples.
[5] What are the different components in the Java environment and their usage?
[6] What are the advantages of a platform-independent language?Also explain how
Java is platform independent.

10 Marks Questions

REFERENCE: STUDY MATRERIAL

[1] Sketch and demonstrate the architecture of JVM.


[2] What are the elements of OOP? How do these elements make the OOP
approach ?
[3] Discus the features and benefits of object oriented programming?

REFERENCE: E. Balaguruswami, Programming with Java, 6th edition


Chapter 1,2,3
5
5

10

5
2
2
2

5
5

2
5

10

2
2
5
2
2

5
2
5

5
5
5

10
5
2
Module 2

2 Marks Questions

REFERENCE: STUDY MATRERIAL


[1] Express a Java programming structure to display “Hello World”. [2]
Write down the signifiance of static keyword.
[3] What are the benifits of reuseability properties?
[4] What happens if the constructors are defined as private?
[5] Write a program to print a string in reverse order.
[6] Write a program to show the use of enhanced for loop in java.
[7] What is a constructor? Explain with suitable example.
[8] Distinguish between instance variables and static variables with a code snippet.
[9] String is immutable in java - justify your answer with a code snippet.
[10] Can you call one constructor from another if a class has multiple constructors?
[11] How can a subclass call a method or a constructor defined in a superclass? [12]
What is the basic difference between string and stringbuffer objects?
[13] How objects of a class are created if no constructor is defined in the class?
[14] Write down the difference between Concat method and + operator to join strings?
[15] Explain default method in java.
[16] What are the relationships between classes?
[17] What is a break statement?
[18] What is a continue statement?
[19] What is a “blank final” variable?
[20] What is the precedence of an operator?
[21] What is the Associavity of an operator?

5 Marks Questions

REFERENCE: STUDY MATRERIAL


[1] Develop a Java application to generate Electricity bills. Create a class with the
following members: Consumer no., consumer name, previous month reading,
current month reading, and type of EB connection (i.e domestic or commercial).
Compute the bill amount using the following tariff. If the type of the EB connection
is domestic, calculate the amount to be paid as follows: First 100 units - Rs. 1 per
unit
101-200 units - Rs. 2.50 per unit
201 -500 units - Rs. 4 per unit
> 501 units - Rs. 6 per unit
[2] Write a program to show the use of object as a return type and parameter.
[3] Given a string, return a new string made of 'n' copies of the last 2 chars of the
original string where 'n' is the length of the string.
Input:Coding
Output: ngngngngngng
[4] Given a string, return a new string made of 'n' copies of the first 2 chars of the
original string where 'n' is the length of the string.
Input:Hello
Output: HeHeHeHeHe
[5] Write about the operators in JAVA with examples.
[6] How is the for each loop different from the for loop?
[7] Using up to four characters, write the Java representation of the octal literal 6.
[8] How many bits represent a Boolean variable? Why?
[9] How can we make a class immutable?
[10] Discus constructing a string with character array and String class.

10 Marks Questions

REFERENCE: STUDY MATRERIAL

[1] Discuss different access specifier of java. Explain each with examples.
[2] a) Explain public static void main(String args[]) in Java.
b) Explain each token in the statement:
System.out.println(“Hello Java”);
[3] Write a program that reads ten numbers through command line argument, computes their
average, and finds out how many numbers are above the average.
[4] Explain different iterators used for accessing the elements,with examples.
[5] Discus operators and control statements in Java in detail.
[6] Write a program that defines a class that represents a complex number.Write a method in
the class that returns the magnitude or modulus of the complex number on which it is called.
REFERENCE: E. Balaguruswami, Programming with Java, 6th edition
Chapter 4,5,6
2
2
5

2
5
2

2
2

10

5
5

5
2

10
10

10

10
10

5
10

Presented By: http://www.ebooksuit.com


5

5 +5+5+5

10

10

Presented By: http://www.ebooksuit.com


10
10

10

10

Presented By: http://www.ebooksuit.com


5

Presented By: http://www.ebooksuit.com


Presented By: http://www.ebooksuit.com
Module 3

2 Marks Questions REFERENCE:

STUDY MATRERIAL
1) What are the different ways to implement method overloading?
2) Compare and contrast overloading and overriding methods.
3) Explain the significance of using Interface.
4) Explain the purpose of abstract classes and how they differ from concrete classes.
5) Discuss the role of abstract methods in abstract classes and how they are implemented in concrete
subclasses.
6) Discuss the role of the @Override annotation in method overriding.
7) Describe the concept of strings in object-oriented programming (OOP) and explain how they are
represented as objects.
8) Explain String Tokenizer with an example.
9) Explain the need for StringEquals function in java with suitable example.
10) Explain the term immutable String in java with suitable example.
11) Can you call one constructor from another if a class has multiple constructors?
12) Explain the syntax of BufferedReader object creation.
13) Can we override a method by using the same method name and arguments but different return
types?
14) Explain the syntax of BufferedReader object creation.
15) Can we override a method by using the same method name and arguments but different return
types?
16) In a class implementing an interface, can we change the value of any variable defined in the
interface?
17) Can we make constructors static?
18) Can we use this() and super() both in a same constructor?
19) Distinguish between private and protected access modifier with suitable examples.
20) Explain var-args array.
21) Write down the significance of static keyword.
22) Distinguish the use of extends and implements.
23) What happens if the constructors are defined as private?
24) If two interfaces contain method with same signature and what happen if a class inherits both?
25) Is it possible to override super-class constructor? Why?
26) Explain "Is-A" relationship in inheritance.
27) Explain "HAS-A" relationship in inheritance.
28) What is method overriding and how does it differ from method overloading in Java?
29) When can a method in super class be prevented from being overridden by a method in subclass?
30) Can we declare the static variables and methods in an abstract class?

5 Marks Questions

REFERENCE: STUDY MATRERIAL


1) Demonstrate constructor overloading with a suitable example.
2) Demonstrate the application of the super keyword in conjunction with a method in Java.
3) Design a Java program that illustrates the concept of static variables by showcasing their
unique property of allocating memory only once throughout the execution of the program.
4) Evaluate the role of abstract classes in Java inheritance. Analyse the advantages and
limitations of using abstract classes compared to interfaces in object-oriented design.
5) Discuss the concept of interface inheritance in Java. Explain how interfaces can extend
other interfaces and inherit methods and constants from parent interfaces. Provide
examples to illustrate interface inheritance and discuss its advantages.
6) Implement a java code to check if the String contains 'e' in umbrella.
7) Develop a java code to examine whether interfaces can be extended in Java.
8) Explain yield() and join() with proper code snippet.
9) Demonstrate different types of polymorphism with a suitable example.
10) How does the abstract class differ from the interface? Discuss with program.
11) Write down the differences between this, super, and final keywords.
12) Develop a Java Program to create an abstract class named Shape that contains two integers
and an empty method named printArea(). Provide three classes named
Rectangle, Triangle and Circle such that each one of the classes extends the class Shape.
Each one of the classes contains only the method printArea () that prints the area of the
given shape.
13) What happens if any value is not assigned to a final and static variable during declaration?
Explain and provide a solution with a program.
14) Write down the advantages and disadvantages of Object Cloning.
15) Is it possible to use the keyword super within a static method? Give justification for your
answer.

10 Marks Questions
REFERENCE: STUDY MATRERIAL
1) Discuss the difference between start() and run() methods by demonstrating through a
Multithreaded Java program. Justify your observations.
2) Design an abstract class shape having two methods calculate_area() and display(). Create
rectangle, triangle, and ellipse classes by inheriting the shape class and overriding the
above methods to suitably implement rectangle, triangle, and ellipse classes.
3) Evaluate the design of a banking application in Java that uses abstract classes and interfaces
to model various account types. Analyse the role of abstract classes in providing common
behaviour among account types and interfaces in defining a contract for account operations.
4) Generate a class where a Company manufactures Vehicles, which could be a Helicopter, a
Car, or a Train depending on the customer’s demand. Each Vehicle instance has a method
called move, which prints on the console the nature of movement of the vehicle. For
example, the Helicopter Flies in Air, the Car Drives on Road and the Train Runs on Track.
Write a program that accepts input from the user on the kind of vehicle the user wants to
order, and the system should print out nature of movement. Implement all Java coding best
practices to implement this program.
5) Develop a java code to create Thread by implementing the Runnable interface. Write a java
program to implement the yield( ) method in thread programming.
6) Design a Java program to display the car no., model, colour and price of a car using class
and object concept.(use Scanner class).
7) What is array of objects? Describe the use of Access Modifiers in Java? Draw a table
showing the scope of accessibility? Justify: I. Why we declare main () method as public
and static member. II. Why we generally declare constructor as public member. III. Why
there is no destructor in java.
8) Differentiate between abstract class and Interface. The abstract Vegetable class has three
subclasses named Potato, Brinjal and Tomato. Write an application that demonstrates how
to establish this class hierarchy. Declare one instance variable of type String that indicates
the colour of a vegetable. Create and display instances of these objects. Override the
toString() method of Object to return a string with the name of the vegetable and its colour.

REFERENCE: E. Balaguruswami, Programming with Java, 6th edition Chapter


8, 9, 10
2
2

2
2

2
2

2
2

Presented By: http://www.ebooksuit.com


5

10

Presented By: http://www.ebooksuit.com


5

Presented By: http://www.ebooksuit.com


5

Presented By: http://www.ebooksuit.com


2
2

10

Presented By: http://www.ebooksuit.com


10

10

10

10

10

Presented By: http://www.ebooksuit.com


5

10

10
10

10
5
5

10

Presented By: http://www.ebooksuit.com


10

10

10

Presented By: http://www.ebooksuit.com


10

Presented By: http://www.ebooksuit.com


2
2

2
5
5

10

Presented By: http://www.ebooksuit.com


5

10

Presented By: http://www.ebooksuit.com


10

Presented By: http://www.ebooksuit.com


Module 4

2 Marks Questions REFERENCE:

STUDY MATRERIAL
1) What are the different types of exceptions?
2) Compare between “extends Thread” and “implements Runnable” options. 3)
Describe the concept of thread scheduling in Java.
4) What is the main advantage of using threads in Java applications?
5) What is a thread in Java?
6) Examine the purpose of Static methods and static variables.
7) What is thread based multitsking?
8) What is process based multitasking ?
9) Write down the difference between Concat method and + operator to join strings?
10) In multi-threading how can we ensure that a resource isn‟t used by multiple threads
simultaneously?
11) Distinguish between private and protected access modifier with suitable examples.
12) What is default exception handler?
13) Distinguish between throw and throws.
14) What happens if matching exception type is not found in catch blocks? Explain.
15) Discuss the use of join() in multithread programming.
16) Write a statement that moves a thread to blocked-state.
17) Write a program where one interface inherits another one.
18) Compare Garbage collection and finalize method
19) Write a program where one interface inherits another one.
20) Write a statement that moves a thread to blocked-state.

5 Marks Questions

REFERENCE: STUDY MATRERIAL


1) Can we have multiple catch blocks for a single try block? Justify your answer with an
example.
2) Implement a java program to remove all the repeated element from the ArrayList.
3) Differentiate between values() and valuesOf() in JAVA
4) Develop a java program to create a package and a subpackage then access the methods
from both.
5) Consider a scenario where two classes with same name are defined in two different
packages. How to access members of both from a same method. Write a program to support
that.
6) Write a java program to create two threads, one for writing odd numbers and another for
writing even numbers up to 150 in two different files.
7) How polymorphism property can be achieved by constructors?

10 Marks Questions

REFERENCE: STUDY MATRERIAL


1) Create a user-defined exception i.e. "LowBalanceException". Write the code to throw that
"LowBalanceException" if your savings account balance goes below 500 Rs. and arrange
to handle that "LowBalanceException". Also, write the output.
2) Develop a Java program that demonstrates the implementation of the Runnable interface to
create threads effectively.
3) Explain the concept of multithreading in Java. Provide a code example demonstrating the
creation and execution of multiple threads. Discuss the advantages of using multithreading
in Java applications.
4) Explain the role of interfaces in achieving multiple inheritance in Java. Discuss how
interfaces allow a class to implement multiple interfaces, thereby inheriting behaviors from
multiple sources. Provide examples to demonstrate the use of multiple interfaces in Java.
5) Create a parent class Computer with three child classes Laptop,TabletComputers and
SmartPhone justify with suitable code showing all Laptops ,TabletComputers and
SmartPhones belongs to Computer class.
6) Distinguish between the „throw‟ and „throws‟. Give proper codes. What happens precisely
when the code in the try block throws an exception?
7) Write a Java program that creates two threads. First thread displays Good Morning! in every
one second, and the second thread displays Hello! in every two seconds.
8) A)Explain about Thread Life Cycle.
B) Describe how to set the priority to threads. what are the different ranges?
9) Write a Java program that creates three threads. First thread generates a random positive
number (>1) every 2 second. If the number is even, the second thread prints all even
numbers between 1 and the generated number. If the number is odd, the third thread will
print all odd numbers between 1 and the generated number.
10) Discuss the working and meaning of the “static” modifier with example and explain static
variable and static methods with an example program. Java program is to be compiled first
and then to be interpreted for execution. True or false? Justify your answer.
11) Write a java program to show the use of throw, throws, try, catch and finally. Explain each.
12) What are the types of Exceptions in Java. What is the implication of catching all the
exceptions with the type “Exception”? Write a program to create a user defined exception
to check correctness of mobile number and also handle that using try, catch. For correctness
of mobile number consider length is 10 and that of numeric only. Take user input to validate
that.
13) Name the superclass of all exception classes in Java. Build a Java program that simulates
a banking transaction. Use exception handling to ensure that the account balance is never
negative after a withdrawal.

REFERENCE: E. Balaguruswami,
Programming with Java, 6th edition Chapter
11, 12, 13
2

2
2

Presented By: http://www.ebooksuit.com


5

Presented By: http://www.ebooksuit.com


5

Presented By: http://www.ebooksuit.com


2

2
2
2
2
2
2
5
2
10

Presented By: http://www.ebooksuit.com


5

Presented By: http://www.ebooksuit.com


5

Presented By: http://www.ebooksuit.com


5

Presented By: http://www.ebooksuit.com


2
2
2

2
2
2

5
5
5

5
5

5
10

10
Module 5

2 Marks Questions

REFERENCE: STUDY MATRERIAL


1) Name three concrete implementations of the List interface in Java
2) Explain the difference between ArrayList and LinkedList in Java
3) Describe the role of the List interface in the Collection Framework
4) Compare Vector and ArrayList in terms of thread-safety
5) Define the Hierarchy of Collection Framework in Java 6) What is the primary purpose of
the Collection Framework in Java?
7) Name three interfaces that are part of the Collection Framework.
8) Explain the difference between ArrayList and LinkedList in Java
9) Describe the role of the List interface in the Collection Framework
10) Compare Vector and ArrayList in terms of thread-safety
11) Define the Hierarchy of Collection Framework in Java 12) What is the primary purpose of
the Collection Framework in Java?
13) Name three interfaces that are part of the Collection Framework.
14) List at least two methods provided by the List interface in Java.
15) Write a program to remove duplicates from ArrayList in Java.
16) What is nested class? Mention its types.
17) What is inner class? Give Example.
5 Marks Questions

REFERENCE: STUDY MATRERIAL


1) Write a program to show annotations in JAVA.
2) Explain the advantages of Autoboxing
3) Write down a program how to use wrapper classes(primitive double to wrapper Double and
vise versa)
10 Marks Questions

REFERENCE: STUDY MATRERIAL

1) Implement a method in Java that takes a HashSet as input and removes all duplicate
elements from it.
2) Develop a utility class that provides methods for merging and sorting multiple
ArrayLists efficiently.
3) What are streams? Write any two methods of character stream classes. What is the
use of ArrayList Class? State any three methods with their use from ArrayList.
REFERENCE: E. Balagurusami,

Programming with Java, 6th edition Chapter 16


5
5
5
5

5
10
Module 6

2 Marks Questions
1) Explain the term collection API ,collections and collection.
2) What does unified mean 3) What Is a Model?
4) Write down about the goals of UML?
5) What is static view?
6) What is Design View?

REFERENCE: STUDY MATRERIAL

5 Marks Questions

REFERENCE: STUDY MATRERIAL


1) Create the suitable UML class diagram shown below. a) Construct a UML Class diagram
for the Online Movie Ticket Booking System. The various entities involved in the system
are Admin, Registered User, Visitor / Guest User, Movie, Book Ticket, and Make Payment.
b) Construct a UML Activity diagram for the Restaurant Food Ordering System, which
shows the flows between the activity of Order, Delivery, Food Item, Category, and
Payment.
2) Explain Internal structure diagram with a suitable example.
3) Explain Collaboration diagram with a suitable example.
4) Explain Component diagram with a suitable example.

10 Marks Questions

REFERENCE: STUDY MATRERIAL


1) The Library Loan System manages the loans and circulation of library resource
material such as books, journals and audiovisuals. Students and faculty enjoy
membership at the library. During checkout, the LLS obtains the student or faculty
ID. Resource materials can be checked out (i.e. borrowed) for a duration of 2 weeks.
A fine of 1 rupee a day is imposed on overdue materials. Draw a detailed Class
diagram.

2) The Library Loan System manages the loans and circulation of library resource
material such as books, journals and audiovisuals. Students and faculty enjoy
membership at the library. During checkout, the LLS obtains the student or faculty
ID. Resource materials can be checked out (i.e. borrowed) for a duration of 2 weeks.
A fine of 1 rupee a day is imposed on overdue materials. Draw a detailed Class
diagram

Module 7

2 Marks Questions
1) Explain the purpose and application of the AWT (Abstract Window Toolkit) package in Java,
highlighting its usage and relevance within the Java programming environment.
2) Create a diagram depicting the applet hierarchy in Java, specifically indicating the superclass name
of the Applet class.
3) What are the life cycle methods of android activity?
4) Differentiate between components and Containers in Swing.
5) What is the super class for all applets?
6) Why do applet classes need to be declared as public.

REFERENCE: STUDY MATRERIAL

5 Marks Questions

REFERENCE: STUDY MATRERIAL


1) Difference between Swing and AWT. Write a Swing Program to use TextField, Button.
2) Describe broadcast receivers? How is it implemented?
3) What is the difference between the initialize and start life cycle stages?

10 Marks Questions

REFERENCE: STUDY MATRERIAL

1) Create a GUI using the swing package containing one text field, button, and label.
Also, incorporate the code against the button click event to fetch the user-given text
from the text field and display the same in the label.
2) Design an applet program in Java to exhibit graphical elements such as a 'Rectangle,' 'Line,'
and 'Arc.' Elaborate on the sequential steps required for compiling and executing the
applet program effectively(Must mention the syntax for compilation and the execution
process).
3) Draw and explain Android Architecture in detail?
REFERENCE: E. Balagurusami,

Programming with Java, 6th edition

Chapter 14
2
2
2
2
2
2
2
2
2

Presented By: http://www.ebooksuit.com


2

10

Presented By: http://www.ebooksuit.com

You might also like