9.
Bank
1 Mark s
1. Which of these components are used in a Java program for compilation, debugging, and execution?
a. JDK
b. JVM
c. JRE
d. JIT
Answer: (a) JDK
2. Which of these literals can be contained in a float data type variable?
a. -3.4e+050
b. +1.7e+308
c. -3.4e+038
d. -1.7e+308
Answer: (b) -3.4e+038
3. What is BigDecimal.ONE?
a. it is a custom-defined statement
b. it is a wrong statement
c. it is a static variable that has a value of 1 on a scale of 0
d. it is a static variable that has a value of 1 on a scale of 10
Answer: (c) it is a static variable that has a value of 1 on a scale of 0
4. When an expression consists of int, double, long, float, then the entire expression will get promoted
into a data type that is:
a. float
b. double
c. int
d. long
Answer: (b) double
5. Which of the following operators can operate on a boolean variable?
A. &&
B. ==
C. ?:
D. +=
a) C & B
b) A & D
c) A, B & D
d) A, B & C
Answer: (d) A, B & C
6. Out of these statements, which ones are incorrect?
a. The Brackets () have the highest precedence
b. The equal to = operator has the lowest precedence
c. The addition operator + and the subtraction operator – have an equal precedence
d. The division operator / has comparatively higher precedence as compared to a multiplication operator
Answer: (d) The division operator / has comparatively higher precedence as compared to a multiplication
operator
7. What will be the output of the following Java program?
class Output
public static void main(String args[])
int p = 1;
int q = 2;
int r = 3;
p |= 4;
q >>= 1;
r <<= 1;
p ^= r;
System.out.println(q + ” ” + q + ” ” + r);
a. 3 3 6
b. 2 3 4
c. 2 2 3
d. 3 1 6
Answer: (d) 3 1 6
8. What will be the output of the following Java code snippet?
class P
enum Enums extends P
PQR, QRS, RST, STU;
a) Compilation Error
b) Runtime Error
c) EnumNotDefined Exception
d) It runs successfully
Answer: (a) Compilation Error
9. When does Overloading not occur?
a. When more than a single method have the same name, yet different types or number of parameters and
different method signature
b. When more than a single method have the same name, the same signature, but have different numbers
of signature
c. When more than a single method have the same signature, same name, and the same number of
parameters have different types
d. When more than a single method have the same name, the same number and types of parameters, and
yet different signatures
Answer: (d) When more than a single method have the same name, the same number and types of
parameters, and yet different signatures
10. What is it called when the child object also gets killed when the parent object is killed in the program?
a. Encapsulation
b. Association
c. Aggregation
d. Composition
Answer: (d) Composition
11. How does one identify if a compilation unit is an interface or class from a .class file?
a. Extension of the compilation unit
b. Java source file header
c. The class and interface cannot be differentiated
d. The unit type must be used to postfix interface or class name
Answer: (b) Java source file header
12. Out of these methods of the String class, which one can be used for testing the strings for equality?
a. isequals()
b. isequal()
c. equals()
d. equal()
Answer: (c) equals()
13. What would happen to the thread whenever the garbage collection kicks off?
a. The garbage collection won’t happen until the running of the thread
b. The thread would continue its operation
c. The garbage collection and the thread don’t interfere with each other
d. The thread would be paused while the running of the garbage collection
Answer: (d) The thread would be paused while the running of the garbage collection
14. Out of these, which one is the correct way of calling a constructor that has no parameters of the
superclass A by the subclass B?
a. superclass.();
b. super(void);
c. super();
d. super.A();
Answer: (c) super();
15. Out of these methods of the Object class, which one can clone an object?
a. Object clone()
b. clone()
c. Object copy()
d. copy()
Answer: (a) Object clone()
16. Out of these packages, which one contains an abstract keyword?
a. java.util
b. java.lang
c. java.system
d. java.io
Answer: (b) java.lang
17. Out of these methods, which one can be used for converting all the characters present in a String into
an Array of characters?
a. both getChars() & toCharArray()
b. both charAt() & getChars()
d. charAt()
d. all of the mentioned
Answer: (a) both getChars() & toCharArray()
18. What value is returned by the compareTo() function in case the invoking string happens to be greater
than the compared string?
a. a value that is greater than zero
b. a value that is less than zero
c. zero
d. none of the above
Answer: (a) a value that is greater than zero
19. Out of these exceptions, which one is thrown by the compareTo() method that is defined in a double
wrapper?
a. SystemException
b. ClassCastException
c. IOException
d. CastException
Answer: (b) ClassCastException
20. Where does the String Pool get stored?
a. Metaspace
b. Java Stack
c. Java Heap
d. Permanent Generation
Answer: (c) Java Heap
21. Out of these data members of the HttpResponse class, which one is used for the storage of the
response that is from an http server?
a. address
b. status
c. statusCode
d. statusResponse
Answer: (c) statusCode
22. Out of these methods, which one makes the raw MIME formatted string?
a. toString()
b. getString()
c. parse()
d. parseString()
Answer: (c) parse()
23. The remover() method throws which of these exceptions:
a. ObjectNotFoundException
b. IllegalStateException
c. IOException
d. SystemException
Answer: (b) IllegalStateException
24. Out of the following, which one is a superclass of all the exception type classes?
a. String
b. RuntimeExceptions
c. Catchable
d. Throwable
Answer: (d) Throwable
25. What happens when we call two threads that have the same priority to process simultaneously?
a. Both of the threads will be simultaneouslyexecuted
b. Any one of the threads can be executed first lexicographically
c. Itdepends on the OS
d. There will be no execution of threads
Answer: (c) Itdepends on the OS
26. Out of these classes, which one is used for reading strings and characters in Java from the console?
a. StringReader
b. BufferedReader
c. InputStreamReader
d. BufferedStreamReader
Answer: (b) BufferedReader
27. Out of these operators, which one can be used to get the run time info about an object?
a. Info
b. getInfo
c. getinfoof
d. instanceof
Answer: (d) instanceof
28. Out of these classes, which one allows a user to define their own formatting pattern for time and
dates?
a. UsersDateFormat
b. ComplexDateFormat
c. SimpleDateFormat
d. DefinedDateFormat
Answer: (c) SimpleDateFormat
29. Which method can we use in an applet to output a string?
a. transient()
b. drawString()
c. print()
d. display()
Answer: (b) drawString()
30. The public int start() returns what?
a. the start index of the previous match
b. the start index of the current match
c. the start index of the input string
d. None of the above
Answer: (a) the start index of the previous match
31. Which one is a superclass of the ContainerEvent class out of the following?
a. ComponentEvent
b. InputEvent
c. ItemEvent
d. WindowEvent
Answer: (a) ComponentEvent
32. _______ is a superclass of all the Adapter classes.
a. ComponentEvent
b. Applet
c. InputEvent
d. Event
Answer: (b) Applet
33. Which method in Java generates boolean random values?
a. randomBoolean()
b. nextBoolean()
c. generateBoolean()
d. previousBoolean()
Answer: (b) nextBoolean()
34. Which class produces objects with respect to their geographical locations?
a. Simple TimeZone
b. Date
c. Locale
d. TimeZone
Answer: (c) Locale
35. Which method is used for notifying the observer about the change in the observed object?
a. notify()
b. update()
c. observed()
d. check()
Answer: (b) update()
36. Which package is used to remotely invoke a method?
a. java.awt
b. java.rmi
c. java.applet
d. java.util
Answer: (b) java.rmi
37. What are the uses of generics?
a. The generics make a code more readable and optimised
b. The generics make a code faster
c. The generics add stability to a code. They do so by making more bugs detectable at the runtime
d. The generics add stability to a code. They do so by making more bugs detectable at the compile time
Answer: (d) The generics add stability to a code. They do so by making more bugs detectable at the
compile time
38. Which mechanism helps in the process of naming as well as visibility control of the classes and their
content?
a. Packages
b. Interfaces
c. Object
d. None of the above
Answer: (a) Packages
39. The configuration is stored in which of the file database tables:
a. .sql
b. .ora
c. .hbm
d. .dbm
Answer: (c) .hbm
40. The primary use of Files.lines(Path path) is that it:
a. reads the lines that are from a file as the Stream
b. reads the files that are at the path specified as the String
c. counts the total number of lines for the files at the specified path
d. reads the filenames at the specified path
Answer: (a) reads the lines that are from a file as the Stream
41. Which keywords for the purpose of upper bound a wildcard?
a. bound
b. stop
c. implements
d. extends
Answer: (d) extends
42. Out of the following statements, which one is not true about the Java beans?
a. It extends the java.io.Serializable class
b. It implements the java.io.Serializable interface
c. It provides getter and setter methods for its properties
d. It provides us with no argument constructor
Answer: (a) It extends the java.io.Serializable class
43. What does the abbreviation MVC pattern stand for?
a. Model View Class
b. Mock View Class
c. Mock View Controller
d. Model View Control
Answer: (d) Model View Control
44. The advantage of using the PreparedStatement in Java is:
a. More memory usage
b. Prevents SQL injection
c. Encourages SQL injection
d. Slow performance
Answer: (b) Prevents SQL injection
45. How does one move from some desired step to another one?
a. logger.error
b. logger.log
c. System.out.println
d. breakpoints
Answer: (d) breakpoints
46. What would happen if the IP Address of the host can’t be determined?
a) IOException is thrown
b) The system will exit with no message
c) Temporary IP Address will be assigned
d) UnknownHostException is thrown
Answer: (d) UnknownHostException is thrown
47. The storage capacity of a single cookie is:
a) 4095 MegaBytes
b) 4095 bytes
c) 2048 bytes
d) 2048 MegaBytes
Answer: (b) 4095 bytes
48. Which action variable helps in including a file in the JSP?
a) jsp:plugin
b) jsp:include
c) jsp:getProperty
d) jsp:setProperty
Answer: (b) jsp:include
49. ______ file defines dependency in maven.
a) dependency.xml
b) build.xml
c) version.xml
d) pom.xml
Answer: (d) pom.xml
50. The main difference between AutoCloseable and Closeable is that:
a) AutoCloseable throws IOException; Closeable throws Exception
b) AutoCloseable is an implementation; Closeable is a concept
c) AutoCloseable throws Exception; Closeable throws IOException
d) AutoCloseable is a concrete class and Closeable is an interface
Answer: (c) AutoCloseable throws Exception; Closeable throws IOException
5 Mark Questions
1. Explain the concept of Object-Oriented Programming (OOP) and how Java implements OOP
principles.
2. What is the Java Virtual Machine (JVM), and how does it work?
3. Describe the difference between == and equals() in Java.
4. What is exception handling in Java? Explain the hierarchy of exceptions and how to use try,
catch, and finally blocks.
5. : Discuss the concepts of multithreading and concurrency in Java. How do you create and manage
threads?
6. What are the main features of the Java programming language?
7. Explain the difference between an interface and an abstract class in Java.
8. Describe the role of the StringBuilder and StringBuffer classes in Java. When should you use one
over the other?
9. What is the purpose of the static keyword in Java? Provide examples of its usage.
10. How does Java achieve platform independence? Explain the role of bytecode and the Java
Runtime Environment (JRE).
11. What is the significance of the final keyword in Java? Explain its usage in variables, methods,
and classes.
12. Describe Java's memory management model, including the heap and stack. How does garbage
collection work in Java?
13. What is the difference between ArrayList and LinkedList in Java? Compare their performance
and use cases.
14. Explain the concept of Java Collections Framework. What are some of the main interfaces and
classes in this framework?
15. What is the difference between a checked exception and an unchecked exception in Java? Provide
examples of each.
16. Describe the synchronized keyword in Java. How does it help in thread safety?
17. What are lambda expressions in Java? Provide an example of how they are used.
18. Explain the concept of Generics in Java. Why are they used, and what advantages do they
provide?
19.
10 Mark Questions
1. Explain the basic concepts of Object-Oriented Programming (OOP) and how they differ from
Procedure-Oriented Programming. Discuss the benefits of OOPs with examples.
2. Describe the history and features of Java. How does Java differ from other programming
languages in terms of its design and functionality?
3. What is the Java Development Kit (JDK) and Java API? Explain the Java Environment and its
components.
4. Discuss the various types of Java programs. Provide examples of each type and explain their
specific use cases.
5. Explain the Java Virtual Machine (JVM) and its role in executing Java programs. How do
command-line arguments work in Java? Provide an example.
6. Discuss the different types of comments in Java. How are they used in a Java program? Provide
examples for single-line, multi-line, and documentation comments.
7. Explain the concepts of constants, variables, and data types in Java. Discuss the scope of
variables with examples.
8. Describe type casting in Java. What are the special operators available in Java, and how are
expressions evaluated? Provide examples.
9. Explain decision-making and branching statements in Java. How are loops used for iteration?
Discuss the use of break, labelled loop, and continue statements with examples.
10. Describe how to create and process one-dimensional and multidimensional arrays in Java.
Provide code examples for array operations.
11. Explain the concepts of Vectors and ArrayLists in Java. What are the advantages of using
ArrayList over arrays? Discuss with examples.
12. Define a class in Java. Explain how to create objects and access class members. Provide examples
to illustrate these concepts.
13. What are constructors in Java? Discuss method overloading and the use of static members in a
class. Provide code examples.
14. Explain the concept of method nesting and the use of the this keyword in Java. How are
command line inputs handled in a Java program?
15. Describe the concept of inheritance in Java. What are the different types of inheritance? Provide
examples to demonstrate each type.
16. Explain method overriding in Java. What are final variables, methods, and classes? Discuss their
significance with examples.
17. What are abstract methods and classes in Java? Explain visibility control in Java and how it helps
in encapsulation. Provide examples.
18. Define an interface in Java. How are interfaces implemented and extended? Provide examples to
illustrate interface usage.
19. Discuss the different string manipulation methods in Java. Explain the use of StringBuffer class
with examples.
20. Explain exception handling in Java. How are exceptions caught and handled? Discuss with
examples, including the use of multiple catch blocks and the finally block.
21. Describe the concept of multithreading in Java. How are threads created and managed? Provide
examples demonstrating thread creation using Thread class and Runnable interface.
22. Discuss Java I/O streams. What are byte streams and character streams? Provide examples to
illustrate reading from and writing to files.
23. Explain the lifecycle of an applet in Java. How is an applet created and executed? Discuss the use
of applet tags in HTML with examples.
24. Describe the Graphics class in Java. How are shapes like lines, rectangles, polygons, circles, arcs,
and line graphs drawn? Provide examples.
25. Discuss the creation of bar charts in Java. How are they drawn and displayed? Provide a detailed
example.
26. Explain the Abstract Window Toolkit (AWT) and event handling in Java. How are event listeners
and handlers used? Provide examples.
27. Describe the various AWT controls in Java. Explain how labels, text components, buttons, and
checkboxes are used and handled in Java applications.
28. Explain the concept of layout managers in Java. How are different layout managers used to
arrange components in a GUI? Provide examples.
29. Discuss the handling of input events in Java. How are menus created and managed? Provide
examples demonstrating menu creation and event handling.
30. Explain the Java system packages and the concept of packages in Java. How are user-defined
packages created and used? Provide examples.
1.