0% found this document useful (0 votes)
30 views16 pages

OOPJ Short QuestionBank 2016

The document is a question bank for the Object Oriented Programming using Java course at L.J. Institute of Engineering & Technology, covering various topics such as Java basics, data types, arrays, strings, classes, inheritance, and interfaces. It includes questions with answers related to Java features, JVM, garbage collection, method overloading, and access modifiers. The content is structured into units and topics, providing a comprehensive overview of key concepts in Java programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views16 pages

OOPJ Short QuestionBank 2016

The document is a question bank for the Object Oriented Programming using Java course at L.J. Institute of Engineering & Technology, covering various topics such as Java basics, data types, arrays, strings, classes, inheritance, and interfaces. It includes questions with answers related to Java features, JVM, garbage collection, method overloading, and access modifiers. The content is structured into units and topics, providing a comprehensive overview of key concepts in Java programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

L.J.

Institute of Engineering & Technology Semester: V (2016)

Subject Name: Object Oriented Programming using JAVA


Subject Code: 2150704
Faculties: MS. HEMALI MOJIDRA(SHAH)

Sr No QUESTIONS
UNIT-1 BASICS OF JAVA:

TOPIC:1 (About Basic Java)


Features of Java, Byte Code and Java Virtual Machine, JDK
1 JVM is platform dependent. Justify. (May-13) [LJIET] 1/2/3
OR Justify statement. (i)JVM is platform dependent (Dec-15) [LJIET]
Ans: The JVM executes Java code, but is written in platform specific languages such as
C/C++/ASM etc. The JVM is not written in Java and hence cannot be platform
independent. Require to build different JVM for different Platform(Operating System).
JVM depends on the operating system. JVMs are not platform independent. In fact they
are platform specific run time environment provided by the vendor. Each platform
(Windows, UNIX, Mac etc) has its own JVM to run Java applications.
2 (ii)There is no destructor in Java. (May-13,Dec-15) [LJIET] 1/2/3
Ans: True- Java has its own garbage collection implementation so it does not require any
destructor like C++ . Garbage collector identifies the objects which no longer needed in
program and free the memory occupied by object. finalize() method of Object class is
invoked when garbage collector is invoked. Developer need to override finalize() method
to release the resources occupied by the class object.
3 (i) Java program is to be compiled first and then to be interpreted for execution. True or 1/2/3
false? Justify your answer. (Dec-15) [LJIET]
Ans:TRUE- Java source file .java compiled using javac command and generates the
bytecode (.class) file. This .class file contains the bytecode which is interpreted by the
JVM(Java Virtual Machine) than execute it and generate the output.
4 What gives Java its 'write once and run anywhere' nature? 1/2/3
Ans: bytecode-Highly compiled code-Java is compiled to be a byte code(.class file) which
is the intermediate language between source code and machine code. This byte code is not
platform specific and hence can be fed to any platform.

5 What is JIT compiler? 1/2/3


Ans: Just-In-Time(JIT) compiler: It is used to improve the performanceof java program .
JIT compiles parts of the byte code that have similar functionality at the same time, and
hence reduces the amount of time needed for compilation.Here the term “compiler” refers
to a translator from the instruction set of a Java virtual machine (JVM) to the instruction
set of a specific CPU.
6 What is bytecode? 1/2/3
Bytecode is highly compiled code which is intermediate representation of Java source code
which is produced by the Java compiler by compiling that source code. This byte code is
an machine independent code.It is not an completely a compiled code but it is an
intermediate code somewhere in the middle which is later interpreted and executed by
JVM.Bytecode is a machine code for JVM.But the machine code is platform specific
whereas bytecode is platform independent that is the main difference between them.It is
Object Oriented Programming using JAVA (2150704) 2016 Page 1
L.J. Institute of Engineering & Technology Semester: V (2016)

stored in .class file which is created after compiling the source code.

TOPIC:2(Data types, Operator, Control Statement)

