Abstraction, Encapsulation, Inheritance, Polymorphism: What Are The Features of Object Oriented Programming?
Abstraction, Encapsulation, Inheritance, Polymorphism: What Are The Features of Object Oriented Programming?
Abstraction, Encapsulation, Inheritance, Polymorphism: What Are The Features of Object Oriented Programming?
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 3 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
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.
24 What is Constructors in Java? What are its types?
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.
There are two types of Constructor
Default Constructor – constructor without argument
Parameterized constructor – constructor with arguments
25 How will you declare a two dimensional array?
The two dimensional array can be declared and initialized as follows
Syntax: data_type array_name[][]=new data_type[size][size];
For example: int a[][]=new int[3][3];
26 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.
e.g. Dalamatian d = (Dalmatian) aDog;
27 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 allow
multiple inheritance. On the other hand, you can implement multiple interfaces in your
class.
28 Write down the importance of static keyword?
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
these variables can be made. static can also be declared for methods. and cannot refer to
this or super.
29 List out java documentation comments
/* text */
//text
/*** documentation */
30 Define access specifier/modifier? (Nov./Dec.2018)(Nov/Dec 2019)
Access specifiers/modifiers in Java helps to restrict the scope of a class, constructor,
variable, method or data member. There are four types of access modifiers available in
java:
Default – No keyword required , Private , Protected and Public
31 What is a package?
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 package. There
are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
32 What is the use of static keyword 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 an instance of the class
33 What are the control flow statements in java?
if, if-else, nested-if , if-else-if
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 4 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
• switch-case
• jump – break, continue, return
UNIT-I / PART-B
1 (i) Explain the characteristics of OOPs (Nov./Dec.2018)
(ii) Explain the features and characteristics of JAVA(Nov/Dec 2019)
2 i) Describe the typical java program structure.
ii) Explain the general java program compilation and execution.
3 What are the different data types in JAVA? Explain each of them with example.
4 How to pass and return the objects to and from the method?
5 Discuss in detail the access specifiers available in Java.
6 Explain Packages in detail.
7 Explain Constructors with examples.
8 Explain in detail the various operators in Java.
9 Explain the concepts of arrays in Java and explain its types with examples?
10 Explain in detail about static variable and static method in Java with example?
11 (i) What is a method? How method is defined? Give example (Nov./Dec.2018)
(ii) State the purpose of finalize() method in java. With an example explain how finalize()
method can be used in java program
UNIT II INHERITANCE AND INTERFACES
Inheritance – Super classes- sub classes –Protected members – constructors in sub classes- the
Object class – abstract classes and methods- final methods and classes – Interfaces – defining an
interface, implementing interface, differences between classes and interfaces and extending
interfaces - Object cloning -inner classes, Array Lists - Strings
UNIT-II / PART-A
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. The advantages of inheritance are reusability of code
and accessibility of variables and methods of the super class by subclasses.
2 What is the use of super keyword?.
This is used to initialize constructor of base class from the derived class and also access the
variables of base class like super.i = 10.
3 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 inheriting.
4 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
accessible to friends and member functions in a derived class only through a pointer to,
reference to, or object of the derived class.
5 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 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.
6 Define super class and subclass?
Super class is a class from which another class inherits. Subclass is a class that inherits
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 5 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
from one or more classes.
7 What are the four types of access modifiers?
There are 4 types of java access modifiers:
1. private
2. default
3. protected
4. public
8 What is role of access modifier in the member of a 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 protected member is accessible within all classes in the same package and within
subclasses in other packages.
9 What is protected method?
A protected method can be called by any subclass within its class, but not by unreleated
classes. Declaring a method protected defines its access level. The other options for
declaring visibility are private and public. If undeclared, the default access level is
package.
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.
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?
In class-based object-oriented programming, a constructor (abbreviation: ctor) is a special
type of subroutine called to create an object. It prepares the new object for use, often
accepting 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 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
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. 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?
Interface is an outside view of a class or object which emphasizes its abstraction while
hiding its structure and secrets of its behavior.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 6 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
16 What is a base class?
Base class is the most generalized class in a class structure. Most applications have such
root classes. In Java, Object is the base class for all classes.
17 What is meant by Binding, Static binding, 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 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
dynamically manipulate at run time. This is supported using Reflection API with built-in
classes like Class, Method, Fields, Constructors etc. Example: Using Java Reflection API we
can get the class name, by using the getName method.
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 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?
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?
a) All the methods declared inside an interface are abstract whereas abstract class must
have at least one abstract method and others may be concrete or abstract.
b) In abstract class, key word abstract must be used for the methods whereas interface we
need not use that keyword for the methods.
c) Abstract class must have subclasses whereas interface can’t have subclasses.
22 What is an interface and state its use?(Nov/Dec 2019)
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 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.
Class and Interface both are used to create new reference types. A class is a collection of
fields and methods that operate on fields. An interface has fully abstract methods i.e.
methods with nobody. An interface is syntactically similar to the class but there is a major
difference between class and interface that is a class can be instantiated, but an 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.
25 What modifiers may be used with top-level class?
Public, abstract and final can be used for top-level class.
26 What is a cloneable interface and how many methods does it contain?
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 7 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
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
notify All
wait (three versions)
28 Define Package.
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 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.
29 What is object cloning? (Nov./Dec.2018)(Nov/Dec 2019)
It is the process of duplicating an object so that two identical objects will exist in the
memory at the same time.
UNIT II / Part - B
1 Define Inheritance. With diagrammatic illustration and java programs illustrate the
different types of inheritance with an example (Nov./Dec.2018)(Nov/Dec 2019)
2 Explain interfaces with example.
3 Differentiate method overloading and method overriding. Explain both with an example
program.
4 Differentiate method overloading and method overriding. Explain both with an example
program.
5 Explain about the object and abstract classes with the syntax.(Nov/Dec 2019)
6 Discuss in detail about inner class. With its advantages.
7 What is meant by object cloning? Explain it with an example.
8 Explain how inner classes and anonymous classes works in java program.
9 What is a Package? What are the benefits of using packages? Write down the steps in
creating a package and using it in a java program with an example.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 9 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
10 Explain arrays in java with suitable example.
11 How Strings are handled in java? Explain with code, the creation of Substring,
Concatenation and testing for equality.
12 Write a Java program to create a student examination database system that prints the mark
sheet of students.Input student name,marks in 6 subjects.This mark should be between 0
and 100. (Nov./Dec.2018)
If the average of marks is>= 80 then prints Grade ‘A’
If the average of marks is< 80 and >=60 then prints Grade ‘B’
If the average of marks is< 60 and >=40 then prints Grade ‘C’
Else prints Grade ‘D’
UNIT III EXCEPTION HANDLING AND I/O
Exceptions - exception hierarchy - throwing and catching exceptions – built-in exceptions,
creating own exceptions, Stack Trace Elements. Input / Output Basics – Streams – Byte streams
and Character streams – Reading and Writing Console – Reading and Writing Files
UNIT-III/ PART-A
1 What are the types of errors?
Compile time errors
Run time errors
2 Define Java Exception.
A Java exception is an object that describes an exceptional (that is, error) condition that 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
finally.
4 Name any four java built in exceptions.
Exception Meaning
ArithmeticException Arithmetic error, such as divide-by-zero.
ArrayIndexOutOfBoundsException Arithmetic Exception Array index is out-of-bounds.
ArrayStoreException Assignment to an array element of an incompatible
type.
ClassCastException Invalid cast
5 What is chained exception?
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 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 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
1. public String getMessage()
2. public String getLocalizedMessage()
3. public synchronized Throwable getCause()
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 10 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
4. public String toString()
5. public void printStackTrace()
8 Compare throw and throws.
Throw is used to throw an exception & throws is used to declare an exception.
Throw is used in method implementation & throws is used in method signature.
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 progam 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
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?
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
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
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’s thrown
by JVM when it ran out of heap memory.
13 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 child
objects – Error and Exception. Exceptions are further divided into checked exceptions and
runtime exception.
14 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.
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. Out of the three, only finally is
related to java exception handling.
15 What happens when exception is thrown by main method?
When exception is thrown by main() method, Java Runtime terminates the program and
print the exception message and stack trace in system console.
16 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 will
have no information about the exception and it will be a nightmare to debug it.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 11 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
17 What are input and output streams?
An I/O Stream represents an input source or an output destination. A stream can
represent many different kinds of sources and destinations, including disk files, devices,
other programs, and memory arrays.
18 What are directories in Java?
A directory is a File which can contain a list of other files and directories. You
use File object to create directories, to list down files available in a directory.
19 What is a byte stream in java?
Programs use byte streams to perform input and output of 8-bit bytes. All byte stream
classes are descended from InputStream and OutputStream.
There are many byte stream classes. The file I/O byte streams, are
FileInputStream and FileOutputStream.
20 What are directories in Java?
A directory is a File which can contain a list of other files and directories. You
use File object to create directories, to list down files available in a directory.
21 Define stream.
A stream can be defined as a sequence of data. There are two kinds of Streams
InPutStream − The InputStream is used to read data from a source.
OutPutStream − The OutputStream is used for writing data to a destination.
22 What is character stream?
Character streams are used to perform input and output for 16-bit unicode. Though there
are many classes related to character streams but the most frequently used classes
are, FileReader and FileWriter.
23 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. 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.
24 State the use of java.io.Console.
The java.io.Console class which provides convenient methods for reading input and
writing output to the standard input (keyboard) and output streams (display) in
command-line.
25 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
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.
26 State the classes used to read file in java.
The classes are:
FileReader for text files in your system's default encoding
FileInputStream for binary files and text files that contain 'weird' characters.
27 Define Runtime Exception (Nov./Dec.2018)
Runtime Exception is the superclass of those exceptions that can be thrown during the
normal operation of the Java Virtual Machine
28 What is the use of assert keyword? (Nov./Dec.2018)(Nov/Dec 2019)
The assert keyword is used in assert statement which is a feature of the Java programming
language since Java 1.4. Assertion enables developers to test assumptions in their
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 12 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
programs as a way to defect and fix bugs
Unit –III/Part B
1 Explain in detail the important methods of Java Exception Class?
2 Explain the different scenarios causing “Exception in thread main”?
3 How will you create your Own Exception Subclasses?
4 Explain in detail Chained exception with an example program.
5 Explain the different types of Exceptions and the exception hierarchy in java with
appropriate examples. (Nov./Dec.2018)Nov/Dec 2019)
6 Write programs to illustrate arithmetic exception, ArrayIndexOutOfBounds Exception and
NumberFormat Exception.
7 Write a calculator program using exceptions and functions.
8 Create two exception classes that can be used by the stack classes developed by TRY
9 Write a program to receive the name of a file within a text field and then displays its
contents within a text area.(Nov/Dec 2019)
10 Write a Java program that prints the maximum of the sequence of non-negative integer
values that are stored on the file data.txt.
11 Write a program reads every single character from the file MyFile.txt and prints all the
characters to the output console also write an example program which uses
a BufferedReader that wraps a FileReader to append text to an existing file.
12 What are input and output streams? Explain them with illustrations. (Nov./Dec.2018)
UNIT IV MULTITHREADING AND GENERIC PROGRAMMING
Difference between multi-threading and multi-tasking, thread life cycle, creating thread,
synchronizing thread, inter-thread communication, demon thread, thread group, generic
programming-generic classes-generic method-Bounded Types-Restrictions and Limitations
UNIT-IV / PART-A
1 How Threads are created in Java?
Threads are created in two ways. They are by extending the Thread class and by
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.
A thread cannot 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./Dec.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 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
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.
5 Difference between multi-threading and multi-tasking?
Multi-threading Multi-tasking
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 13 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
In any single process, multiple threads is It refers to having multiple (programs,
allowed and again, can run simultaneously. processes, tasks, threads) running at the
same time.
It is sharing of computing resources among It is sharing of computing resources(CPU,
threads of a single process. memory, devices, etc.) among processes
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 14 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
13 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
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.
14 Write short note on isAlive() and join()?
isAlive() and join() methods are used to determine whether a thread has finished or
not.
First, you can call isAlive() on the thread. This method is defined by Thread, and its
general form is:
final Boolean isAlive()
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
15 What do you mean by generic programming? (Nov./Dec.2018)
Generic programming is a style of computer programming in which algorithms are
written in terms of to-be-specified-later types that are then instantiated when needed for
specific types provided as parameters
16 Define Deadlock and When it will occur?
Deadlock describes a situation where two or more threads are blocked forever, waiting for
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 15 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
each other. Deadlock occurs when multiple threads need the same locks but obtain them in
different order. A Java multithreaded program may suffer from the deadlock condition
because the synchronized keyword causes the executing thread to block while waiting for
the lock, or monitor, associated with the specified object.
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 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?
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
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:
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){
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 State the two challenges of generic programming in virtual machines.
Generics are checked at compile-time for type-correctness. The generic type
information is then removed in a process called type erasure.
Type parameters cannot be determined at run-time
22 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
local variable; sometimes as a return type (though it is better programming practice to be
more specific).
23 What is erasure in Java?
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 16 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
Generics were introduced to the Java language to provide tighter type checks at compile
time and to support generic programming. To implement generics, the Javacompiler
applies type erasure to: Replace all type parameters in generic types with their bounds or
Object if the type parameters are unbounded.
24 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
might only want to accept instances of Number or its subclasses. This is what bounded
type parameters are for.
25 What is daemon thread?
A daemon thread is a thread that does not prevent the JVM from exiting when the
program finishes but the thread is still running. An example for a daemon thread is the
garbage collection.
26 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
Cannot Use Casts or instance of With Parameterized Types
Cannot Create Arrays of Parameterized Types
Cannot Create, Catch, or Throw Objects of Parameterized Types
Unit –IV/Part B
1 What are the two ways of thread creation? Explain with suitable examples.
2 With illustrations explain multithreading, interrupting threads, thread states and thread
properties.
3 Describe the life cycle of thread and various thread methods. Or Explain in detail the
different states of a thread? (Nov./Dec.2018)
4 Explain the thread properties in detail.
5 Explain inter thread communication and suspending, resuming and stopping threads.
6 Write a java program that synchronizes three different threads of the same program and
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 called
consumer, producer and stock.
8 Explain in detail about generic classes and methods in java with suitable example.
9 Describe briefly about generics with wildcards.
10 What are the restrictions are considered to use java generics effectively? Explain in detail.
11 Demonstrate Inter thread Communication and suspending, resuming and stopping
threads. (Nov./Dec.2018)
12 Create a Bank database application program to illustrate the use of multithread
(Nov./Dec.2018)
UNIT V EVENT DRIVEN PROGRAMMING
Graphics programming-Frame-Components-Working with 2D Shapes-Using color,fonts,and images-
Basics of event handling-event handler-adapter classes-actions-mouse events-AWT event hierarchy-
introduction to Swing-layout management-Swing components-Text fields, Text areas-Buttons-Check
Boxes-Radio Buttons-Lists-choices-scrollbars-Windows-Menus-dialog Boxes.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 17 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
Unit –V/Part A
1 What is an Applet?
Applet is a Java application, which can be executed in JVM, enabled web browsers.
2 What is AWT?
A collection of graphical user interface (GUI) components that were implemented using
native-platform versions 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.
3 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 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.
4 Write some methods, which are used to add UI components in Applet?
add - Adds the specified Component.
remove - Removes the specified Component.
setLayout - Sets the layout manager.
5 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.
stop - To stop the applet's execution, such as when the user leaves the applet's page
or quits the browser.
destroy - To perform a final cleanup in preparation for unloading.
6 Code a graphics method in java to draw the string “Hello World” from the
Coordinates(100,200).
g.drawString("Hello, World", 100, 150);
7 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)
Labels (java.awt.Label)
Lists (java.awt.List)
Pop-up lists of choices (java.awt.Choice)
Sliders and scrollbars (java.awt.Scrollbar)
Drawing areas (java.awt.Canvas)
Menus (java.awt.Menu, java.awt.MenuItem,
java.awt.CheckboxMenuItem)
Containers (java.awt.Panel, java.awt.Window and its subclasses)
8 How can you prevent the overwriting of a displayed text in a TextField of a java
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 18 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
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 setPromptText method:
txtFld.setPromptText("Enter Name..");
To find out the value of the prompt text of a TextField object use the getPromptText
method:
String promptext = txtFld.getPromptText();
9 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.
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.
10 Name the listener methods that must be implemented for the key listener interface.
(NOV 2013)
void keyTyped(KeyEvent e)
void keyPressed(KeyEvent e)
void keyReleased(KeyEvent e)
11 How Events are handled in java ?
A source generates an Event and send it to one or more listeners registered with the
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.
12 Define swing in java.
Java Swing is a part of Java Foundation Classes (JFC) that is used to create window-based
applications. It is built on the top of AWT (Abstract Windowing Toolkit) API and entirely.
13 Components of Event Handling
Event handling has three main components,
Events : An event is a change in state of an object.
Events Source : Event source is an object that generates an event.
Listeners : A listener is an object that listens to the event. A listener gets notified when an
event occurs.
14 Why are swing components called lightweight component?
Swing is considered lightweight because it is fully implemented in Java, without calling
the native operating system for drawing the graphical user interface components.
15 What is a layout manager and what are different types of layout managers available in
java AWT?
A layout manager is an object that is used to organize components in a container. The
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 19 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout
and GridBagLayout.
16 Metion some class for java swing
The javax.swing package provides classes for java swing API such as JButton, JTextField,
JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser.
17 What is the difference between scrollbar and scrollpane?
A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and
handles its own events and perform its own scrolling.
18 What is the use of JButton and mention the constructor of JButton class.
JButton class provides functionality of a button. JButton class has three
constuctors,Button(Icon ic),JButton(String str),JButton(String str, Icon ic)
19 What is the use of JTextField and mention the constructor of JTextField class.
JTextField is used for taking input of single line of text. It is most widely used text
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.
20 What is meant by window adapter classes? (Nov./Dec. 18)
The class WindowAdapter is an abstract (adapter) class for receiving window events. All
methods of this class are empty. This class is convenience class for creating listener objects.
21 Enumerate the features of AWT in Java. (Nov./Dec. 18)
A collection of graphical user interface (GUI) components that were implemented using
native-platform versions 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.
UNIT-V / PART-B
1 What is event delegation model and what are the event classes and event interfaces?
2 Explain various components in AWT?
3 State and explain the basic of AWT Event handling in detail (Nov./Dec.2018)
4 Explain the layout managers in Java also describe the concept of menu creation.Nov/Dec
2019)
5 What is an adapter class? Describe about various adapter classes in detail?
6 Explain about JComboBoxclass, JCheckBoxclass
7 Develop a java program that have 11 text fields one submit button. When you press the
button first 10 text field’s average has to be displayed in the 11th text field.
8 Develop a java code that keeps the count of right clicks of mouse.
9 Explain about JButtonclass, JTextAreaclass, JFrameclass
10 Develop java program that changes the color of a filled circle when you make a right click.
11 How will you display an image on the frame in a window using java?
12 Describe in detail about the different layout in Java GUI.Which layout is the default one?
(Nov./Dec.2018)
13 Code a java program to implement the following:Create four checkboxes.The initial state
of the first box should be in the checked state.The status of each check box should be
displayed.when we change the state of a check box,status should be display is updated.
(Nov./Dec.2018)
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 20 of 21
CS8392- Object Oriented Programing Department of EEE 2020-2021
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 21 of 21