[go: up one dir, main page]

0% found this document useful (0 votes)
91 views47 pages

JAVA PAST QUESTIONS

The document contains a series of multiple-choice questions related to Java programming, covering topics such as Java's characteristics, JDBC, servlets, and object-oriented programming principles. Each question provides four options, with some requiring true or false responses. The content is structured as a quiz format, aimed at assessing knowledge in Java programming concepts.
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)
91 views47 pages

JAVA PAST QUESTIONS

The document contains a series of multiple-choice questions related to Java programming, covering topics such as Java's characteristics, JDBC, servlets, and object-oriented programming principles. Each question provides four options, with some requiring true or false responses. The content is structured as a quiz format, aimed at assessing knowledge in Java programming concepts.
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/ 47

1.

Java programs are


A) Faster than others
B) Platform independent
C) Not reusable
D) Not scalable
2. Java has its origin in
A) C programming language
B) PERRL
C) COBOL
D) Oak programming language
3. Which one of the following is true for Java
A) Java is object oriented and interpreted
B) Java is efficient and faster than C
C) Java is the choice of everyone.
D) Java is not robust.
4. The command javac is used to
A) debug a java program
B) compile a java program
C) interpret a java program
D) execute a java program
5. Java servlets are an efficient and powerful solution for creating ………….. for
the web.
A) Dynamic content
B) Static content
C) Hardware
D) Both a and b
6. Filters were officially introduced in the Servlet ……………… specification.
A) 2.1
B) 2.3
C) 2.2
D) 2.4
7. Which is the root class of all AWT events
A) java.awt.ActionEvent
B) java.awt.AWTEvent
C) java.awt.event.AWTEvent
D) java.awt.event.Event
8. OOP features are
i) Increasing productivity ii)
Reusability iii) Decreasing
maintenance cost iv) High
vulnerability
A) 1,2 & 4
B) 1,2 & 3
C) 1, 2 & 4
D) none of the above
9. break statement is used to
i) get out of method
ii) end a program iii)
get out of a loop iv)
get out of the system