Data types, Operator Control Statements – If , else, nested if, if-else ladders, Switch, while,
do-while, for, for-each, break, continue.
1 Is delete,next,main,exit or null keyword in java? 1
Ans: NO
2 List primitive Java types? 1
Ans: The eight primitive types are byte, char, short, int, long, float, double, and boolean.
3 Which of these can not be used for a variable name in Java? 1
a) identifier b) keyword c) identifier & keyword d) None of the mentioned
Answer: b) keyword
4 What is the output of this program? 1
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
a) 25 b) 24 c) 32 d) 33
Ans:c)32

UNIT-2 ARRAY AND STRING:

TOPIC:1 (Array)
Single and Multidimensional Array
1 Which will legally declare, construct, and initialize an array? 1
A. int [] myList = {"1", "2", "3"}; B. int [] myList = (5, 8, 2);
C. int myList [] [] = {4,9,7,0}; D. int myList [] = {4, 3, 7};
Answer: D int myList [] = {4, 3, 7};
2 Which of these operators is used to allocate memory to array variable in Java? 1
a) malloc b) alloc c) new d) new malloc
Answer: c) new
3 Which of these is an incorrect array declaration? 1
a) int arr[] = new int[5] b) int [] arr = new int[5]
c) int arr[] arr = new int[5] d) int arr[] = int [5] new
Answer:d) int arr[] = int [5] new
4 Which of these is necessary to specify at time of array initialization? 1
a) Row b) Column c) Both Row and Column d) None of the mentioned
Answer: a) Row
5 What are ragged arrays in java and how are they implemented? 1/2/3
Ans: Ragged arrays : an array with rows of nonuniform length is known as a ragged array.
Syntaxt:
int[][] raggedArray = new int[n][];
for (int i=0; i<raggedArray.length; i++) {
raggedArray[i] = new int[i+1];
}

Object Oriented Programming using JAVA (2150704) 2016 Page 2


L.J. Institute of Engineering & Technology Semester: V (2016)

TOPIC:2 (String And Wrapper Classes)


String class, StringBuffer class,Operations on string,, Command line argument, Use of
Wrapper Class.
1 What is the meaning of immutable in terms of String? 1
Ans:The simple meaning of immutable is unmodifiable or unchangeable. Once string
object has been created, its value can't be changed.
2 What is the basic difference between string and stringbuffer object? 1
Ans:String is an immutable object. StringBuffer is a mutable object.
3 What are wrapper classes? 1
Ans:Wrapper classes are classes that allow primitive types to be accessed as objects.
Example: Integer, Character, Double, Boolean etc.
4 In which string class function returns the number of characters in a string? 1
A) length() B) replace()
C) charAt() D) equalIgnoreCase()
ANSWER: A) length()
5 The wrapper classes are part of the which package, that is imported by default into all Java 1
programs?
A) java.lang B) java.net C) java.io D) java.util
Ans:A) java.lang
6 Void it is not a wrapper class? 1
A) True B) False
ANSWER: A) True
7 The following two statements illustrate the difference between a 1
int x = 25;
Integer y = new Integer(33);
A) Primitive data types B) primitive data type and an object of a wrapper class
C) Wrapper class D) None of the above
ANSWER: B) primitive data type and an object of a wrapper class

UNIT-3 Classes, Objects and Methods:

TOPIC:1 (Class,Object, Constructor And Method)


Class, Object, Object reference, Constructor, Constructor Overloading, Method
Overloading, Recursion, Passing and Returning object form Method
1 What do you mean by Object? 1
Ans: Object is a runtime entity and it’s state is stored in fields and behavior is shown via
methods. Methods operate on an object's internal state and serve as the primary mechanism
for object-to-object communication.
2 Define class? 1
Ans: A class is a blue print from which individual objects are created. A class can contain
fields and methods to describe the behavior of an object.
3 What do you mean by Constructor? 1
Ans: Constructor gets invoked when a new object is created. Every class has a constructor.
If we do not explicitly write a constructor for a class the java compiler builds a default
constructor for that class.
Object Oriented Programming using JAVA (2150704) 2016 Page 3
L.J. Institute of Engineering & Technology Semester: V (2016)

