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

Java Questionbank

Uploaded by

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

Java Questionbank

Uploaded by

k.shyam06082005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

CS4352- Java Programming Department of IT 2023-2024

CS4352 JAVA PROGRAMMING LTPC


3 0 03
UNIT I INTRODUCTION TO JAVA 9
History of Java-Environmental Setup -features of java-data types- variables- modifiers-keywords
operators- Iterative, Conditional and control statement - command line arguments - string- string
buffer - simple java program- enumerators-array-formatting output.
UNIT II OBJECT,CLASS,INTERFACES AND PACKAGES 9
Object-class-constructor-benefits of OOPS-concepts of OOPS- inheritance - polymorphism-abstract
class generic class- Overriding-Overloading-Interface: Implementation of interface-extending
interface-inner class- static and dynamic binding- package: Package as Access Protection-
CLASSPATH setting- Import packages.
UNIT III EXCEPTION AND FILE I/O STREAMS 9
Exceptions-benefits of exception-Types of Exceptions-Errors-Control flow- JVM reaction to
Exception usage of try, catch, throw, final and finally keyword-rethrowing exceptions, exception
specification, built in exceptions-File I/O: Standard Streams-Reading and writing Streams- Byte
Array Stream-Data Stream- File Stream- Input and output Stream.
UNIT IV THREADS AND GENERIC CLASSES 9
Understanding Threads, Needs of Multi-Threaded Programming, Thread Life-Cycle, Thread
Priorities, Synchronizing Threads, Inter Communication of Threads, Critical Factor in Thread –
Deadlock-Generic: Introduction to Generics-Built-in Generics collections-writing simple generic
class.
UNIT V JAVAFX EVENT HANDLING, CONTROLS AND COMPONENTS FOR GUI
PROGRAM 9
JAVAFX Events and Controls: Event Basics – Handling Key and Mouse Events. Controls:
Checkbox, ToggleButton – RadioButtons – ListView – ComboBox – ChoiceBox – Text Controls
ScrollPane.Layouts – FlowPane – HBox and VBox – BorderPane – StackPane – GridPane. Menus–
Basics – Menu – Menu bars – MenuItem.
TOTAL : 45 PERIODS
TEXT BOOK:
1. Herbert Schildt, “Java Complete Reference”, McGraw-Hill, 12th Edition, 2021.
REFERENCE:
1. Paul Deitel and Harvey Dietel, “Java How to Program”, Pearson, 11th Edition, 2017

COURSE OUTCOMES
On successful completion of this course, the student will be able to
Develop a simple Java program using all basic data types
C304.1
Develop a Java program with simple OOPS concepts
C304.2

C304.3 Build a basic Java program using Exception and I/O Streams.
Build a Java program using multi-threading and with generic class
C304.4
Develop a Java application using basic event handling and swing component concept
C304.5
MAPPING BETWEEN CO AND PO, PSO WITH CORRELATION LEVEL 1/2/3
P P P P P
P P P P P P P P P
Course 0 O O S S PS
O O O O O O O O O PS
Outcome 1 1 1 O O O
1 2 3 4 5 6 7 8 9 O3
0 1 2 1 2 4
C304.1 - - - 1 2 - - - 1 2 3 2 1 2 2 2
C304.2 2 1 1 3 2 - - - - 1 - 2 3 2 - -
C304.3 3 1 - 3 1 - - - - - - 1 2 2 - -
C304.4 3 2 3 3 3 - - - - - - 1 3 3 1 1
C304.5 3 1 3 3 3 - - - - - - 1 2 2 1 1

St. Joseph’s Institute of Technology 1


CS4352- Java Programming Department of IT 2023-2024

RELATION BETWEEN COURSE CONTENT WITH COs


UNIT I INTRODUCTION TO JAVA
Knowledge
Sl. No. Course Content Course Outcome
level
1 History of Java R&U
2 Environmental Setup R&U
3 Installation of Java and Java Packages R&U
4 Features of Java R&U
5 Datatypes,variables R, U &Ap
6 Modifiers,keywords R, U &Ap
7 Operators R, U &Ap
8 Iterative R, U &Ap C304.1
9 Conditional and Control Statement R, U &Ap
10 Command line arguments R&U
11 String,String buffer R, U &Ap
12 Simple Java Program R, U &Ap
13 Enumerators R, U &Ap
14 Array R, U &Ap
15 Formatting output R,U &Ap
UNIT II OBJECT,CLASS,PACKAGES AND INTERFACES
Knowledge
Sl. No. Course Content Course Outcome
level
1 Object,Class R&U
2 Constructor U, An & E
3 Benefits of OOPS U, An & E
4 Concepts of OOPS R&U
5 Inheritance R&U
6 Polymorphism R&U
7 Abstract Class,Generic Class R&U
8 Method Overriding and Overloading R,U &Ap C304.2
9 DynamicMethod Dispatch R,U &Ap
10 Interfaces R,U &Ap
11 final with Inheritance R,U &Ap
12 Packages and Interfaces: Packages R,U &Ap
13 Packages and Member Access R,U &Ap
14 Importing Packages R,U &Ap
15 CLASSPATH setting R,U &Ap
UNIT III EXCEPTION AND FILE I/O STREAMS
Sl. Knowledge
Course Content Course Outcome
No. level
1 Exception Handling basics R&U
2 Benefits of Exception R&U
3 Types of Exception R&U
4 Errors R,U &Ap
5 Control Flow R,U &Ap
C304.3
6 JVM reaction to Exception R,U & E
7 Usage of try,catch,throw,final and finally keyword R,U &Ap
8 Rethrowing exceptions R,U &Ap
9 Exception specification R,U &Ap
10 Builtin exceptions R,U &Ap

St. Joseph’s Institute of Technology 2


CS4352- Java Programming Department of IT 2023-2024

Sl. Knowledge
Course Content Course Outcome
No. level
11 File I/O:Standard Streams,Reading /Writing Streams R,U &Ap
12 Byte Array Stream,Data Stream R,U &Ap
13 File Stream,Input and Output Stream R,U &Ap
UNIT IV THREADS AND GENERIC CLASSES
Sl.
Knowledge
No. Course Content Course Outcome
level
1 Understanding Threads R&U
2 Needs of Multi-threaded Programming R&U
3 Thread Life-cycle. R,U, Ap& E
4 Thread Priorities,Synchronozing Threads R,U &Ap
5 Intercommunication of Threads R&U C304.4
6 Critical Factor in Thread,Deadlock R,U &Ap
7 Introduction to Generics R,U &Ap
8 Builtin Generic Collections R,U &Ap
9 Writing Simple Generic Class R,U &Ap
UNIT V JAVAFX EVENT HANDLING, CONTROLS AND COMPONENTS
FOR GUI PROGRAM
Sl. Knowledge
Course Content Course Outcome
No. level
1 JAVAFX Events and Controls: Event Basics U, Ap& E
2 Handling Key and Mouse Events. U, Ap& E
3 Controls:Checkbox, ToggleButton U, Ap& E
RadioButtons – ListView ,ComboBox – U, Ap& E
4 C304.5
ChoiceBox
5 Text Controls ScrollPane. Layouts – FlowPane U, Ap& E
6 HBox and VBox U, Ap& E
7 BorderPane,StackPane,GridPane Menus,Menu bars U, Ap& E
8 MenuItem. U, Ap& E
BL – Bloom’s Taxonomy Levels (1 – Remembering; 2– Understanding; 3 – Applying; 4 – Analysing,
5- Evaluating, 6-Creating)
UNIT I INTRODUCTION TO JAVA
History of Java-Environmental Setup -features of java-data types- variables- modifiers-keywords
operators- Iterative, Conditional and control statement - command line arguments - string- string
buffer - simple java program- enumerators-array-formatting output.
UNIT I/PART – A (CO: C304.1)
1. What are the OOP Principles?
The principles of object-oriented programming is Class inheritance, interface
BL1
implementation, abstraction of data and behavior, encapsulation of data and class
implementation, polymorphism and virtual methods.
2. What are the four cornerstones of OOP?
The following are the four cornerstones of OOP.
Abstraction: Can manage complexity through abstraction. Gives the complete overview
of a particular task and the details are handled by its derived classes. Example: Car.
Encapsulation: Nothing but data hiding, like the variables declared under private of a
BL1
particular class is accessed only in that class and cannot access in any other the class.
Inheritance: Is the process in which one object acquires the properties of another object,
ie., derived object.
Polymorphism: One method different forms, ie., method overriding and interfaces are
the examples of polymorphism.