A) 1 & 2
B) 1,2 & 3
C) 1 & 3
D) 3
10. Native – protocol pure Java converts ……….. into the ………… used by DBMSs
directly.
A) JDBC calls, network protocol
B) ODBC class, network protocol
C) ODBC class, user call
D) JDBC calls, user call
11. The JDBC-ODBC bridge allows ……….. to be used as ………..
A) JDBC drivers, ODBC drivers
B) Drivers, Application
C) ODBC drivers, JDBC drivers
D) Application, drivers
12. Which of the following is true about Java.
A) Java does not support overloading.
B) Java has replaced the destructor function of C++
C) There are no header files in Java.
D) All of the above.
13. ……………. are not machine instructions and therefore, Java interpreter
generates machine code that can be directly executed by the machine that is
running the Java program.
A) Compiled Instructions
B) Compiled code
C) byte code
D) Java mid code
14. The command javac
A) Converts a java program into binary code
B) Converts a java program into bytecode
C) Converts a java program into machine language
D) None of the above.
15. Which of the following is not the java primitive type
A) Byte
B) Float
C) Character
D) Long double
16. Command to execute compiled java program is
A) java
B) javac
C) run
D) javaw
17. Java Servlet
i) is key component of server side java development ii) is a
small pluggable extension to a server that enhances
functionality iii) runs only in Windows Operating System iv)
allows developers to customize any java enabled server
A) i, ii & iii are ture
B) i, iii & iv are true
C) ii, iii & iv are true
D) i, ii & iv are true
18. Inner classes are
A) anonymous classes
B) nested classes
C) sub classes
D) derived classes
19. How many times does the following code segment
execute int x=1, y=10, z=1;
do{y–; x++; y-=2; y=z; z++} while (y>1 && z<10);
A) 1
B) 10
C) 5
D) infinite
20. State weather the following statement is true or false for EJB.
1. EJB exists in the middle-tier
2. EJB specifies an execution environment
3. EJB supports transaction processing
A) 1-true, 2. true, 3. true
B) 1- true, 2. false, 3. true
C) 1- false, 2- false, 3- false
D) 1-true, 2-true, 3-false
21. All java classes are derived from
A) java.lang.Class
B) java.util.Name
C) java.lang.Object
D) java.awt.Window
22. The jdb is used to
A) Create a jar archive
B) Debug a java program
C) Create C header file
D) Generate java documentation
23. What would happen if “String[]args” is not included as argument in
the main method. A) No error
B) Compilation error
C) Program won’t run
D) Program exit
24. For execution of DELETE SQL query in JDBC, …………. method must be used.
A) executeQuery()
B) executeDeleteQuery()
C) executeUpdate()
D) executeDelete()
25. Which method will a web browser call on a new applet?
A) main method
B) destroy method
C) execute method
D) init method
26. Which of the following is not mandatory in variable declaration?
A) a semicolon
B) an identifier
C) an assignment
D) a data type
27. When a program class implements an interface, it must provide behavior
for
A) two methods defined in that interface
B) any methods in a class
C) only certain methods in that interface
D) all methods defined in that interface
28. In order to run JSP ……………….. is required.
A) Mail Server
B) Applet viewer
C) Java Web Server
D) Database connection
29. State true of false.
i) AWT is an extended version of swing ii)
Paint( ) of Applet class cannot be
overridden
A) i-false, ii-false
B) i-false,ii-true
C) i-true, ii-false
D) i-true, ii-true
30. Prepared Statement object in JDBC used to execute……….. queries.
A) Executable
B) Simple
C) High level
D) Parameterized
31. In Java variables, if first increment of the variable takes place and then the
assignment occurs. This operation is also called ……………………….. .
A) pre increment
B) post increment
C) incrementation
D) pre incrementation
32. When the operators are having the same priority, they are evaluated from
…………….. …………. in the order they appear in the expression.
A) right to left
B) left to right
C) any of the order
D) depends on compiler
33. In java, …………. can only test for equality, where as ………… can evaluate any
type of the Boolean expression.
A) switch, if
B) if, switch
C) if, break
D) continue, if
34. The ………………….. looks only for a match between the value of the
expression and one of its case constants.
A) if
B) match
C) switch
D) None of the above
35. System.in.read() is being used, the program must specify the ………………
clause.
A) throws.java.out.IOException
B) throws.java.in.IOException
C) throws.java.io.IOException
D) throws.java.io.InException
36. By using ………………. you can force immediate termination of a loop, by
passing the conditional expression and any remaining code in the body of the
loop.
A) Break
B) Continue
C) Terminate
D) Loop Close
37. The out object is an object encapsulated inside the …………….. class, and
represents the standard output device.
A) standard
B) local
C) globlal
D) system
38. The third type of comment is used by a tool called ……………… for automatic
generation of documentation.
A) Java commenting
B) Java generator
C) Java doc
D) Java loc
39. In the second type the information written in java after // is ignored by the
…………………..
A) Interpreter
B) Compiler
C) Programmer
D) All of the above
40. The compiled java program can run on any ………………… plateform having
Java Virtual Machine (JVM) installed on it.
A) program
B) java
C) hardware
D) non java
41. Preparedstatement Object in JDBC is used to execute ………………………
queries. A) executable
B) simple
C) high level
D) parameterized
42. In JDBC …………………… imports all Java classes concerned with
database connectivity. A) javax.sql.*
B) java.mysql.*
C) java.sql.*
D) com.*
43. MS-SQL stores data in a …………………… file format.
A) .DAT
B) .MDB
C) .MSSQL
D) .OBJ
44. Ingres is a ……………………
A) Socket
B) Compiler
C) Database
D) Web server
45. In Java servlet method init( ) is called ………………… times.
A) 1
B) 2
C) 0
D) multiple
46. State true or false for Java Program.
i) All class variables are instance
variables ii) All protected methods are
friendly methods
A) i-false, ii-false
B) i-false, ii-true
C) i-true, ii-false
D) i-true, ii-true
47. State true or false for Java Program.
i) Data members of an interface are by default final ii) An abstract
class has implementations of all methods defined inside it.
A) i-false, ii-false
B) i-false, ii-true
C) i-true, ii-false D)
i-true, ii-true
48. …………………… of a remotely accessible object must implement …………….
A) all methods, RemoteException
B) class, RemoteException
C) class, RemoteInterface
D) all methods, RemoteInterface
49. ………………….is the key to ……………………
A) Serialization, persistence
B) Persistence, inheritance
C) Inheritance, object
D) Persistence, serialization
50. A method name myMethod( ) that needs two integer arguments is
declared as
A) public void myMethod( );
B) public void myMethod(int a, int b);
C) public void myMethod(int a, b);
D) public int myMethod(a, b);
51. JSP embeds in ……………. in ………………….
A) Servlet, HTML
B) HTML, Java
C) HTML, Servlet
D) Java, HTML
52. The class at the top of exception class hierarchy is ……………………..
A) ArithmeticException
B) Throwable
C) Class
D) Exception
53. In a java program, package declaration ……………….. import statements.
A) must precede
B) must succeed
C) may precede or succeed
D) none
54. The class string belongs to ………………. package.
A) java.awt
B) java.lang
C) java.applet
D) java.string
55. …………… package is used by compiler itself. So it does not need to be
imported for use.
A) java.math
B) java.awt
C) java.applet
D) java.lang
56. State true or false for the following statements in Java.
i) Java beans slow down software development
process. ii) Java Servlets do not have built in
multithreading feature.
A) i-false, ii-false
B) i-false, ii-true
C) i-true, ii-false
D) i-true, ii-true
57. State whether true or false.
i) init( ) of servlet is called after a client request comes
in ii) Servlets are ultimately converted into JSP
A) i-false, ii-false
B) i-false, ii-true
C) i-true, ii-false
D) i-true, ii-true
58. What will be the result of compiling following code.
public class MyClass{
public static void main(String args[]){
System.out.println(“In first main()”);
}
public static void main(char args[]){
System.out.println(‘a’);
}
}
A) Code will not compile and will give “Duplicate main() method declaration”
error
B) Code will compile correctly but will give a runtime exception
C) Code will compile correctly and will print “In first main()” (without quotes)
when it is run
D) Code will compile correctly and will print “a” (without quotes) when it is run
59.Match the following.
a) Java 1) is a tool for debugging java program
b) Javah 2) is a tool for creating C-like header files
c) Javap 3) runs java bytecode
d) jdb 4) prints java code representation
A) a-3, b-2,c-1
B) a-3, b-2, c-4, d-1
C) a-1, b-2, c-3, d-4
D) a-2, b-1, c-3, d-4
60.State true or false.
i) init() is called after start() in applet ii)
applets are used for networking iii)
inheritance is a part of Java Foundation
Classes iv) final does not prevent inheritance

A) i-true, ii-true, iii-false, iv-true