4 What is method overloading? 1


Ans: If a class have multiple methods by same name but different parameters, it is known
as Method Overloading. It increases the readability of the program.
5 Can we overload main() method? 1
Ans: Yes, You can have many main() methods in a class by overloading the main method.

TOPIC:2 (new, this, static, finalize, Access Control and Modifiers)


new operator, this and static keyword, finalize() method, Access control, modifiers
1 Why main method is static? 1
Ans: because object is not required to call static method if It were non-static method,jvm
creats object first then call main() method that will lead to the problem of extra memory
allocation.
2 What is static block? 1
Ans: Is used to initialize the static data member.
It is excuted before main method at the time of classloading.
3 What if the static modifier is removed from the signature of the main method? 1
Ans:Program compiles. But at runtime throws an error "NoSuchMethodError".
4 What is Garbage Collection? 1
Ans:Garbage collection is a process of reclaiming the runtime unused objects.It is
performed for memory management.
5 What is gc()? 1
Ans: gc() is a daemon thread.gc() method is defined in System class that is used to send
request to JVM to perform garbage collection.
6 What is the purpose of finalize() method? 1/2
Ans: finalize() method is invoked just before the object is garbage collected.It is used to
perform cleanup processing.
7 What is difference between final, finally and finalize? 1/2/3
final: final is a keyword, final can be variable, method
or class.You, can't change the value of final variable,
can't override final method, can't inherit final class.

finally: finally block is used in exception handling.


finally block is always executed.

finalize():finalize() method is used in garbage


collection.finalize() method is invoked just before the
object is garbage collected.The finalize() method can be
used to perform any cleanup processing.

8 What is protected access modifier? 1


Ans: Variables, methods and constructors which are declared protected in a superclass can
be accessed only by the subclasses in other package or any class within the package of the
protected members' class.
9 What do you mean by Access Modifier? 1
Ans: Java provides access modifiers to set access levels for classes, variables, methods and
constructors. A member has package or default accessibility when no accessibility modifier
Object Oriented Programming using JAVA (2150704) 2016 Page 4
L.J. Institute of Engineering & Technology Semester: V (2016)

is specified.

TOPIC:3 (Nested, Inner, Abstract Class)


Nested class, Inner class, Anonymous inner class, Abstract class.

1 What is abstract class? 1


Ans: A class that is declared as abstract is known as abstract class. It needs to be extended
and its method implemented. It cannot be instantiated.
2 Can there be any abstract method without abstract class? 1
Ans: No, if there is any abstract method in a class, that class must be abstract.
3 Is it possible to instantiate the abstract class? 1
Ans: No, abstract class can never be instantiated.
4 What is nested class? 1
Ans: A class which is declared inside another class is known as nested class. There are 4
types of nested class member inner class, local inner class, annonymous inner class and
static nested class.

UNIT-4 Inheritance and Interfaces:

TOPIC:1 (Basics Of Inheritance)


Use of Inheritance, Inheriting Data members and Methods, constructor in inheritance,
Multilevel Inheritance – method overriding
1 Difference between method Overloading and Overriding. 1/2/3
Method Overloading Method Overriding
Method overriding provides the
1) Method overloading increases the specific implementation of the
readability of the program. method that is already provided
by its super class.
Method overriding occurs in
2) method overlaoding is occurs within the
two classes that have IS-A
class.
relationship.
In this case, parameter must be
3) In this case, parameter must be different.
same.
2 Explain - The Cosmic Superclass.
Ans: Object class is the “Cosmic Super class”.
The Object class is the ultimate ancestor—every class in Java extends Object. However,
you never have to write “class Employee extends Object”.
In Java, every class that is defined without an explicit extends clause automatically extends
the class Object. That is, the class Object is the direct or indirect superclass of every class
in Java

3 Which class is the superclass for every class. 1


Ans: Object class.

Object Oriented Programming using JAVA (2150704) 2016 Page 5


L.J. Institute of Engineering & Technology Semester: V (2016)