St. Joseph’s Institute of Technology 3


CS4352- Java Programming Department of IT 2023-2024

3. What are the features of Object Oriented Programming?


● Emphasis is on data rather than procedure.
● Programs are divided into objects.
● Data structures are designed such that they characterize the objects.
● Functions that operate on the data of an object are tied together. BL1
● Data is hidden and cannot be accessed by external functions.
● Objects may communicate with each other through functions.
● New data and functions can easily be added whenever necessary.
● Follows bottom-up approach.
4. What are the features of Java Language?(April 2017)
The features of Java Language are Simple, Object-Oriented, Portable, Platform
BL1
independent, Secured, Robust, Architecture neutral, Dynamic, Interpreted, High
Performance, Multithreaded and Distributed.
5. How Java supports platform independency?
● The meaning of platform independent is that, the java source code can run on all
operating systems. A compiler is a program that translates the source code for
another program from a programming language into executable code which
may be a sequence of machine instructions that can be executed by the CPU
directly, or it may be an intermediate representation that is interpreted by a
BL2
virtual machine. This intermediate representation in Java is the Java Byte Code.
● It is the Bytecode that makes it platform independent. This adds to an
important feature in the JAVA language termed as portability. Every system
has its own JVM which gets installed automatically when the jdk software is
installed. JAVA is platform-independent language but the JVM is platform-
dependent
6. Give the contents of Java Environment (JDK).
The Java Development Kit (JDK) is a software development environment used for
developing Java applications and applets. It includes the Java Runtime Environment BL1
(JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation
generator (javadoc) and other tools needed in Java development.
7. What is Java Interpreter?
It is a Java Virtual Machine. An interpreter is a program that reads in as input a source
program, along with data for the program, and translates the source program instruction BL1
by instruction. For example, the Java interpreter java translate a .class file into code that
can be executed natively on the underlying machine.
8. Give any 4 differences between C and Java.
C JAVA
C is a procedural Language Java is Object Oriented Language
C is a compiled language. Java is an Interpreted language BL3
C uses the top-down approach Java uses the bottom-up approach.
C does not support overloading Java supports Method Overloading
9. Compare C++ with Java.(April 2018)
C++ JAVA
C++ generates object code and the same Java is interpreted for the most part and
code may not run on different platforms. hence platform independent.
C++ supports structures, unions, Java does not support pointers,
templates, operator overloading,pointers templates, unions, operator overloading, BL3
and pointer arithmetic. structures etc.
C++ supports goto statement. Java doesn’t support goto statement.
C++ support destructors, which is Java support automatic garbage
automatically invoked when the object is collection. It does not support
destroyed. destructors as C++ does.

St. Joseph’s Institute of Technology 4


CS4352- Java Programming Department of IT 2023-2024

10. Distinguish between procedure oriented programming (POP) and Object oriented
programming.(OOP)
POP OOP
In POP, program is divided into small In OOP, program is divided into parts
parts called functions. called objects.
POP does not have any access specifier. OOP has access specifiers named Public,
Private, Protected, etc. BL3
POP does not have any proper way for OOP provides Data Hiding so provides
hiding data so it is less secure. more security.
In POP, Overloading is not possible. In OOP, overloading is possible in the
form of Function Overloading and
Operator Overloading.
Example of POP are : C, VB, Example of OOP are : C++, JAVA,
FORTRAN, Pascal VB.NET, C#.NET.
11. What are the data types supported in Java?
Operator in java is a symbol that is used to perform operations like +, -, *, / etc. There
are many types of operators in java which are Unary Operator, Arithmetic Operator, BL1
Shift Operator, Relational Operator, Bitwise Operator,
Logical Operator, Ternary Operator and, Assignment Operator.
12. Define Abstraction.
Abstraction refers to the act of representing the essential features without including the
background details or explanations. It reduces the complexity and increases the BL1
efficiency. Small programs can be easily upgraded to large programs. Software
complexity can easily be managed.
13. What is Polymorphism?(Nov 2021)
Polymorphism is the ability to take more than one form and refers to an operation
exhibiting different behavior instances. Object oriented programs use polymorphism to
BL2
carry out the same operation in a manner customized to the object. It allows a single
name/operator to be associated with different operation depending on the type of data
passed to it.
14. Define Objects and Classes in Java(Nov 2018)
● Class is a collection of data and the function that manipulate the data. The data
components of the class are called data fields and the function components of the
class are called member functions or methods. The class that contains main
function is called main class. BL2
● Object is an instance of a class. The objects represent real world entity. The
objects are used to provide a practical basis for the real world. Objects are used to
understand the real world. The object can be declared by specifying the name of
the class.
15. Write the syntax for declaration of class and creation of objects?
A class is declared using class keyword. A class contains both data and method that
operate on that data. Thus, the instance variables and methods are known as class
members. When creating an object from a class
Declaration − A variable declaration with a variable name with an object type.
Instantiation − The 'new' keyword is used to create the object.
Initialization − The 'new' keyword is followed by a call to a constructor. This call
initializes the new object.
Class Student BL2
{ String name; int rollno;
int age;}
Student std=new Student( );
● std is instance/object of Student class.
● new keyword creates an actual physical copy of the object and assign it to the std
variable.
● The new operator dynamically allocates memory for an object.

St. Joseph’s Institute of Technology 5


CS4352- Java Programming Department of IT 2023-2024

16. Define Encapsulation (Apr 2012, Apr 2017, Nov 2020, April 2021,Dec 2021)
The wrapping up of data and functions into a single unit is known as data
encapsulation. Here the data is not accessible to the outside the class. The data BL1
inside that class is accessible by the function in the same class. It is normally not
accessible from the outside of the component.
17. What is Inheritance? What are its types?
● Inheritance is a mechanism of reusing the properties and extending existing
classes without modifying them, thus producing hierarchical relationships
between them.
● extends and implements keywords are used to describe inheritance in Java. BL2
Types of inheritance are: Single inheritance, Multi-level inheritance, Hierarchical
inheritance, Hybrid inheritance.
Syntax : Class Subclass-name extends Superclass-name
{ //methods and fields }
18. Define class (Nov 2011,Nov 2018)
Class is a template for a set of objects that share a common structure and a common BL1
behavior.
19. What do you mean by Dynamic Initialization?
Java is a flexible programming language which allows the dynamic initialization of
variables. In other words, at the time of declaration one can initialize the variables. In
java we can declare the variable at any place before it is used. BL2
Example:
int a=10;
float d=2.34f;
20. What do you mean by Variable? What are the rules for variable declaration?
Variable is a fundamental unit of storage in java. The variables are used in combination
BL2
with identifiers, data types, operators and some value for initialization.The syntax of
variable declaration will be: data type name_of_variable=[initialization];
21. What are the steps for execution of a java program?
A program is written in JAVA, the javac compiles it. The result of the JAVA compiler is
the .class file or the bytecode and not the machine native code (unlike C compiler).The
BL2
bytecode generated is a non-executable code and needs an interpreter to execute on a
machine. This interpreter is the JVM and thus the Bytecode is executed by the JVM &
finally program runs to give the desired output.
22. What do you mean by Bytecode? What is JVM and JIT?
Bytecode is an intermediate form of java programs.We get bytecode after compiling the BL2
java program using a compiler called javac. The bytecode is to be executed by java
runtime environment which is called as Java Virtual Machine(JVM). The programs that
are running on JVM must be compiled into a binary format which is denoted by .class
files. The JVM executes .class or .jar files, by either interpreting it or using a just-in-
time compiler (JIT). The JIT is used for compiling and not for interpreting the file. It is
used in most JVMs today to achieve greater speed. BL2
23. What are the different datatypes in Java?
TYPE SIZE RANGE SYNTAX
byte 8 bits -128 to 127 byte i,j;
short 16 bits -32768 to 32767 short a,b;
int 32 bits -2,147,483,648 int i,j;
to 2,417,483,647
long 64 bits -9,223,372,036,854,775,808 long x,y;
BL2
to 9,223,372,036,854,775,807
float 32 bits -9,223,372,036,854,775,808 float p,q;
to 9,223,372,036,854,775,807
double 64 bits 1.4e-045 to 3.4e+038 double a,b;
char 16 bits 4.9e-324 to 1.8e+308 char a;
boolean 1 bit true or false true or
false

St. Joseph’s Institute of Technology 6


CS4352- Java Programming Department of IT 2023-2024

24. What is Garbage collection?


Objects are dynamically allocated by using the new operator, dynamically allocated
objects must be manually released by use of a delete operator. Java takes a different
approach; it handles deallocation automatically this is called garbage collection. When
BL1
no references to an object exist, that object is assumed to be no longer needed, and the
memory occupied by the object can be reclaimed. Garbage collection only occurs
sporadically (if at all) during the execution of your program. It will not occur simply
because one or more objects exist that are no longer used.
25. What is the difference between Methods and Constructor?
A constructor is a member function of a class that is used to create objects of that class.
It has the same name as the class itself, has no return type, and is invoked using the new
BL2
operator.
A method is an ordinary member function of a class. It has its own name, a return type
(which may be void), and is invoked using the dot operator.
26. What is passed by reference?
Objects are passed by reference.In java we can create an object pointing to a particular
location ie NULL location by specifying : <class name> <object name>;and also can
BL1
create object that allocates space for the variables declared in that particular class by
specifying
Syntax:<object name > = new <class name> ( );
27. What is Constructors in Java? What are its types?( Nov 2020, April 2021)
A constructor is a special method that is used to initialize an object.The name of the
constructor and the name of the class must be the same. A constructor does not have
any return type.The constructor invoked whenever an object of its associated class is
created. It is called constructor because it creates the values for the data fields of the
class.
A constructor has same name as the class in which it resides. Constructor in Java
cannot be abstract, static, final or synchronized. These modifiers are not allowed
for constructors.
Class Car
{String name; BL1
String model;
Car()//Constructor
{name=””;
model=””;
}}
There are two types of Constructor
Default Constructor and Parameterized constructor
Each time a new object is created at least one constructor will be invoked. Car
c=new Car(); //Default constructor invoked
Car c=new Car(name); //Parameterized constructor invoked
28. What is array? How to declare array and how to allocate the memory to for array?
Java array contains elements of similar data type. It is a data structure where we store
similar elements. We can store only fixed set of elements in a java array. Array in java
is index based, first element of the array is stored at 0 index.
BL2
data_typearray_name []; and to allocate the memory-
array_name=new data_type[size];where array_name represent name of the array, new
is a keyword used to allocate the memory for arrays, data_type specifies the data type of
array elements and size represents the size of an array. For example:int a=new int[10];
29. How will you declare Two Dimensional array?
The two dimensional arrays are the arrays in which elements are stored in rows as well
as columns. For example:
10 20 30
BL2
40 50 60
70 80 90
The two dimensional array can be declared and initialized as follows
Syntax:data_typearray_name=new data_type[size];For example: int a[][]=new int[3][3];

St. Joseph’s Institute of Technology 7


CS4352- Java Programming Department of IT 2023-2024

30. What is method in java? How to define and call the method?
Method is a programming construct used for grouping the statement together to build a
function. There are two ways by which the method is handled.
1. Defining a method 2. Calling a method
Here is example that helps to understand the concept of method defining and calling.
public class methDemo { BL3
public static void main(String args[]) { int a=10;int b=20;int c=sum(a,b);
System.out.println(“The sum of “+a”+” and “+b+” is=”+c);
}
public static int sum(int num1,int num2)
{
int ans=num1+num2; return ans;}}
31. What is Assert Keyword? (Nov 2018)
An assertion allows testing the correctness of any assumptions that have been made in
the program.Assertion is achieved using the assert statement in Java. While executing BL1
assertion, it is believed to be true. If it fails, JVM throws an error named AssertionError.
assert expression; assert expression1 : expression2;
32. What is down casting?
Doing a cast from a base class to a more specific class. The cast does not convert the
object, just asserts it actually is a more specific extended object. BL1
e.g. Dalamatian d = (Dalmatian) aDog;
33. What are types of Constructors?
Default Constructor, Parameterized Constructor, Copy Constructors are the types of BL1
Constructors.
34. What's the difference between an interface and an abstract class?
An abstract class may contain code in method bodies, which is not allowed in an
interface. With abstract classes,you have to inherit your class from it and Java does not BL2
allow multiple inheritance. On the other hand, you can implement multiple interfaces in
your class.
35. What is meant by static?
When a member is declared as static it can be accessed before any objects of its class are
created and without any reference to any object. these are global variables, no copy of BL1
these variables can be made. staticcan also be declared for methods. and cannot refer to
this or super.
36. List any four Java Doc comments. [NOV 2011]
A Javadoc comment is set off from code by standard multi-line comment tags /* and */.
The opening tag, however, has an extra asterisk, as in /**.The first paragraph is a
BL1
description of the method documented. Following the description are a varying number
of descriptive tags, signifying: The parameters of the method (@param),What the
method returns (@return) and any exceptions the method may throw (@throws)
37. What are the access specifiers/modifiers for classes in Java?(Nov 2018,Nov 2019)
Java Access Specifiers (also known as Visibility Specifiers) regulate access to classes,
fields and methods in java. These specifiers determine whether a field or method in c
BL1
lass, can be used or invoked by another method in another class or sub-class. Access
Specifiers can beused torestrict access. There are 4 types of java access modifiers:
Private, Default, Protected and Public
38. What is a package?(Nov 2014)
A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined BL1
package. There are many built-in packages such as java, lang, awt, javax, swing, net, io,
util, sql etc.
39. What is static methods in Java?
● A static method belongs to the class rather than object of a class.
BL1
● A static method can be invoked without the need for creating an instance of a
class.

St. Joseph’s Institute of Technology 8


CS4352- Java Programming Department of IT 2023-2024

● Static method can access static data member and can change the value of it.
There are two main restrictions for the static method is that the static method cannot use
non static data member or call non-static method directly.
40. What are the control flow statements in Java?( Nov 2020,April 2021)
A programming language uses control statements to control the flow of execution of
program based on certain conditions. These are used to cause the flow of execution to
advance and branch based on changes to the state of a program.
Java’s Selection statements:
• if
BL2
• if-else
• nested-if,if-else-if
• switch-case
• jump – break, continue, return
These statements allow you to control the flow of your program’s execution based
upon conditions known only during run time.
41 What is static variables in Java?
The static keyword in java is used for memory management mainly. We can apply java
static keyword with variables, methods, blocks and nested class. The static keyword
belongs to the class than instance of the class. If you declare any variable as static, it is
known static variable. BL1
The static variable can be used to refer the common property of all objects (that is not
unique for each object) e.g. company name of employees, college name of students etc.
The static variable gets memory only once in class area at the time of class loading.
Advantage - It makes your program memory efficient (i.e it saves memory).
UNIT-I / PART-B
1. Explain the various features of the Object Oriented Programming Language(Nov 2018) BL2
2. (i) With relevant examples explain abstraction and encapsulation.Write a Java program
that uses abstraction and encapsulation.Give self explanatory comments in your
program.(Nov 2014) BL2
(ii) What is polymorphism?Write a Java program that uses polymorphism.Give self
explanatory comments in your program.(Nov 2014,Nov 2019)
3. (i)List out the characteristics of Java.(May 2016)
BL2
(ii)Explain about dynamic method dispatch with an example..(May 2016)
4. How to pass and return the objects to and from the method? BL3
5. Discuss in detail the access specifiers available in Java. BL2
6. Explain the characteristics of OOP.(Nov 2018) BL2
7. Explain the difference between data hiding and data abstraction.(Nov 2019) BL2
8. Explain in detail the various characteristics of Java.(Nov 2019) BL2
9. Explain the concepts of arrays in Java and explain its types with examples? BL2
10. Explain in detail about finalize keyword? (Nov 2018) BL2
11. i) What is a constructor? What is the use of new method?
BL3
ii) Give the syntax for static method and its initialization
12. Write a java program for push and pop operations in stack using arrays in classes and
BL6
object.
13. (i) Write a Java Program to generate Fibonacci Series.(Nov 2017,April 2019) BL4
(ii) Explain how to declare arrays in Java.Give examples.(Nov 2017) BL2
14. i) What is meant by package? How it is created and implemented in JAVA. BL3,
ii) Write a JAVA program to find the smallest number in the given list BL6
15. Consider the following series of number:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, etc.
BL5
Write a Java program to print the above series by getting the numbers of values to be
printed from the user(Nov 2022).
16. Write a Java Program to sort an array of ‘n’ names in alphabetic order.Use classes and
BL6
methods.(April 2018,Nov 2019)
17. Create a java program using local, static, instance variable with proper justification BL6
18. What is JVM?Explain the internal architecture of JVM with neat sketch.(Nov 2019) BL2

St. Joseph’s Institute of Technology 9


CS4352- Java Programming Department of IT 2023-2024

19. Develop a Java program to design the following pattern using any control flow
statements
*
* * BL6
* * *
* * * *
* * * * * (Nov 2022)
UNIT II OBJECT,CLASS,INTERFACES AND PACKAGES
Object-class-constructor-benefits of OOPS-concepts of OOPS- inheritance - polymorphism - abstract
class generic class- Overriding- Overloading- Interface: Implementation of interface-extending
interface-inner class- static and dynamic binding- package: Package as Access Protection-
CLASSPATH setting- Import packages.
UNIT-II / PART-A (CO: C304.2)
1. What is meant by Inheritance and what are its advantages?
Inheritance is a relationship among classes, wherein one class shares the structure or
behavior defined in another class. This is called Single Inheritance. If a class shares the
structure or behavior from multiple classes, then it is called Multiple Inheritance. BL1
Inheritance defines “is-a” hierarchy among classes in which one subclass inherits from
one or more generalized super classes. The advantages of inheritance are reusability of
code and accessibility of variables and methods of the super class by subclasses.
2. What is the difference between superclass and subclass?
A super class is a class that is inherited whereas sub class is a class that does the BL3
inheriting.
3. Brief about super keyword ( ). (Nov 2020,April 2021)
This is used to initialize constructor of base class from the derived class and also access BL1
the variables of base class like super.i = 10.
4. Differentiate between a Class and an Object.
The Object class is the highest-level class in the Java class hierarchy. The Class class is
used to represent the classes and interfaces that are loaded by a Java program. The
Class class is used to obtain information about an object's design. A Class is only a BL3
definition or prototype of real life object. Whereas an object is an instance or living
representation of real life object. Every object belongs to a class and every class
contains one or more related objects.
5. Define super class and subclass.
Super class is a class from which another class inherits.Subclass is a class that inherits BL1
from one or more classes.
6. What are the four types of access modifiers?
There are 4 types of java access modifiers:
1. private
BL1
2. default
3. Protected
4. public
7. What is protected class in Java?
A private member is only accessible within the same class as it is declared. A member
with no access modifier is only accessible within classes in the same package. A BL1
protected member is accessible within all classes in the same package and within
subclasses in other packages.
8. What is protected function?
Protected members that are also declared as static are accessible to any friend or member
function of a derived class. Protected members that are not declared as static are BL1
accessible to friends and member functions in a derived class only through a pointer to,
reference to, or object of the derived class.
9. What is protected method?
● A protected method can be called by any subclass within its class, but not by
BL2
unreleated classes.
● Declaring a method protected defines its access level.

St. Joseph’s Institute of Technology 10


CS4352- Java Programming Department of IT 2023-2024

10. What is final modifier?


The final modifier keyword makes that the programmer cannot change the value
anymore. The actual meaning depends on whether it is applied to a class, a variable, or a
method. BL1
final Classes- A final class cannot have subclasses.
final Variables- A final variable cannot be changed once it is initialized.
final Methods- A final method cannot be overridden by subclasses.
11. What is a constructor in a class?(Nov 2020,April 2021)
In class-based object-oriented programming, a constructor is a special type of
subroutine called to create an object. It prepares the new object for use, often accepting BL1
arguments that the constructor uses to set required member
variables.
12. Why creating an object of the sub class invokes also the constructor of the super
class?
When inheriting from another class, super() has to be called first in the constructor. If BL2
not, the compiler will insert that call. This is why super constructor is also invoked when
a Sub object is created. This doesn't create two objects, only one Sub object. The reason
to have super constructor called is that if super class could have private fields which
need to be initialized by its constructor.
13. What is an Abstract Class?
Abstract class is a class that has no instances. An abstract class is written with the
BL1
expectation that its concrete subclasses will add to its structure and behavior, typically
by implementing its abstract operations.
14. What are inner class and anonymous class?
Inner class: classes defined in other classes, including those defined in methods are
called inner classes. An inner class can have any accessibility including private. BL1
Anonymous class: Anonymous class is a class defined inside a method without a name
and is instantiated and declared in the same place and cannot have explicit constructors.
15. What is an Interface and State its use?(Nov 2019)
Interface is an outside view of a class or object which emphasizes its abstraction while BL1
hiding its structure and secrets of its behavior.
16. What is a base class?
Base class is the most generalized class in a class structure. Most applications have such BL1
root classes. In Java, Object is the base class for all classes.
17. What is meant by Binding, Static binding and Dynamic binding?
Binding: Binding denotes association of a name with a class.
Static binding: Static binding is a binding in which the class association is made during
BL1
compile time. This is also called as Early binding.
Dynamic binding: Dynamic binding is a binding in which the class association is not
made until the object is created at execution time. It is also called as Late binding.
18. What is reflection API? How are they implemented?
Reflection is the process of introspecting the features and state of a class at runtime and
BL2
dynamically manipulate at run time. This is supported using Reflection API with built-
in classes like Class, Method, Fields, Constructors etc
19. What is the difference between a static and a non-static inner class?
A non-static inner class may have object instances that are associated with instances of BL3
the class's outer class. A static inner class does not have any object instances.
20. Can you have an inner class inside a method and what variables can you access?
BL3
Yes, we can have an inner class inside a method and final variables can be accessed.
21. What is the difference between abstract class and interface?
ABSTRACT CLASS INTERFACE
1.Abstract class must have at least one 1.All the methods declared inside an
abstract method and others may be interface are abstract
BL2
concrete or abstract
2. key word abstract must be used for the 2.We need not use that keyword for the
methods methods.
3.Abstract class must have subclasses 3.Interface can’t have subclasses

St. Joseph’s Institute of Technology 11


CS4352- Java Programming Department of IT 2023-2024

22. What is interface and state its use?


Interface is similar to a class which may contain method’s signature only but not bodies
and it is a formal set of method and constant declarations that must be defined by the
class that implements it. Interfaces are useful for:
a) Declaring methods that one or more classes are expected to implement BL2
b) Capturing similarities between unrelated classes without forcing a class
relationship.
c) Determining an object’s programming interface without revealing the actual
body of the class.
23. Difference between class and interface.( Nov 2020,April 2021)
CLASS INTERFACE
Class are used to create new reference Interface are used to create new
types reference types BL2
A class is a collection of fields and An interface has fully abstract methods
methods that operate on fields i.e.methods with nobody
Class can be instantiated Interface can never be instantiated
24. What is extending interface?
An interface can extend another interface in the same way that a class can
extend another class. The extends keyword is used to extend an interface, and the
child interface inherits the methods of the parent interface.
Syntax: BL1
interface interface_name
{ Public void method1():
Public void method2():
}
25. What is Runtime Exception?(Nov 2018)
Runtime Exceptions are exceptions that can be prevented programmatically. BL1
E.g NullPointer Exception, ArrayIndexOutOfBound Exception.
26. What is a cloneable interface and how many methods does it contain?
BL1
It is not having any method because it is a TAGGED or MARKER interface.
27. What are the methods provided by the object class?
The Object class provides five methods that are critical when writing multithreaded Java
programs:
● notify BL1
● notify All
● wait (three versions)
28. Define: Dynamic proxy.
A dynamic proxy is a class that implements a list of interfaces, which you specify at
runtime when you create the proxy. To create a proxy, use the static method
java.lang.reflect.Proxy::newProxyInstance(). BL1
This method takes three arguments:
The class loader to define the proxy class, A list of interfaces that the proxy instance
implements, An invocation handler to intercept and handle method calls
29. What is object cloning?(Nov 2018,Nov 2019,Nov 2014)
It is the process of duplicating an object so that two identical objects will exist in the BL1
memory at the same time.
30. Define Package.(Nov 2014)
To create a package is quite easy: simply include a package command as the first
statement in a Java source file. Any classes declared within that file will belong to the
BL1
specified package. The package statement defines a name space in which classes are
stored. If you omit the package statement, the class names are put into the default
package, which has no name.
31. What is Class Hierarchy?(Nov 2018)
A class can be defined in terms of other classes. The class hierarchy defines the BL1
inheritance relationship between the classes. The root of the class hierarchy is the class

St. Joseph’s Institute of Technology 12


CS4352- Java Programming Department of IT 2023-2024

Object. Every class in Java directly or indirectly extends (inherits from) this class.
32. Define Array list class.
The ArrayList class extends AbstractList and implements the List interface. ArrayList is
a generic class that has this declaration:
class ArrayList<E>
Here, E specifies the type of objects that the list will hold. BL1
An ArrayList is a variable-length array of object references. That is, an ArrayList can
dynamically increase or decrease in size. Array lists are created with an initial size.
When this size is exceeded, the collection is automatically enlarged. When objects are
removed, the array can be shrunk.
UNIT-II / PART-B
1. Explain the concept of inheritance with suitable examples. (Nov 2018,Nov 2019) BL2
2. Write a Java Proogram to calculate electricity bill using Inheritance.The program should
get the inputs of watts per hour and unit rate.Check your program for the following
case:Assume a consumer consumes 5000 watts per hour daily for one month.Calculate BL5
the total energy bill of that consumer if per unit rate is 7[1 unit= 1 k Wh]
(Nov 2020,April 2021)
3. Explain interfaces with example.( Nov 2020,April 2021,Nov 2021) BL2
4. Differentiate method overloading and method overriding. Explain with a program. BL3
5. Explain method overriding. with an example .(Nov 2021). BL2
6. Explain about the object and abstract classes with the syntax. BL2
7. Discuss in detail about inner class. With its advantages. BL3
8. What is meant by object cloning? Explain it with an example.(Nov 2019) BL2
9. Explain how inner classes and anonymous classes works in java program. BL3
10. What is a Package? What are the benefits of using packages? Write down the steps in
BL4
creating a package and using it in a java program with an example.
11. (i)What is inheritance? How inheritance is implemented in java?
(ii)Create a class Book and define display method to display book information. Inherit
Reference_Book and Magazine classes from Book class and override display method of BL5
Book class in Reference_Book and Magazine classes. Make necessary assumptions
required.(Nov 2022)
12. Develop an Interest interface which contains simpleInterest and compInterest methods
BL5
and static final field of Rate 25%. Write a class to implement those methods(Nov 2022)
13. Create an abstract Reservation class which has Reserve() abstract method. Implement the
sub-classes like ReserveTrain and ReserveBus classes and implement the same. Use BL6
necessary variables, methods for reserving tickets(Nov 2022)
UNIT III EXCEPTION AND FILE I/O STREAMS
Exceptions-benefits of exception-Types of Exceptions-Errors-Control flow- JVM reaction to Exception
usage of try, catch, throw, final and finally keyword-rethrowing exceptions, exception specification, built in
exceptions-File I/O: Standard Streams-Reading and writing Streams- Byte Array Stream-Data
Stream- File Stream- Input and output Stream.
UNIT-III / PART-A (CO: C304.3)
1. What are the types of errors?
BL1
Compile time errors and Run time errors are the two types of errors.
2. Define Java Exception.
A Java exception is an object that describes an exceptional (that is, error) condition that
BL1
has occurred in a piece of code. When an exceptional condition arises, an object
representing that exception is created and thrown in the method that caused the error.
3. State the five keywords in exception handling.
Java exception handling is managed via five keywords: try, catch, throw, throws, and BL2
finally.
4. What are the uses of exception ?
The class at the top of the exception class hierarchy is the Throwable class, which is a
direct subclass of the Object class. Throwable has two direct subclasses - Exception and BL2
Error. The Exception class is used for exception conditions that the application may
need to handle.

St. Joseph’s Institute of Technology 13


CS4352- Java Programming Department of IT 2023-2024

5. What is chained exception?(Nov 2021)


Chained Exceptions allows to relate one exception with another exception, i.e one
exception describes cause of another exception. For example, consider a situation in BL2
which a method throws an ArithmeticException because of an attempt to divide by zero
but the actual cause of exception was an I/O error which caused the divisor to be zero.
6. What does java.lang.StackTraceElement represent?
The java.lang.StackTraceElement class element represents a single stack frame. All
stack frames except for the one at the top of the stack represent a method invocation. The BL1
frame at the top of the stack represents the execution point at which the stack trace was
generated.
7. What are the useful methods of throwable classes
The following are the useful methods of throwable classes:
● public String getMessage()
● public String getLocalizedMessage() BL1
● public synchronized ThrowablegetCause()
● public String toString()
● public void printStackTrace()
8. Compare throw and throws.
● Throw is used in method implementation & throws is used in method signature.
BL2
● Using throw keyword we can throw only 1 exception at a time & throws can
declare multiple exceptions at a time.
9. What is the use of try and catch exception?
Try-catch block is used for exception handling in the program code. try is the start of the
block and catch is at the end of try block to handle the exceptions. A Program can have BL2
multiple catch blocks with a try and try-catch block can be nested also. catch block
requires a parameter that should be of type Exception.
10. What is the use of finally exception?( Nov 2020,April 2021)
Finally block is optional and can be used only with try-catch block. Since exception halts
the process of execution, we might have some resources open that will not get closed, so BL2
we can use finally block. finally block gets executed always, whether exception occurrs
or not.
11. How to write custom exception in Java?
Extend Exception class or any of its subclasses to create our custom exception class. The
BL2
custom exception class can have its own variables and methods and one can use to pass
error codes or other exception related information to the exception handler.
12. What is OutOfMemoryError in Java?
OutOfMemoryError in Java is a subclass of java.lang.VirtualMachineError and it is BL2
thrown by JVM when it runs out of heap memory.
13. What is difference between final, finally and finalize in Java?
Final and finally are keywords in java whereas finalize is a method.
Final keyword can be used with class variables so that they can’t be reassigned, with
class to avoid extending by classes and with methods to avoid overriding by subclasses.
BL2
Finally keyword is used with try-catch block to provide statements that will always gets
executed even if some exception arises, usually finally is used to close resources.
finalize() method is executed by Garbage Collector before the object is destroyed, it’s
great way to make sure all the global resources are closed.
14 What happens when exception is thrown by main method?
When exception is thrown by main() method, Java Runtime terminates the program and BL1
print the exception message and stack trace in system console.
15. Can we have an empty catch block?
We can have an empty catch block but it’s the example of worst programming. We
should never have empty catch block because if the exception is caught by that block, we BL2
will have no information about the exception and it will be a nightmare to debug it.

St. Joseph’s Institute of Technology 14


CS4352- Java Programming Department of IT 2023-2024

16. How Java Exception Hierarchy categorized?


Java Exceptions are hierarchical and inheritance is used to categorize different types of
exceptions. Throwable is the parent class of Java Exceptions Hierarchy and it has two BL2
child objects – Error and Exception. Exceptions are further divided into checked
exceptions and runtime exception.
17. What are input and output streams?(Nov 2020,April 2021)
An I/O Stream represents an input source or an output destination. A stream can
BL1
represent many different kinds of sources and destinations, including disk files, devices,
other programs, and memory arrays.
18. What is a byte stream in java?
Programs use byte streams to perform input and output of 8-bit bytes. All byte stream
BL1
classes are descended from InputStream and OutputStream.There are many byte stream
classes. The file I/O byte streams, are FileInputStream and FileOutputStream.
19. Define stream.
A stream can be defined as a sequence of data.There are two kinds of Streams such as
InputStream and OutputStream BL1
InputStream − The InputStream is used to read data from a source.
OutputStream − The OutputStream is used for writing data to a destination.
20. What is character stream?
Character streams are used to perform input and output for 16-bit unicode. Though there
BL1
are many classes related
to character streams but the most frequently used classes are, FileReader and FileWriter.
21. What are directories in Java?
A directory is a File which can contain a list of other files and directories. You BL1
use File object to create directories, to list down files available in a directory.
22. What are the two useful methods to create directories?
There are two useful File utility methods, which can be used to create directories
The mkdir( ) method creates a directory, returning true on success and false on failure.
BL2
Failure indicates that the path specified in the File object already exists, or that the
directory cannot be created because the entire path does not exist yet.
The mkdirs() method creates both a directory and all the parents of the directory.
23. State the use of java.io.Console.
The java.io.Console class which provides convenient methods for reading input and
BL2
writing output to the standard input (keyboard) and output streams (display) in
command-line.
24. What is the use of java console class?
The Java Console class is be used to get input from console. It provides methods to read
BL2
texts and passwords. If you read password using Console class, it will not be displayed
to the user. The java.io.Console class is attached with system console internally.
25. State the classes used to read file in java.
The classes are:
BL2
● FileReader for text files in your system's default encoding
● FileInputStream for binary files and text files that contain 'weird' characters.
UNIT-III / PART-B
1. Explain in detail the important methods of Java Exception Class? BL2
2. Explain the different scenarios causing “Exception in thread main”? BL6
3. How will you create your Own Exception Subclasses? BL6
4. Explain in detail Chained exception with an example program.( Nov 2020,April 2021) BL2
5. Explain in detail the various exception types with its hierarchy.(Nov 2018) BL2
6. Write programs to illustrate arithmetic exception, ArrayIndexOutOfBounds Exception
BL2
and NumberFormat Exception.
7. Create two exception classes that can be used by the stack classes developed by TRY BL6
8. Evaluate a try block that is likely to generate three types of exception and then
BL5
incorporate necessary catch blocks and handle them appropriately
9. Show how to learn from and copy to a different file with suitable examples? BL4

St. Joseph’s Institute of Technology 15


CS4352- Java Programming Department of IT 2023-2024

10. Discuss about concatenating and buffering files BL2


11. Give suitable examples to learn from and write bytes to a file. BL2
12. Construct a Java program that reads a file name from the user, displays information
about whether the file exists, whether the file is readable, or writable, the type of file and BL6
the length of the file in bytes.(Nov 2022)
13. Develop the Java program to concatenate the two files and produce the output in the
BL6
third file.(Nov 2022)
14. (i)Develop a program to read and count the characters from files.(Nov 2022)
BL6
(ii)Develop a Java program to transfer the content of one file to another file.(Nov 2022)
15. Analyze the following in detail with example program
BL4
(i) Checked Exception. (ii) Unchecked exception.
UNIT IV THREADS AND GENERIC CLASSES
Understanding Threads, Needs of Multi-Threaded Programming, Thread Life-Cycle, Thread
Priorities,Synchronizing Threads, Inter Communication of Threads, Critical Factor in Thread –
Deadlock-Generic: Introduction to Generics-Built-in Generics collections-writing simple generic
class.
UNIT-IV / PART-A (CO: C304.4)
1. How Threads are created in Java?(Dec 2021)
Threads are created in two ways. They are by extending the Thread class and by BL2
implementing Runnable interface.
2. Define Thread.
A thread is a single sequential flow of control within program. Sometimes, it is called an
execution context or light weight process. A thread itself is not a program.Thread cannot
BL1
run on its own. Rather, it runs within a program. A program can be divided into a
number of packets of code, each representing a thread having its own separate flow of
control.
3. What is Multi-threading?(Nov 2018)
Multithreading is a conceptual programming concept where a program(process) is
divided into two or more subprograms(process), which can be implemented at the same
BL1
time in parallel. A multithreaded program contains two or more parts that can run
concurrently. Each part of such a program is called a thread, and each thread defines a
separate path of execution.
4. What is meant by Multitasking?
Multitasking, in an operating system, is allowing a user to perform more than one
computer task (such as the operation of an application program) at a time. The operating
BL1
system is able to keep track of where you are in these tasks and go from one to the other
without losing information. Multitasking is also known as multiprocessing.Java Support
Multitasking in network platform.
5. What do you mean by Thread Scheduling?
Execution of multiple threads on a single CPU in some order is called scheduling. The
Java runtime environment supports a very simple, deterministic scheduling algorithm BL1
called fixed-priority scheduling. This algorithm schedules threads on the basis of their
priority relative to other Runnable threads.
6. What is Synchronization thread?(Nov 2021)
When two or more threads need access to a shared resource, they need some way to
BL1
ensure that the resource will be used by only one thread at a time. The process by which
this synchronization is achieved is called thread synchronization.
7. What is daemon thread?
A daemon thread is a thread that does not prevent the JVM from exiting when the
BL1
program finishes but the thread is still running. An example for a daemon thread is the
garbage collection.
8. Define thread group.
Every Java thread is a member of a thread group. Thread groups provide a mechanism
for collecting multiple threads into a single object and manipulating those threads all at BL1
once, rather than individually. For example, you can start or suspend all the threads
within a group with a single method call.

St. Joseph’s Institute of Technology 16


CS4352- Java Programming Department of IT 2023-2024

9. What is the need of wrapper classes?


They convert primitive data types into objects.
BL2
The classes in java util package handles only objects and hence wrapper classes help in
this case also
10. Why do we need run() and start() method both? Can we achieve it with only run
method?
The separate start() and run() methods in the Thread class provide two ways to create
threaded programs. The start() method starts the execution of the new thread and calls
the run() method. The start() method returns immediately and the new thread normally
continues until the run() method returns.
The Thread class' run() method does nothing, so sub-classes should override the BL3
method with code to execute in the second thread. If a Thread is instantiated with a
Runnable argument, the thread's run() method executes the run() method of the
Runnable object in the new thread instead.Depending on the nature of your threaded
program, calling the Thread run() method directly can give the same output as calling
via the start() method, but in the latter case the code is actually executed in a new
thread.
11. What is thread priority?
Every Java thread has a priority that helps the operating system determine the order in
which threads are scheduled. Java priorities are in the range between
MIN_PRIORITY(a constant of 1) and MAX_PRIORITY( a constant of 10). By default,
BL1
every thread is given priority NORM_PRIORITY(a constant of 5).Threads with higher
priority are more important to a program and should be allocated processor time before
lower- priority threads. However, thread priorities cannot guarantee the order in which
threads execute and very much platform independent.
12. List out the methods of object class to perform inter thread communication?
⮚ wait() – This method make the current thread to wait until another
thread invokes the notify() method.
⮚ notify() – This method wakes up a thread that called wait() on same BL2
object.
⮚ notifyAll() – This method wakes up all the thread that called wait() on
same object.
13. What are the various states of a thread?(Nov 2019,Nov 2021)
● Running
● Runnable
● Active thread BL1
● Newborn
● Blocked
● Dead
14. What is Thread Pool?
A thread pool is a managed collection of threads that are available to perform tasks.
● Improved performance when executing large numbers of tasks due to reduced per-
BL1
task invocation overhead
● A means of bounding the resources, including threads, consumed when executing a
collection of tasks.
15. What is daemon thread and which method is used to create the daemon thread?
Daemon thread is a low priority thread which runs intermittently in the back ground
BL1
doing the garbage collection operation for the java runtime system. setDaemon method
is used to create a daemon thread.
16. Write short note on isAlive() and join()?
isAlive() and join() methods are used to determine whether a thread has finished or not.
BL1
First, you can call isAlive() on the thread. This method is defined by Thread, and its
general form is:final Boolean isAlive()

St. Joseph’s Institute of Technology 17


CS4352- Java Programming Department of IT 2023-2024

The isAlive() method returns true if the thread upon which it is called is still running. It
returns false otherwise. While isAlive() is occasionally useful, the method that you
will more commonly use to wait for a thread to finish is called join(). The general
form is: final void join() throws InterruptedException
This method waits until the thread on which it is called terminates
17. Define thread group.
Every Java thread is a member of a thread group. Thread groups provide a mechanism
for collecting multiple threads into a single object and manipulating those threads all at BL1
once, rather than individually. For example, you can start or suspend all the threads
within a group with a single method call.
18. Why do we need generics in Java?(Nov/Dec 2018)
Code that uses generics has many benefits over non-generic code: Stronger type checks
at compile time. A Java compiler applies strong type checking to generic code and issues BL2
errors if the code violates type safety.Fixing compile-time errors is easier than fixing
runtime errors, which can be difficult to find.
19. How to create generic class?
A class that can refer to any type is known as generic class. Here, we are using T type
parameter to create the generic class of specific type.
Let’s see the simple example to create and use the generic class.
Creating generic class:
BL2
class MyGen<T>{ T obj;
void add(T obj){this.obj=obj;} T get()
{return obj;} }
The T type indicates that it can refer to any type (like String, Integer, Employee etc.).
The type you specify for the class, will be used to store and retrieve the data.
20. How to declare a java generic bounded type parameter?
To declare a bounded type parameter, list the type parameter’s name, followed by the
extends keyword, followed by its upper bound, similar like below method.
Public static<T extends Comparable<T>>int compare(Tt1, Tt2)
{
BL2
return t1.compareTo(t2);
}
The invocation of these methods is similar to unbounded method except that if we will
try to use any class that is not Comparable, it will throw compile time error.Bounded
type parameters can be used with methods as well as classes and interfaces.
21. What are wildcards in generics?
In generic code, the question mark (?), called the wildcard, represents an unknown type.
The wildcard can be used in a variety of situations: as the type of a parameter, field, or BL1
local variable; sometimes as a return type (though it is better programming practice to
be more specific).
22. What is erasure in Java?
Generics were introduced to the Java language to provide tighter type checks at compile
BL1
time and to support generic programming. To implement generics, the Java compiler
applies type erasure to: Replace all type parameters in generic types with their bounds.
23. What are the restrictions on generics?
To use Java generics effectively, you must consider the following restrictions:
● Cannot Instantiate Generic Types with Primitive Types
● Cannot Create Instances of Type Parameters
● Cannot Declare Static Fields Whose Types are Type Parameters BL1

● Cannot Use Casts or instance of With Parameterized Types


● Cannot Create Arrays of Parameterized Types
● Cannot Create, Catch, or Throw Objects of Parameterized Types
24. State the two challenges of generic programming in virtual machines.
BL2
● Generics are checked at compile-time for type-correctness. The generic type

St. Joseph’s Institute of Technology 18


CS4352- Java Programming Department of IT 2023-2024

information is then removed in a process called type erasure.


● Type parameters cannot be determined at run-time
25. When to use bounded type parameter?
There may be times when you want to restrict the types that can be used as type
arguments in a parameterized type. For example, a method that operates on numbers BL2
might only want to accept instances of Number or its subclasses. This is what bounded
type parameters are for.
UNIT-IV / PART-B
1. What are the two ways of thread creation? Explain with suitable examples. BL2
2. With illustrations explain multithreading,interrupting threads,thread states and thread
BL3
properties (Nov 2020, April 2021)
3. Describe the life cycle of thread and various thread methods.(Nov 2018) BL2
4. Explain the thread properties in detail. BL2
5. Explain inter thread communication. (Nov 2018, Nov 2021) BL2
6. Write a java program that synchronizes three different threads of the same program and
BL6
displays the contents of the text supplies through the threads.
7. Write a java program for inventory problem to illustrate the usage of thread
synchronized keyword and inter thread communication process. They have three classes BL6
called consumer, producer and stock.(Nov 2022)
8. Explain in detail about wrappers with example. BL2
9. Illustrate the use of Auto boxing with example. BL3
10. Design two threads to display odd numbered element in an array of size50 and even
numbered element in another array of size 50.Create instances of the above thread and BL4
run them.
11. Explain in detail about generic classes and methods in java with example.(Nov 2021) BL2
12. Describe briefly about generics with wildcards. BL2
13. What are the restrictions are considered to use java generics effectively? Explain in
BL2
detail.
14. Generalize multithreading for an sample sequence of strings with a delay of 1000
BL4
millisecond for displaying it using Java threads.(Nov 2022)
15. Construct a Java program to perform the following tasks using three different threads.
Each thread will be responsible for its own task only. Among these three threads one will
find the average number of the input numbers, one will be responsible for finding the BL5
Maximum number from the input array of numbers, and one will be responsible for
finding the Minimum number from the input array of numbers.(Nov 2020,April 2021)
UNIT V JAVAFX EVENT HANDLING, CONTROLS AND COMPONENTS FOR GUI
PROGRAM
JAVAFX Events and Controls: Event Basics – Handling Key and Mouse Events. Controls:
Checkbox, ToggleButton – RadioButtons – ListView – ComboBox – ChoiceBox – Text Controls
ScrollPane.Layouts – FlowPane – HBox and VBox – BorderPane – StackPane – GridPane. Menus–
Basics – Menu – Menu bars – MenuItem.
UNIT-V / PART-A (CO: C304.5)
1. What is an Applet?
BL1
Applet is a Java application, which can be executed in JVM, enabled web browsers.
2. What are methods available in the Applet class?
init() - To initialize the applet each time it's loaded (or reloaded).
start() - To start the applet's execution, such as when the applet's loaded or when the
user revisits a page that contains the applet.
BL1
stop() - To stop the applet's execution, such as when the user leaves the applet's page
or quits the browser.
paint()- To display the image
destroy - To perform a final cleanup in preparation for unloading.
3. What is Window adapter class?(Nov 2018)
WindowAdapter is an abstract (adapter) class for receiving window events. This class is BL1
convenience class for creating listener objects.

St. Joseph’s Institute of Technology 19


CS4352- Java Programming Department of IT 2023-2024

4. What is AWT?(Nov 2018)


A collection of graphical user interface (GUI) components that were implemented using
native-platform versions
BL1
of the components. These components provide that subset of functionality which
is common to all native platforms. Largely supplanted by the Project Swing
component set.
5. What is the relationship between an event- listener interface and an event adapter
class?
● An event-listener interface allows describing the methods which must be
BL2
implemented by one of the event handler for a specific event.
● An event-adapter allows default implementations of an event-listener interface of a
specific event.
6. List out some UI components available in AWT.
● Buttons (java.awt.Button)
● Checkboxes (java.awt.Checkbox)
● Single-line text fields (java.awt.TextField)
● Larger text display and editing areas (java.awt.TextArea) BL1
● Labels (java.awt.Label)
● Lists (java.awt.List)
● Menus (java.awt.Menu, java.awt.MenuItem, java.awt.CheckboxMenuItem)
● Containers (java.awt.Panel, java.awt.Window and its subclasses)
7. Write some methods, which are used to add UI components in Applet.
● add - Adds the specified Component.
BL1
● remove - Removes the specified Component.
● setLayout - Sets the layout manager.
8. How can you prevent the overwriting of a displayed text in a TextField of a java
program?
If you create a TextField object with default text then setting the prompt text will not
overwrite the default text. To set the prompt text for a TextField use the
BL2
setPromptText method:
txtFld.setPromptText("Enter Name..");
To find the value of the prompt text of a TextField object use the getPromptText
method:String promptext = txtFld.getPromptText();
9. How Events are handled in java ?
A source generates an Event and send it to one or more listeners registered with the BL2
source. Once event is received by the listener, they process the event and then return.
Events are supported by a number of Java packages, like java.util, java.awt and
java.awt.event. BL1
10. How does a radio button in java differ from a check box?
● Radio buttons are used when there is a list of two or more options that are
mutually exclusive and the user must select exactly one choice. In other words,
clicking a non-selected radio button will deselect whatever other button was
previously selected in the list. BL2
● Checkboxes are used when there are lists of options and the user may select any
number of choices, including zero, one, or several. In other words, each checkbox
is independent of all other checkboxes in the list, so checking one box doesn't
uncheck the others.
11. Name the listener methods that must be implemented for the key listener interface.
(NOV 2013)
void keyTyped(KeyEvent e) BL1
void keyPressed(KeyEvent e)
void keyReleased(KeyEvent e)

St. Joseph’s Institute of Technology 20


CS4352- Java Programming Department of IT 2023-2024

12. What are the components of Event Handling


Events : An event is a change in state of an object.
Events Source : Event source is an object that generates an event. BL1
Listeners : A listener is an object that listens to the event. A listener gets notified when
an event occurs.
13. Write Syntax of HBox
HBoxhbox=new HBox();
BL2
Button button1=new Button(“Button Number 1”);
Button button2=new Button(“Button Number 2”);
14. Mention some Event Classes and Interface
Event Classes Description Listener Interface
generated when button is pressed,
ActionEvent ActionListener
menu-item is selected, list-item is
double clicked
generated when mouse is dragged,
MouseEvent moved,clicked,pressed or released MouseListener
and also when it enters or exit a
component
KeyEvent generated when input is received KeyListener
BL1
from keyboard
ItemEvent generated when check-box or list ItemListener
item is clicked
MouseWheelEvent generated when mouse wheel is MouseWheel
moved Listener
generated when window is activated,
WindowEvent WindowListener
deactivated,deiconified, iconified,
opened or closed
generated when component is ComponentEvent
ComponentEvent
hidden, moved,resized or set visible Listener
15. What is a layout manager & what are the types of layout managers available in
java AWT?
A layout manager is an object that is used to organize components in a container. The BL1
different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout
and GridBagLayout.
16. Define swing in java.
Java Swing is a part of Java Foundation Classes (JFC) that is used to create window-
BL1
based applications. It is built on the top of AWT (Abstract Windowing Toolkit) API and
entirely.
17. Why are swing components called lightweight component?
Swing is considered lightweight because it is fully implemented in Java, without calling BL2
the native operating system for drawing the graphical user interface components.
18. Mention some class for java swing
The javax.swing package provides classes for java swing API such as JButton, BL1
JTextField, JTextArea,JRadioButton, JCheckbox, JMenu, JColorChooser.
19. What is the difference between scrollbar and scrollpane?
A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and BL3
handles its own events and perform its own scrolling.
20. What is the use of JButton and mention the constructor of JButtonclass.
JButton class provides functionality of a button. JButton class has three BL2
constuctors,Button(Icon ic),JButton(String str),JButton(String str, Icon ic)
21. What is the use of JTextField and mention the constructor of JTextFieldclass.
JTextField is used for taking input of single line of text. It is most widely used text
BL2
component. It has three constructors, JTextField(int cols), JTextField(String str, int
cols),JTextField(String str)cols represent the number of columns in text field.
22. What is meant by controls and what are different types of controls in AWT?
BL1
Controls are components that allow a user to interact with your application and the AWT

St. Joseph’s Institute of Technology 21


CS4352- Java Programming Department of IT 2023-2024

supports the following types of controls: Labels, Push Buttons, Check Boxes, Choice
Lists, Lists, Scrollbars, Text Components. These controls are subclasses of Component.
23. What is the difference between choice and list?
A Choice is displayed in a compact form that requires you to pull it down to see the list
of available choices and only one item may be selected from a choice. A List may be BL3
displayed in such a way that several list items are visible and it supports the selection of
one or more list items.
24. What are the different types of flowpanes in Java?
There are 2 types of flowpanes- horizontal and vertical where the former lays out the
child nodes in rows that wrap up along the pane width and latter lays out the child nodes BL1
in columns that wrap up along the pane height. Java
FlowPane can be instantiated from the class javafx.scene.layout.FlowPane.
25. How to use stackpane in JavaFX?
The node added first is placed at the bottom of the stack and the next node is placed on
top of it. The class named StackPane of the package javafx.scene.layout represents the BL2
stack pane layout. The Text Flow layout arranges multiple text nodes in a single
flow.The layout is based on the concept of stack itself in Java environment.
UNIT-V / PART-B
1. What is event delegation model and what are the event classes and event interfaces? BL2
2. Explain various components in AWT?(Nov 2018,Nov 2021) BL2
3. What is event handling in java? List out the available event classes and listener
BL2
interfaces with suitable example.
4. Explain the layout managers in Java also describe the concept of menu creation.(Nov
BL2
2018)
5. What is an adapter class? Describe about various adapter classes in detail. BL2
6. Explain about JComboBoxclass, JCheckBoxclass BL2
7. Develop a java program that have 11 text fields one submit button. When you press the
BL6
button first 10 text field’s average has to be displayed in the 11th text field..(Nov 2022)
8. Develop a java code that keeps the count of right clicks of mouse. BL4
9. Explain about JButtonclass, JTextAreaclass, JFrameclass BL2
10. Develop java program that changes the color of a filled circle when you make a right
BL6
click.
11. Outline the use of setSize(),getSize(),setVisible() and setTitle() methods when working
BL4
with frame windows with their signature.(Nov 2018)
12. How will you display an image on the frame in a window using java. BL4
13. Write a program to develop HBox and VBox BL3
14. Write a program to perform BorderPane BL3
15. Develop StackPaneand GridPanein Java BL3
16. Demonstrate any four mouse event handlers with example.(Nov 2020,April 2021) BL6
17. Explain about Menu bars and Menuitems. BL2
18. What is event delegation model and what are the event classes and event interfaces? BL2
19. Write a program to create a frame with the following menus, such that the corresponding
geometric object is created when a menu is clicked.
BL6
a.Circle. b.Rectangle.
c.Line. d.Diagonal for the rectangle. .(Nov 2022)
20. Write a Java program to implement a 3 frame in a window, In each frame create
BL6
rectangle and fill each one with (i) color (ii) texture and (iii) gradient.(Nov 2022)
21. Develop a Java program to implement the following Create four check boxes. The initial
state of the first box should be in checked state. The status of each check box should be
BL6
displayed. When we change the state of a check box, the status should be displayed and
updated. (Nov 2022)

St. Joseph’s Institute of Technology 22

You might also like