B) i-false, ii-false, iii-false, iv-false
C) i-true, ii-true, iii-true, iv-true
D) i-true, ii-false, iii-false, iv-false
61. The ……………… and ……………….. classes are abstract classes that support
reading and writing of byte streams.
A) reader, writer
B) inputstream, outputstream
C) objectinputstream, objectoutputstream
D) none
62. What is the error in the following code?
class Test
{ abstract void
display( );
}
A) No error
B) Method display( ) should be declared as static
C) Test class should be declared as abstract
D) Test class should be declared as public
63. A package is a collection of
A) classes
B) interfaces
C) editing tools
D) classes and interfaces
64. Which of the following methods belong to the string class?
A) length( )
B) compare To ( )
C) equals ( )
D) All of them
65. What will be the output of the following code?
byte x=64, y;
y= (byte) (x<<2);
System.out.println(y);
A) 0
B) 1
C) 2
D) 64
66. If m and n are int type variables, what will be the result of the
expression m%n when m=5 and n=2 ?
A) 0
B) 1
C) 2
D) None of the above
67. Which of the following control expressions are valid for an if statement?
A) An integer expression
B) A Boolean expression
C) Either A or B
D) Neither A nor B
8. The concept of multiple inheritance is implemented in Java by
A) extending two or more classes
B) extending one class and implementing one or more interfaces
C) implementing two or more interfaces
D) both B and C
69. Which of the following do not represent legal flow control statements?
A) break;
B) return;
C) exit();
D) continue outer;
70. Data input is
A) an abstract class defined in java.io
B) a class we can use to read primitive data types
C) an interface that defines methods to open files.
D) an interface that defines methods to read primitive data types.
71. Using which keyword we can access value of the instance variables and
class variables of that class inside the method of that class itself.
A) super
B) final
C) this
D) either super or this
72. If a variable is declared final, it must include …………………. value.
A) integer
B) no
C) initial
D) float
73. State true or false.
i) Jpanel is a class included in awt package.
ii) Anonymous classes are mostly used for event handling.
iii)Names of anonymous classes must be unique iv) JOptionPane is an inner
class A) i-false, ii-false, iii-true, iv-true
B) i-true, ii-false, iii-true, iv-false
C) i-false, ii-true, iii-false, iv-false
D) i-true, ii-false, iii-false, iv-true
74. In java, string is a ………….
A) primitive data type
B) abstract data type
C) combination of boolean
D) None of the above
75. Methods can be overloaded with a difference only in the type of the return
value ..
A) Not supported
B) False
C) True
D) None of the above
76. Each method in a java class must have a unique name.
A) Not necessary
B) True
C) False
D) None of the above 77. State true or false.
i) comparisons precede logical operations in java
ii) assignment operations succeed increment
operations iii) arithmetic operations succeed
comparisons iv) x precede +
A) i-true, ii-true, iii-false, iv-true
B) i-true, ii-false, iii-true, iv-false
C) i-false, ii-true, iii-false, iv-false
D) i-true, ii-false, iii-false, iv-true
78. It is important feature of java that it always provides a default constructor
to a class.
A) Not supported
B) False
C) True
D) None of the above
79. ………………….. is the key to ………………
A) Serialization, persistence
B) Persistence, inheritance
C) Inheritance, object
D) Persistence, serialization
80. State true of false.
i) Public can only be assigned to class ii) Protected
protects a statement iii) Protected method is never
accessible outside the package iv) Friendly variable
may be accessible outside class

A) i-true, ii-true, iii-false, iv-true


B) i-true, ii-false, iii-true, iv-false
C) i-false, ii-true, iii-false, iv-false
D) i-true, ii-false, iii-false, iv-true
81. In java a ………………….. is a sequence of characters.
A) string
B) arrayChar
C) groupChar
D) collection
82. Java programs perform I/O through ………..
A) I/O methods
B) I/O package
C) streams
D) compiler
83. What is byte code in the context of Java?
A) The type of code generated by a Java compiler
B) The type of code generated by a Java Virtual Machine
C) It is another name for Java source file
D) It is the code written within the instance methods of a class
84. Which of the following statements about abstract methods/classes in
Java is true? A) An abstract class cannot be instantiated.
B) Constructors can be abstract.
C) A subclass of an abstract class must defined the abstract methods.
D) Static methods may be declared abstract.
85. Which of the following statement is false?
A) The sleep() method should be enclosed in try ……… catch block
B) The yield() method should be enclosed in try ……… catch block.
C) A thread can be temporarily suspended from running by using the wait()
method. D) A suspended thread using suspend() method can be revived
using the resume() method.

86. The new operator dynamically allocates …………..for an object and