4 Can we override static method? 1


Ans: No, you can't override the static method because they are the part of class not object.

TOPIC:2 (super And final)


Handle multilevel constructors – super keyword, Stop Inheritance – Final keywords,
1 What is final variable? 1
Ans: If you make any variable as final, you cannot change the value of final variable(It
will be constant)
2 What is final method? 1
Ans: Final methods can't be overridden
3 What is final class? 1
Ans: Final class can't be inherited.
4 Can you declare the main method as final? 1
Ans: Yes, such as, public static final void main(String[] args){}.
5 Can you use abstract and final both with a method? 1
Ans: No, because abstract method needs to be overridden whereas you can't override final
method.
6 When super keyword is used? 1/2
Ans:- To invoke super classs constructor.
- To access super class data member
-To invoke super class member function
7 What is runtime polymorphism or dynamic method dispatch? 1
Ans: Runtime polymorphism or dynamic method dispatch is a process in which a call to an
overridden method is resolved at runtime rather than at compile-time. In this process, an
overridden method is called through the reference variable of a superclass.
8 What is Dynamic Binding(late binding)? 1
Ans: Binding refers to the linking of a procedure call to the code to be executed in
response to the call. Dynamic binding means that the code associated with a given
procedure call is not known until the time of the call at run-time.

TOPIC:3 (Interface)
Creation and Implementation of an interface, Interface reference, instanceof operator,
Interface inheritance, Dynamic method dispatch ,Understanding of Java Object Class,
Comparison between Abstract Class and interface, Understanding of System.out.println –
statement.
1 What is interface? 1
Ans: Interface is a blueprint of a class that have static constants and abstract methods. It
can be used to achieve fully abstraction and multiple inheritance.
2 Can an Interface extend another Interface? 1
Yes an Interface can inherit another Interface, for that matter an Interface cannot extends
more than one Interface.
3 Can you declare an interface method static? 1
Ans: No, because methods of an interface is abstract by default, and static and abstract
keywords can't be used together.
4 Can an Interface be final? 1
Ans: No, because its implementation is provided by another class.
5 What is difference between abstract class and interface? 1
Object Oriented Programming using JAVA (2150704) 2016 Page 6
L.J. Institute of Engineering & Technology Semester: V (2016)

Abstract class Interface


1)An abstract class can have
Interface have only
method body (non-abstract
abstract methods.
methods).
An interface cannot
2)An abstract class can have
have instance
instance variables.
variables.
3)An abstract class can have Interface cannot have
constructor. constructor.
4)An abstract class can have Interface cannot have
static methods. static methods.
5)You can extends one abstract You can implement
class. multiple interfaces.
6 Give some features of Interface? 1
Ans: It includes − Interface cannot be instantiated, An interface does not contain any
constructors., All of the methods in an interface are abstract.

UNIT-5 PACKAGES
Use of Package, CLASSPATH, Import statement, Static import, Access control
1 What is package? 1
Ans: A package is a group of similar type of classes interfaces and sub-packages. It
provides access protection and removes naming collision.
2 Do I need to import java.lang package any time? Why ? 1
Ans: No. It is by default loaded internally by the JVM.
3 What is static import ? 1
Ans: By static import, we can access the static members of a class directly, there is no to
qualify it with the class name.
4 What is difference between Path and Classpath? 1
Ans: Path and Classpath are operating system level environment variales. Path is defines
where the system can find the executables(.exe) files and classpath is used to specify the
location of .class files.
5 Which access specifiers can be used for a class so that it’s members can be accessed by a 1
different class in the different package?
A) Private B) Public C) Protected D) None of the above
ANSWER: B) Public
6 Which provides accessibility to classes and interface? 1
A) import B) Static import C) Both A & B D) None of the above
ANSWER: A) import

UNIT-6 EXCEPTION HANDLING:

TOPIC:1 (Basic of Exception)


Exception and Error, Use of try, catch, throw, throws and finally
1 Is it necessary that each try block must be followed by a catch block? 1

Object Oriented Programming using JAVA (2150704) 2016 Page 7


L.J. Institute of Engineering & Technology Semester: V (2016)

Ans: It is not necessary that each try block must be followed by a catch block. It should be
followed by either a catch block OR a finally block. And whatever exceptions are likely to
be thrown should be declared in the throws clause of the method.
2 What is Exception Handling? 1
Ans: Exception Handling is a mechanism to handle runtime errors.It is mainly used to
handle checked exceptions.
3 What is difference between Checked Exception and Unchecked Exception? 1
1)Checked Exception:
The classes that extend Throwable class except RuntimeException and Error are known as
checked exceptions e.g.IOException,SQLException etc. Checked exceptions are checked
at compile-time.
2)Unchecked Exception:
The classes that extend RuntimeException are known as unchecked exceptions e.g.
ArithmeticException,NullPointerException etc. Unchecked exceptions are not checked at
compile-time.
4 Can finally block be used without catch? 1
Ans: Yes, by try block. finally must be followed by either try or catch.
5 What is finally block? 1
Ans: finally block is a block that is always executed.
6 When throws keyword is used? 1
Ans: If a method does not handle a checked exception, the method must declare it using
the throwskeyword. The throws keyword appears at the end of a method's signature.
7 When throw keyword is used? 1
Ans: An exception can be thrown, either a newly instantiated one or an exception that you
just caught, by using throw keyword.
8 What is the difference between error and an exception? 1
Ans:An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory
error. Exceptions are conditions that occur because of bad input etc. e.g.
FileNotFoundException will be thrown if the specified file does not exist.
9 Exception Handling is a mechanism to handle runtime errors? 1
A) True B) False
ANSWER: A) True
10 These five keywords are used in try, catch, finally, throw, and throws? 1
A) Exception Handling B) String Handling C) Event Handling
D) None of the above
ANSWER: A) Exception Handling
11 These exceptions are seen in 1
NullPointerException, ArrayIndexOutOfBoundsException,
ArithmeticException, NumberFormatException ?

A) Checked exception B) Unchecked exception


C) Both A & B D) None of the above
ANSWER: B) Unchecked exception

12 Which block contains a block of program statements within which an exception might 1
occur?

Object Oriented Programming using JAVA (2150704) 2016 Page 8


L.J. Institute of Engineering & Technology Semester: V (2016)

A) Catch B) try C) throw D) final


ANSWER: B) try
13 Which keyword is used for the block to handle the exceptions generated by try block? 1
A) Catch B) Final C) throw D) try
ANSWER: A) Catch
14 Unchecked exceptions are checked at compile-time rather they are checked at runtime? 1
A) True B) False
ANSWER: B) False
15 If you are inserting any value in the wrong index as shown below, it would result in 1
1. int a[]=new int[5];
2. a[10]=50;
A) NullPointerException B) ArrayIndexOutOfBoundsException
C) ArithmeticException D) NumberFormatException
ANSWER: B) ArrayIndexOutOfBoundsException
TOPIC:2 (Built in and Custom Exception)
Built in Exception, Custom exception, Throwable Class.
1 What is the base class for Error and Exception? 1
Ans: Throwable.
2 What is difference between throw and throws? 1/2/3
throw keyword throws keyword
1)throw is used
to explicitly throws is used to declare an
throw an exception.
exception.
2)checked
exceptions can
checked exception can be propagated
not be
with throws.
propagated with
throw only.
3)throw is
followed by an throws is followed by class.
instance.
4)throw is used
throws is used with the method
within the
signature.
method.
5)You cannot You can declare multiple exception
throw multiple e.g. public void method()throws
exception IOException,SQLException.

UNIT-7 MULTITHREADED PROGRAMMING:

TOPIC:1 (Basic of Thread)


Use of Multithread programming, Thread class and Runnable interface

1 What is multithreading? 1
Object Oriented Programming using JAVA (2150704) 2016 Page 9
L.J. Institute of Engineering & Technology Semester: V (2016)