returns a reference to it. A) classes
B) variables
C) memory
D) none of the above
87. Which of the following statements correctly describes an interface?
A) It’s a concrete class
B) It’s a super class
C) It’s a type of abstract class
D) It’s a subclass
88. What is the priority of the Garbage collector thread of jdk?
A) Low Priority
B) Highest Priority
C) Medium Priority
D) Decided at run time
89. ……………. is a feature that allows one interface to be used for a general
class of actions. A) Class
B) Inheritance
C) Polymorphism
D) Interface
90. The default package that is implicitly called in a java program is ………….
A) java.Lang
B) java.System
C) java.Window
D) java.Lang.System
91. Java was developed by the company
A) Sun Micro systems
B) Microsoft
C) Micro tech
D) IBM
92. What is the file extension of compiled java program?
A) .class
B) .java
C) .css
D) .html
93. ……………… keyword is used to invoke the current object.
A) New
B) That
C) This
D) Me
94. Which of the function is used to convert string to Number in java program?
A) to Number()
B) conString()
C) valueOf()
D) toString()
95. What are the part in executing a Java program and their purposes?
A) Java Compiler
B) Java Interpreter
C) Java Pre-processor
D) Directive Pre-processor
96. Method overloading is one of the way that Java supports …………
A) encapsulation
B) class
C) inheritence
D) polymorphism
97. Java support RMI. What does this RMI stands for?
A) Random Memory Interface
B) Remote Method Invocation
C) Random Method Invocation
D) Remote Memory Interface
98. Which of the following represent legal flow control statements?
A) break;
B) break();
C) continue(inner);
D) exit();
99. The keywords reserved but used in the initial version of Java are
A) union
B) const
C) inner
D) goto
100. What is the default return type of main() ..
A) void
B) double
C) float
D) int
101. If m and n are int type variables, what will be the result of the expression
m%n when m=-14 and n= 3?
A) 4
B) 2
C) -2
D) -4
102. Consider the following
code if(number>=0)
if(number>0)
system.out.println(“Number is positive”);
else
system.out.println(“Number is negative”);
What will be the output if number is equal to 0?
A) Number is negative
B) Number is positive
C) Both A and B
D) None of the above 103. Consider the following code:
char c=’a’;
switch
(c){ case ‘a’:
system.out.println(“A”);
case ‘b’:
system.out.println(“B”);
default:
system.out.println(“C”);
}
For this code, which of the following statement is true?
A) Output will be A
B) Output will be A followed by B
C) Output will be A, followed by B, and then followed by C
D) Code is illegal and therefore will not compile 104. Consider
the following class definition.
class Student extends String{
}
What happens when we try to compile this class?
A) Will not compile because class body is not defined
B) Will not compile because the class in not declared
public.
C) Will not compile because string is abstract.
D) Will not compile because string is final. 105. What is wrong
in the following class definitions?
abstract class
print{ abstract show();
} class Display extends
Print{
}
A) Nothing is wrong
B) Wrong. Method show() should have a return type C)
Wrong. Method show() is not implemented in Display
D) Wrong. Display does not contain any numbers.
106. What is the error in the following class
definitions? abstract class XY{ abstract sum(int x,
int y){ }
}
A) Class header is not defined properly
B) Constructor is not defined C)
Method is not defined properly
D) No error.
107. Which of the following statements are true?
i) We cannot use abstract classes to instantiate objects directly.
ii)The abstract methods of an abstract class must be defined in its
subclass. iii) We cannot declare abstract constructors. iv) We may
declare abstract static methods.
A) Line i only
B) Line ii only
C) Line i and ii only
D) Line i, ii and iii only
108. We would like to make a member of a class visible in all subclasses
regardless of what package they are in. Which one of the following keywords
would archive this? A) Private
B) Protected
C) Public
D) Private Protected
109. The use of protected keyword to a member in a class will restrict its
visibility as follows:
A) Visible only in the class and its subclass in the same package.
B) Visible only inside the same package.
C) Visible in all classes in the same package and subclasses in other
packages
D) Visible only in the class where it is declared.
110. Consider the following
code: interface Area{ float
compute (float x, float y);
}
class Room implements
Area{ float compute (float x,
float y){ return(x&y);
}
}
What is wrong with the code?
A) Interface definition is incomplete
B) Method compute() in interface Area should be declared public
C) Method compute() in class Room should be declared public
D) All the above
111. A java program is first ……………. and ……………….
A) executed, run
B) compiled, run
C) run, compiled
D) interpreted, compiled
112. Byte code is also a ………..
A) machine code
B) bit code
C) cryptographic code
D) none
113. A private class is accessible from inside a ……………..
A) package
B) class
C) method
D) none
114. Consider the statement “x=(a>b)?a:b”, then the value of x is 19, if a=19
and b=12
A) true
B) not supported
C) false
D) none of the above
115. Adapter classes are used for ……………
A) code redundancy
B) code reduction
C) code organization
D) none
116. ………………… inheritance is enable by interface in java.
A) min level
B) multiple
C) low level
D) none
117. ……………….. is generated if a button is clicked in AWT.
A) ItemEvent
B) WindowEvent
C) ActionEvent
D) MouseEvent
118. Using which keyword we can access value of the instance and class
variables of that class inside the method of that class itself.
A) super
B) final
C) this
D) either super or this
119. If a variable is declared FINAL, it must include ……………………. value.
A) integer
B) number
C) initial
D) float
120. In java, string is a
A) primitive data type
B) abstract data type
C) combination of boolean
D) None of the above
121. Methods can be overloaded with a difference only in the type of the
return value
A) Not supported
B) False
C) True
D) None of the above
122. Each method in a java class must have a unique name
A) Not necessarily
B) True
C) False
D) None of the above
123. It is an important feature of java that it always provides a default
constructor to a class
A) Not supported
B) False
C) True
D) None of the above
124. If one or more abstract methods are not implemented in an abstract
class, then the subclass is also abstract.
A) Not necessarily
B) False
C) True
D) None of the above
125. Life cycle of an applet is described by ……………… methods.
A) six
B) three
C) four
D) five
126. Which of the following is not subclass of “writer” stream.
A) FileWriter
B) LineWriter
C) BufferedWriter
D) PrintWriter
127. In java RMI, stub is located in
A) client machine
B) proxy
C) server
D) none of the above
128. The new keyword will
i) create in instance of an
object ii) create instance of
a class iii) assign memory
to an array iv) call the
destructor of a class
A) i and iii
B) ii and iii
C) i and ii
D) ii, iii and iv
129. ODBC stands for
A) Object Data Binding Command
B) Open Database Console
C) Open Database Connectivity D) Open Database Command
130. Continue statement can be
used i) anywhere inside main
method ii) anywhere inside
class iii) within instance
methods iv) only within looping
statements
A) i, ii and iii
B) i and iv
C) only iv
D) ii, iii and iv
131) Which of the following statement is/are true?
i) The name of a java program file must match the name of the class with the
extension .java
ii) Two methods cannot have the same name in java
A. i- only
B. ii- only
C. Both i and ii
D. None of the above
132) Which of the following represent(s) of a hexadecimal number?
A. 570
B. (hex)5
C. 0X9F
D. 0X5
133) …….. can appear only where in the body of a java method.
A. definition
B. declaration
C. determine
D. package
134) State whether the following statement are True or False?
i) The modulus operator(%) can be used only with integer
operands ii) Declarations can appear anywhere in the body of a
java method
A. i-True, ii-False
B. i-False, ii-True
C. i-True, ii-True
D. i-False, ii-False
135) Which of the following will produce a value of 22 if x=22.9?
A. ceil(x)
B. round(x)
C. rint(x)
D. abs(x)
136) …….. is passed to a method by use of call by reference.
A. Variables
B. Objects
C. Methods
D. Operators
137) Using the keyboard interface you can fully abstract a …
A. Method
B. Keyword
C. Class
D. Variables
138) State True or False for the following statements in java.
i) All the bitwise operators have same level of precedence in
java ii) The default can is always required in the switch
selection structure.
A. i-True, ii-False
B. i-False, ii-True
C. i-True, ii-True
D. i-False, ii-False
139) Java is designed for ………. environment of the Internet.
A. Development
B. Deduction
C. Distributed
D. Web Design
140) Which of the following will produce a value of 10 if x=9.7?
A. floor(x)
B. abs(x)
C. rint(x)
D. round(x)
141) Variable declared as ……… do not occupy on a per instance basis.
A. Static
B. Final
C. Abstract
D. Code
142) Which of the following is not keyword?
A. NULL
B. implements
C. protected
D. switch
143) The …… statement is used to terminate a statement sequence.
A. Break
B. Switch
C. Continue
D. Wait
144) Multidimensional arrays are actually ……
A. Arrays of element
B. Arrays of variable
C. Arrays of arrays
D. Arrays of variable
145) Which of the following keywords are used to control access to a class
member? i) default ii) abstract iii) protected iv) interface v) public
A. i, ii and iii only
B. ii, iii and iv only
C. iii, iv and v only
D. ii, iii and v only
146) ……. is used for initialize the value to the string object.
A. Character literals
B. String literals
C. String group literals
D. Group literals
147) Which of the following methods can be used to remove a component
from the display? A. delete()
B. remove()
C. disappear()
D. hide()
148) Which of the following statements are valid array
declaration? i) int number(); ii) float average[ ]; iii)
double[]marks; iv) counter int[];
A. i and ii
B. ii and iii
C. iii and iv
D. All i, ii, iii and iv
149) Which of the following methods belong to the String class?
A. length()
B. CompareTo()
C. equals()
D. substring()
E. All of the above
150) Which of the following in NOT represent legal flow control statements?
A. break;
B. break();
C. continue outer;
D. return;
151) Object is an …….. of class.
A. instance
B. implement
C. inheritance
D. invoke
152) ……. is the wrapper class.
A. Random
B. Byte
C. Vector
D. String
153) Class is a …….. entity.
A. logical
B. Physical
C. up normal
D. collection of
154) Which of the following denotes a javadoc comment?
A. //#
B. /*
C. /**
D. //**
155) Object is a …….. entity.
A. normal
B. physical
C. logical
D. normal
156) One interface can inherit another by use of the keyword ……..
A. public
B. extends
C. method name
D. class name
157) ……… must be the first non comment statement in the file
A. package
B. class
C. object
D. declaration
158) In java thread to thread communication is called ….
A. passing
B. sending
C. messaging
D. calling
159) Every method of a ……….. is implicitly final.
A. static class
B. dynamic class
C. final class
D. abstract class
160) The string is defined in ……… name space.
A. java.Lang
B. java.String
C. java.Char
D. java.Awt
161) A ……… object cannot be modified after it is created.
A. double
B. int
C. string
D. main
162) ……… is a special member function.
A. method
B. class
C. use defined function
D. constructor
163) A …….. class may not have any abstract method.
A. abstract
B. static
C. final
D. public
164) Keyword ………. is always a reference to the object.
A. new
B. this
C. invoke
D. class
165) ……… operators are overloaded for string objects?
A. -,+
B. +,=
C. <<,>>
D. ++,–
166) ……. is a small unit of process.
A. method
B. thread
C. applet
D. steam
167) ……. is valid for if statement?
A. An integer expression
B. A Boolean expression
C. A character expression
D. A legal expression
168) Wrapper class is a wrapper around a ……. data type.
A. normal
B. central
C. primitive
D. concrete

169) …….. statement is valid for array declaration.


A. int number();
B. float number();
C. float number[];
D. count int[];
20) ……. operators which concatenates two strings.
A. +
B. ++
C. – D. +-
JAVA THEORY QUESTIONS
COMPILED BY MISBAWU #5
1. What do you know about Java?
Java is a high-level programming language originally developed by Sun
Microsystems and released in 1995. Java runs on a variety of platforms, such
as Windows, Mac OS, and the various versions of UNIX.
2. What are the supported platforms by Java Programming Language? Java
runs on a variety of platforms, such as Windows, Mac OS, and the various
versions of UNIX/Linux like HP-Unix, Sun Solaris, Redhat Linux, Ubuntu,
CentOS, etc.
3. List any five features of Java?
• • Some features include Object Oriented
• • Platform Independent
• • Robust
• • Interpreted
• • Multi-threaded

4. Why is Java Architectural Neutral?


It’s compiler generates an architecture-neutral object file format, which makes
the compiled code to be executable on many processors, with the presence of
Java runtime system.
5. What is a singleton class? Give a practical example of its usage.
A singleton class in java can have only one instance and hence all its methods
and variables belong to just one instance. Singleton class concept is useful
for the situations when there is a need to limit the number of objects for a
class.
The best example of singleton usage scenario is when there is a limit of
having only one connection to a database due to some driver limitations or
because of any licensing issues.
6. What are the access modifiers in Java?
There are 3 access modifiers. Public, protected and private, and the default
one if no identifier is specified is called friendly, but programmer cannot
specify the friendly identifier explicitly.
7. What is are packages?
A package is a collection of related classes and interfaces providing access
protection and namespace management.
8. What is meant by Inheritance and what are its advantages?
Inheritance is the process of inheriting all the features from a class. The
advantages of inheritance are reusability of code and accessibility of variables
and methods of the super class by subclasses.
9. 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.
10.What is an abstract class?
An abstract class is a class designed with implementation gaps for
subclasses to fill in and is deliberately incomplete.
11.What are the states associated in the thread?
Thread contains ready, running, waiting and dead states.
12.What is synchronization?
Synchronization is the mechanism that ensures that only one thread is
accessed the resources at a time.
13.What is deadlock?
When two threads are waiting each other and can’t precede the program is
said to be deadlock.
14.What is an applet?
Applet is a dynamic and interactive program that runs inside a web page
displayed by a java capable browser
15.What is the lifecycle of an applet?
init() method – Can be called when an applet is first loaded
start() method – Can be called each time an applet is
started. paint() method – Can be called when the applet is
minimized or maximized.

stop() method – Can be used when the browser moves off the applet’s page.
destroy() method – Can be called when the browser is finished with the applet.
16.How do you set security in applets?
using setSecurityManager() method
17.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 different layouts are available are FlowLayout, BorderLayout,
CardLayout,
GridLayout and GridBagLayout
18.What is JDBC?
JDBC is a set of Java API for executing SQL statements. This API consists of
a set of classes and interfaces to enable programs to write pure Java
Database applications.
19.What are drivers available?
a) JDBC-ODBC Bridge driver b) Native API Partly-Java driver
c) JDBC-Net Pure Java driver d) Native-Protocol Pure Java driver
20.What is stored procedure?
Stored procedure is a group of SQL statements that forms a logical unit and
performs a particular task. Stored Procedures are used to encapsulate a set
of operations or queries to execute on database. Stored procedures can be
compiled and executed with different parameters and results and may have
any combination of input/output parameters.
21.What is the Java API?
The Java API is a large collection of ready-made software components that
provide many useful capabilities, such as graphical user interface (GUI)
widgets.
22.Why there are no global variables in Java?
Global variables are globally accessible. Java does not support globally
accessible variables due to following reasons:
1)The global variables breaks the referential transparency
2)Global variables creates collisions in namespace.
23.What are Encapsulation, Inheritance and Polymorphism?
Encapsulation is the mechanism that binds together code and data it
manipulates and keeps both safe from outside interference and misuse.
Inheritance is the process by which one object acquires the properties of
another object. Polymorphism is the feature that allows one interface to be
used for general class actions.
24.What is the use of bin and lib in JDK?
Bin contains all tools such as javac, applet viewer, awt tool, etc., whereas lib
contains API and all packages.
25.What is method overloading and method overriding?
Method overloading: When a method in a class having the same method name
with different arguments is said to be method overloading. Method overriding :
When a method in a class having the same method name with same
arguments is said to be method overriding.
26.What is the difference between this() and super()? this() can be used to
invoke a constructor of the same class whereas super() can be used to
invoke a super class constructor.
27.What is Domain Naming Service(DNS)? It is very difficult to remember a
set of numbers(IP address) to connect to the Internet. The Domain
Naming Service(DNS) is used to overcome this problem. It maps one
particular IP address to a string of characters. For example, www. mascom.
com implies com is the domain name reserved for US commercial sites,
moscom is the name of the company and www is the name of the specific
computer, which is mascom’s server.
28.What is URL?
URL stands for Uniform Resource Locator and it points to resource files on the
Internet. URL has four components: http://www. address. com:80/index.html,
where http – protocol name, address – IP address or host name, 80 – port
number and index.html – file path.
29.What is RMI and steps involved in developing an RMI object?
Remote Method Invocation (RMI) allows java object that executes on one
machine and to invoke the method of a Java object to execute on another
machine. The steps involved in developing an RMI object are: a) Define the
interfaces b) Implementing these interfaces c) Compile the interfaces and
their implementations with the java compiler d) Compile the server
implementation with RMI compiler e) Run the RMI registry f) Run the
application.
30.What is RMI architecture?
RMI architecture consists of four layers and each layer performs specific
functions: a) Application layer – contains the actual object definition. b) Proxy
layer – consists of stub and skeleton. c) Remote Reference layer – gets the
stream of bytes from the transport layer and sends it to the proxy layer. d)
Transportation layer – responsible for handling the actual machine-to-
machine communication.
31.What is a Java Bean?
A Java Bean is a software component that has been designed to be reusable
in a variety of different environments.
32. What are checked exceptions?
Checked exception are those which the Java compiler forces you to catch. e.g.
IOException are checked Exceptions.
33. What are runtime exceptions?
Runtime exceptions are those exceptions that are thrown at runtime because
of either wrong input data or because of wrong business logic etc. These are
not checked by the compiler at compile time.
34. What is the difference between error and an exception?
An error is an irrecoverable condition occurring at runtime. Such as
OutOfMemory error. These JVM errors and you can not repair them at runtime.
While exceptions are conditions that occur because of bad input etc. e.g.
FileNotFoundException will be thrown if the specified file does not exist. Or a
NullPointerException will take place if you try using a null reference. In most
of the cases it is possible to recover from an exception (probably by giving
user a feedback for entering proper values etc.).
35. What is the purpose of finalization?
The purpose of finalization is to give an unreachable object the opportunity to
perform any cleanup processing before the object is garbage collected. For
example, closing a opened file, closing a opened database Connection.

36. What is the difference between yielding and sleeping?


When a task invokes its yield() method, it returns to the ready state. When a
task invokes its sleep() method, it returns to the waiting state.
37. What is the difference between preemptive scheduling and time slicing?
Under preemptive scheduling, the highest priority task executes until it
enters the waiting or dead states or a higher priority task comes into
existence. Under time slicing, a task executes for a predefined slice of time
and then reenters the pool of ready tasks. The scheduler then determines
which task should execute next, based on priority and other factors.
38. What is mutable object and immutable object?
If a object value is changeable then we can call it as Mutable object. (Ex.,
StringBuffer, …) If you are not allowed to change the value of an object, it is
immutable object. (Ex., String, Integer, Float, …)
39. What is the purpose of Void class?
The Void class is an uninstantiable placeholder class to hold a reference to
the Class object representing the primitive Java type void.
40. What is JIT and its use?
Really, just a very fast compiler… In this incarnation, pretty much a one-pass
compiler — no offline computations. So you can’t look at the whole method,
rank the expressions according to which ones are re-used the most, and then
generate code. In theory terms, it’s an on-line problem.
41. What is nested class?
If all the methods of a inner class is static then it is a nested class.
42. What is HashMap and Map?
Map is Interface and Hashmap is class that implements that.
43. What are different types of access modifiers? public: Any thing declared
as public can be accessed from anywhere. private: Any thing declared as
private can’t be seen outside of its class. protected: Any thing declared as
protected can be accessed by classes in the same package and
subclasses in the other packages. default modifier : Can be accessed only
to classes in the same package.

44. What is the difference between Reader/Writer and InputStream/Output


Stream?
The Reader/Writer class is character-oriented and the
InputStream/OutputStream class is byte-oriented. 45. What is servlet?
Servlets are modules that extend request/response-oriented servers, such as
javaenabled web servers. For example, a servlet might be responsible for
taking data in an
HTML order-entry form and applying the business logic used to update a
company’s order database.
46. What is Constructor?
A constructor is a special method whose task is to initialize the object of its
class. It is special because its name is the same as the class name. They
do not have return types, not even void and therefore they cannot return
values.
They cannot be inherited, though a derived class can call the base class
constructor.
Constructor is invoked whenever an object of its associated class is created.
47.What is an Iterator ?
The Iterator interface is used to step through the elements of a Collection.
Iterators let you process each element of a Collection.
Iterators are a generic way to go through all the elements of a Collection no
matter how it is organized.
Iterator is an Interface implemented a different way for every Collection.
48.What is the List interface?
The List interface provides support for ordered collections of objects.
Lists may contain duplicate elements.
49.What is memory leak?
A memory leak is where an unreferenced object that will never be used again
still hangs around in memory and doesn’t get garbage collected.
50.What is the difference between the prefix and postfix forms of the ++
operator?

The prefix form performs the increment operation and returns the value of the
increment operation. The postfix form returns the current value all of the
expression and then performs the increment operation on that value.
51.What is the difference between a constructor and a method?
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 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.
52.What will happen to the Exception object after exception handling?
Exception object will be garbage collected.
53.Difference between static and dynamic class loading.
Static class loading: The process of loading a class using new operator is
called static class loading. Dynamic class loading: The process of loading a
class at runtime is called dynamic class loading.
Dynamic class loading can be done by using
Class.forName(….).newInstance(). 54. Explain the Common use of EJB
The EJBs can be used to incorporate business logic in a web-centric
application. The EJBs can be used to integrate business processes in
Business-to-business (B2B) e-commerce applications.In Enterprise
Application Integration applications, EJBs can be used to house processing
and mapping between different applications.
55. What is JSP?
JSP is a technology that returns dynamic content to the Web client using
HTML, XML and JAVA elements. JSP page looks like a HTML page but is a
servlet. It contains Presentation logic and business logic of a web application.
56. What is the purpose of apache tomcat?
Apache server is a standalone server that is used to test servlets and create
JSP pages. It is free and open source that is integrated in the Apache web
server. It is fast, reliable server to configure the applications but it is hard to
install. It is a servlet container that includes tools to configure and manage the
server to run the applications. It can also be configured by editing XML
configuration files.

57. Where pragma is used?


Pragma is used inside the servlets in the header with a certain value. The
value is of no-cache that tells that a servlets is acting as a proxy and it has to
forward request. Pragma directives allow the compiler to use machine and
operating system features while keeping the overall functionality with the Java
language. These are different for different compilers.
58. Briefly explain daemon thread.
Daemon thread is a low priority thread which runs in the background performs
garbage collection operation for the java runtime system.
59. What is a native method?
A native method is a method that is implemented in a language other than
Java.
60. Explain different way of using thread?
A Java thread could be implemented by using Runnable interface or by
extending the Thread class. The Runnable is more advantageous, when you
are going for multiple inheritance.
61.What are the two major components of JDBC?
One implementation interface for database manufacturers, the other
implementation interface for application and applet writers.
62.What kind of thread is the Garbage collector thread?
It is a daemon thread.
63.What are the different ways to handle exceptions?
There are two ways to handle exceptions,
1. By wrapping the desired code in a try block followed by a catch block to
catch the exceptions. and
2. List the desired exceptions in the throws clause of the method and let
the caller of the method handle those exceptions.
64. How many objects are created in the following piece of
code? MyClass c1, c2, c3; c1 = new MyClass (); c3 = new
MyClass ();

Answer: Only 2 objects are created, c1 and c3. The reference c2 is only
declared and not initialized.
65.What is UNICODE?
Unicode is used for internal representation of characters and strings and it
uses 16 bits to represent each other.
66.Can a constructor have different name than a Class name in Java?
Constructor in Java must have same name as the class name and if the
name is different, it doesn’t act as a constructor and compiler thinks of it
as a normal method.
67.What will be the output of Round(3.7) and Ceil(3.7)?
Round(3.7) returns 4 and Ceil(3.7) returns 4.
68: Can we use goto in Java to go to a particular line?
In Java, there is not goto keyword and java doesn’t support this feature of
going to a particular labeled line.
69.Can a dead thread be started again?
In java, a thread which is in dead state can’t be started again. There is no way
to restart a dead thread.
70.Is the following class declaration correct?
public abstract final class testClass {
// Class methods and variables
}
The above class declaration is incorrect as an abstract class can’t be declared
as Final.
71.Is JDK required on each machine to run a Java program?
JDK is development Kit of Java and is required for development only and to
run a
Java program on a machine, JDK isn’t required. Only JRE is required.
72. Which object oriented Concept is achieved by using overloading
and overriding? Polymorphism
73.Is it possible to define a method in Java class but provide it’s
implementation in the code of another language like C?
Yes, we can do this by use of native methods. In case of native method based
development, we define public static methods in our Java class without its
implementation and then implementation is done in another language like C
separately.
74.How destructors are defined in Java?
In Java, there are no destructors defined in the class as there is no need to
do so. Java has its own garbage collection mechanism which does the job
automatically by destroying the objects when no longer referenced. 75. Can
a variable be local and static at the same time?
No a variable can’t be static as well as local at the same time. Defining a local
variable as static gives compilation error.
76.Can we have static methods in an Interface?
Static methods can’t be overridden in any class while any methods in an
interface are by default abstract and are supposed to be implemented in the
classes being implementing the interface. So it makes no sense to have static
methods in an interface in Java.
77.In a class implementing an interface, can we change the value of any
variable defined in the interface?
No, we can’t change the value of any variable of an interface in the
implementing class as all variables defined in the interface are by default
public, static and Final and final variables are like constants which can’t be
changed later.
78.Is it correct to say that due to garbage collection feature in Java, a java
program never goes out of memory?
Even though automatic garbage collection is provided by Java, it doesn’t
ensure that a Java program will not go out of memory as there is a possibility
that creation of Java objects is being done at a faster pace compared to
garbage collection resulting in filling of all the available memory resources.
So, garbage collection helps in reducing the chances of a program going out
of memory but it doesn’t ensure that.
79.Can we have any other return type than void for main method? No, Java
class main method can have only void return type for the program to get
successfully executed.
Nonetheless , if you absolutely must return a value to at the completion of
main method , you can use System.exit(int status)
80. I want to re-reach and use an object once it has been garbage collected.
How
it’s possible?
Once an object has been destroyed by garbage collector, it no longer exists on
the heap and it can’t be accessed again. There is no way to reference it again.
81.In Java thread programming, which method is a must implementation for
all threads?
Run() is a method of Runnable interface that must be implemented by all
threads.
82.I want to control database connections in my program and want that only
one thread should be able to make database connection at a time. How
can I implement this logic?
This can be implemented by use of the concept of synchronization. Database
related code can be placed in a method which has synchronized keyword so
that only one thread can access it at a time.
83.Can an Interface extend another Interface?
Yes an Interface can inherit another Interface, for that matter an Interface can
extend more than one Interface.
84.I want my class to be developed in such a way that no other class (even
derived class) can create its objects. How can I do so? If we declare the
constructor of a class as private, it will not be accessible by any other
class and hence, no other class will be able to instantiate it and formation
of its object will be limited to itself only.
85.How objects are stored in Java?
In java, each object when created gets a memory space from a heap. When an
object is destroyed by a garbage collector, the space allocated to it from the
heap is re-allocated to the heap and becomes available for any new objects.
86.How can we find the actual size of an object on the heap?
In java, there is no way to find out the exact size of an object on the heap.
87.Which of the following classes will have more memory allocated?
Class A: Three methods, four variables, no object
Class B: Five methods, three variables, no object
Memory isn’t allocated before creation of objects. Since for both classes,
there are no objects created so no memory is allocated on heap for any class.
88. What happens if an exception is not handled in a program?
If an exception is not handled in a program using try catch blocks, program
gets aborted and no statement executes after the statement which caused
exception throwing.
89.I have multiple constructors defined in a class. Is it possible to call a
constructor from another constructor’s body?
If a class has multiple constructors, it’s possible to call one constructor from
the body of another one using this().
90.What’s meant by anonymous class?
An anonymous class is a class defined without any name in a single line of
code using new keyword.
For example, in below code we have defined an anonymous class in one line
of code: public java.util.Enumeration testMethod() { return new
java.util.Enumeration()
{
@Override public boolean
hasMoreElements()
{
// TODO Auto-generated method stub
return false;
}
@Override public Object
nextElement()
{
// TODO Auto-generated method stub
return null;
}

91. Is there a way to increase the size of an array after its declaration?
Arrays are static and once we have specified its size, we can’t change it. If we
want to use such collections where we may require a change of size ( no of
items), we should prefer vector over array.
92. If an application has multiple classes in it, is it okay to have a main
method in more than one class?
If there is main method in more than one classes in a java application, it won’t
cause any issue as entry point for any application will be a specific class and
code will start from the main method of that particular class only.
93. I want to persist data of objects for later use. What’s the best approach
to do so? The best way to persist data for future use is to use the concept
of serialization.
94. What is a Local class in Java?
In Java, if we define a new class inside a particular block, it’s called a local
class.
Such a class has local scope and isn’t usable outside the block where its
defined.
95. String and StringBuffer both represent String objects. Can we compare
String and StringBuffer in Java?
Although String and StringBuffer both represent String objects, we can’t
compare them with each other and if we try to compare them, we get an
error. 96. Which API is provided by Java for operations on set of objects?
Java provides a Collection API which provides many useful methods which
can be applied on a set of objects. Some of the important classes provided by
Collection API include ArrayList, HashMap, TreeSet and TreeMap.
97.Can we cast any other type to Boolean Type with type casting?
No, we can neither cast any other primitive type to Boolean data type nor can
cast Boolean data type to any other primitive data type.
98.What are synchronized methods and synchronized statements?
Synchronized methods are methods that are used to control access to an
object. A synchronized statement can only be executed after a thread has
acquired the lock for the object or class referenced in the synchronized
statement.
99.How does a try statement determine which catch clause should be used
to handle an exception?

When an exception is thrown within the body of a try statement, the catch
clauses of the try statement are examined in the order in which they appear.
The first catch clause that is capable of handling the exception is executed.
The remaining catch clauses are ignored.
100. What will be the default values of all the elements of an array defined
as an instance variable?
If the array is an array of primitive types, then all the elements of the array will
be initialized to the default value corresponding to that primitive type.

You might also like