Ans:Multithreading is a process of executing multiple threads simultaneously. Its main


advantage is:
Threads share the same address space.
Thread is lightweight.
Cost of communication between process is low.
2 What is thread? 1
Ans: A thread is a lightweight subprocess.It is a separate path of execution.It is called
separate path of execution because each thread runs in a separate stack frame.
3 What does join() method? 1
Ans: The join() method waits for a thread to die. In other words, it causes the currently
running threads to stop executing until the thread it joins with completes its task.
4 What is difference between wait() and sleep() method? 1
wait() sleep()
1) The wait() method is The sleep() method is
defined in Object class. defined in Thread class.
2) wait() method releases The sleep() method doesn't
the lock. releases the lock.
5 Which method is used in thread class to starts the execution of the thread and JVM calls 1
the run() method on the thread?
A) public void start() B) public void run()
C) public void stop() D) public coid suspend()
ANSWER: A) public void start()
6 Can we start a thread twice? 1
A) Yes B) No
ANSWER: B) No
7 Which method waits for a thread to die? 1
A) stop() B) start() C) terminate() D) join()
ANSWER: D) join()
8 Which method returns a reference to the currently executing thread object? 1
A) currentThread() B) runningThread()
C) runnableThread() D) None of the above
ANSWER: A) currentThread()
TOPIC:2 (Thread Communication)
Thread priority, Thread synchronization, Thread communication, Deadlock
1 What is synchronization? 1
Ans: Synchronization is the capabilility of control the access of multiple threads to any
shared resource.It is used:
1. To prevent thread interference.
2. To prevent consistency problem.

2 What is the purpose of Synchronized block? 1


Ans: Synchronized block is used to lock an object for any shared resource.
Scope of synchronized block is smaller than the method.
3 What is the difference between notify() and notifyAll()? 1
Ans: The notify() is used to unblock one waiting thread whereas notifyAll() method is
Object Oriented Programming using JAVA (2150704) 2016 Page 10
L.J. Institute of Engineering & Technology Semester: V (2016)

used to unblock all the threads in waiting state.


4 What is deadlock? 1
Ans: Deadlock is a situation when two threads are waiting on each other to release a
resource. Each thread waiting for a resource which is held by the other waiting thread.

UNIT-8 IO PROGRAMMING:

TOPIC:1 (Basic of IO)


Introduction to Stream, Byte Stream, Character stream, Readers and Writers
1 Which stream does Java application uses to read data from a source, it may be a file, an 1
array, peripheral device or socket?
A) InputStream B) OutputStream
C) Input/OutputStream D) None of the above
ANSWER: A) InputStream
2 These commonly used methods of - public abstract int read()throws IOException 1
A) OutputStream class
B) InputStream class
C) Input/OutputStream class
D) None of the above
ANSWER: B) InputStream class
TOPIC:2 (File Handling)
File Class, File InputStream, File Output Stream, InputStreamReader,
OutputStreamWriter, FileReader, FileWriter, Buffered Reader
1 Which is used for writing data to a file in file handling? 1
A) FileInputStream B) FileOutputStream
C) Both A & B D) None of the above
ANSWER: B) FileOutputStream

UNIT-9 COLLECTION CLASSES :


,
TOPIC:1 (About Collection classes, java.util Package)
List, AbstractList, ArrayList, LinkedList, Enumeration, Vector, Properties, java.util
Package
1 What is the difference between ArrayList and Vector? 1/2
No. ArrayList Vector
ArrayList is not
1) Vector is synchronized.
synchronized.
ArrayList is not a
2) Vector is a legacy class.
legacy class.
ArrayList
increases its size Vector increases its size by doubling the array
3)
by 50% of the size.
array size.
2 What is the difference between ArrayList and LinkedList? 1/2

Object Oriented Programming using JAVA (2150704) 2016 Page 11


L.J. Institute of Engineering & Technology Semester: V (2016)

No. ArrayList LinkedList

LinkedList uses doubly linked


1) ArrayList uses a dynamic array.
list.

ArrayList is not efficient for manipulation because a LinkedList is efficient for


2)
lot of shifting is required. manipulation.

LinkedList is better to
3) ArrayList is better to store and fetch data.
manipulate data.

3 What is the difference between Iterator and ListIterator? 1/2

Iterator traverses the elements in forward direction only whereas ListIterator traverses the
elements in forward and backward direction.

No. Iterator ListIterator

Iterator traverses the ListIterator traverses the


1) elements in forward elements in backward and
direction only. forward directions both.

Iterator can be used


ListIterator can be used in
2) in List, Set and
List only.
Queue.

4 What is the difference between Iterator and Enumeration? 1/2


No. Iterator Enumeration

Iterator can traverse Enumeration can


1) legacy and non-legacy traverse only legacy
elements. elements.

Enumeration is not fail-


2) Iterator is fail-fast.
fast.

Iterator is slower than Enumeration is faster


3)
Enumeration. than Iterator.

5 What is the difference between Set and Map? 1


Ans: Set contains values only whereas Map contains key and values both.
6 What is the difference between HashSet and HashMap? 1
Ans: HashSet contains only values whereas HashMap contains entry(key,value). HashSet
can be iterated but HashMap need to convert into Set to be iterated.
7 What is the difference between HashSet and TreeSet? 1
Ans: HashSet maintains no order whereas TreeSet maintains ascending order.
8 What is the difference between HashMap and Hashtable? 1
Object Oriented Programming using JAVA (2150704) 2016 Page 12
L.J. Institute of Engineering & Technology Semester: V (2016)

No. HashMap Hashtable

HashMap is not Hashtable is


1)
synchronized. synchronized.

HashMap can contain one Hashtable cannot


2) null key and multiple null contain any null key or
values. null value.

UNIT-10 NETWORKING WITH java.net


InetAddress class,Socket class, DatagramSocket class, DatagramPacket class
TOPIC:1 (Basic Of Networking)
InetAddress class
1 How do I convert a numeric IP address like 192.18.97.39 into a hostname like 1
java.sun.com?
Ans: By InetAddress.getByName("192.18.97.39").getHostName() where 192.18.97.39 is
the IP address.
2 Define Network Programming? 1
Ans: It refers to writing programs that execute across multiple devices (computers), in
which the devices are all connected to each other using a network.
3 What is a Socket? 1
Ans: Sockets provide the communication mechanism between two computers using TCP.
A client program creates a socket on its end of the communication and attempts to connect
that socket to a server.
4 The java.net.InetAddress class represents an? 1
A) Socket B) IP Address
C) Protocol D) MAC Address
ANSWER: B) IP Address
5 In InetAddress class which method it returns the host name of the IP Address? 1
A) public String getHostName()
B) public String getHostAddress()
C) public static InetAddress getLocalHost()
D) None of the above
ANSWER: A) public String getHostName()
TOPIC:2 (TCP Socket Programming)
Socket class
1 Which classes are used for connection-oriented socket programming? 1
A) Socket B) ServerSocket
C) Both A & B D) None of the above
ANSWER: C) Both A & B
2 Which class can be used to create a server socket. This object is used to establish 1
communication with the clients?
A) ServerSocket B) Socket

Object Oriented Programming using JAVA (2150704) 2016 Page 13


L.J. Institute of Engineering & Technology Semester: V (2016)

C) Both A & B D) None of the above


ANSWER: A) ServerSocket
3 Which methods are commonly used in ServerSocket class? 1
A) public OutputStream getOutputStream()
B) public Socket accept()
C) public synchronized void close()
D) None of the above
ANSWER: B) public Socket accept()
4 The client in socket programming must know which informations? 1
A) IPaddress of Server
B) Port number
C) Both A & B
D) None of the above
ANSWER: C) Both A & B
TOPIC:3 (UDP Socket Programming)
DatagramSocket class, DatagramPacket class
1 Which classes are used for connection-less socket programming? 1
A) DatagramSocket B) DatagramPacket
C) Both A & B D) None of the above
ANSWER: C) Both A & B
2 The DatagramSocket and DatagramPacket classes are not used for connection-less socket 1
programming.
A) True B) False
ANSWER: B) False

UNIT-11 BASIC OF UML:


Introduction to Object orientation, Modelling as a Design Technique Modelling Concepts,
abstraction, The three models, Class Model, State model and Interaction model.
1 Define UML?
Ans: Unified Modeling Language, a standard language for designing and documenting a
system in an object-oriented manner. It has nine diagrams which can be used in design
document to express design of software architecture.
2 What is purpose of OO analysis and design ?
 Identifying the objects of a system.
 Identify their relationships.
 Make a design which can be converted to executables using OO languages.
3 What do you mean by object modeling technique?
4 What is the programming style of the object oriented conceptual model? 1
a) Invariant relationships
b) Algorithms
c) Classes and objects
d) Goals, often expressed in a predicate calculus.
Answer: c
5 The fact that the same operation may apply to two or more classes is called what? 1
A. Inheritance B. Polymorphism
C. Encapsulation D. Multiple classification

Object Oriented Programming using JAVA (2150704) 2016 Page 14


L.J. Institute of Engineering & Technology Semester: V (2016)

Answer: Option B- Polymorphism

UNIT-12 CLASS MODELING:


Object and class concepts, link and association, Generalization and Inheritance
1 Define Association: 1
Association is basically a set of links that connects elements of an UML model. It also
describes how many objects are taking part in that relationship.
2 Define Generalization: 1
Generalization can be defined as a relationship which connects a specialized element with
a generalized element. It basically describes inheritance relationship in the world of
objects.

3 Define Dependency: 1
Dependency is the relationship between two things in which a change in one thing may
affect the other thing, but not necessarily the reverse. Graphically, it can be represented as
a dashed directed line, directed to the thing being depended on.
4 Single inheritance, Multiple inheritance, and Aggregation comes under _______ 1
a) Modularity b) Typing c) Hierarchy d) None of the mentioned
Answer: c
5 When two or more classes serve as base class for a derived class, the situation is known as 1
__________.
a) multiple inheritance b)polymorphism
c) encapsulation d)hierarchical inheritance
Answer: (a)

UNIT-13 ADVANCED CLASS MODELING:


Advanced Object and class concepts, Association Ends, N-ary associations, aggregation,
abstract classes, multiple inheritance, Metadata, Constraints, Derived data, Packages.
1 Package: 1

Package is the only one grouping thing available for gathering structural and behavioral
things.

2 Composition is a stronger form of which of the following? 1


A. Aggregation B. Encapsulation
C. Inheritance D. All of the above.
Answer: Option A- Aggregation
3 An abstract class is which of the following? 1
A. A class that has direct instances, but whose descendants may have direct instances.
B. A class that has no direct instances, but whose descendants may have direct
Object Oriented Programming using JAVA (2150704) 2016 Page 15
L.J. Institute of Engineering & Technology Semester: V (2016)

instances.
C. A class that has direct instances, but whose descendants may not have direct
instances.
D. A class that has no direct instances, but whose descendants may not have direct
instances
Answer: Option B

UNIT-14 STATE CLASS MODELING:


Events, states, Transition and conditions, state diagram, state diagram behaviour
1 Define States 1
States represent situations during the life of an object. You can easily illustrate a state in
SmartDraw by using a rectangle with rounded corners.
2 Define Transition 1
A solid arrow represents the path between different states of an object. Label the transition
with the event that triggered it and the action that results from it. A state can have a
transition that points back to itself.
3 Event : An event is something that happens that affects the system 1

UNIT-15 INTERACTION CLASS MODELING:


Use case Models, sequence models, activity models
1 Define use Sequence diagram 1
This diagram is used to explore logic of complex operations, function or procedure. In this
diagram, sequence of the interactions between the objects is represented step by step.
2 Define use Activity diagram 1
Activity diagram gives detail view of the business logic.

Object Oriented Programming using JAVA (2150704) 2016 Page 16

You might also like