1.
What was the initial name of Java?
Correct Answer
B. Oak
Explanation
The initial name of Java was Oak.
2.
Apart from James Gosling who are the other two behind developing Java?
Correct Answer
C. Mike Sheridan & Patrick Naughton
Explanation
Mike Sheridan and Patrick Naughton are the other two individuals who were involved in the development of Java, along with James Gosling.
3.
What is the latest version of Java Released?
Correct Answer
B. Java 11
Explanation
Java 11 is the latest version of Java released. This version was released on September 2018 and it introduced several new features and enhancements such as local variable type inference, HTTP Client API, and improved garbage collection. It also included long-term support (LTS) which means it will receive updates and support for a longer period of time compared to non-LTS versions.
4.
Which component is responsible to OPTIMIZE bytecode to machine code?
Correct Answer
A. JIT Compiler
Explanation
The JIT Compiler, or Just-In-Time Compiler, is responsible for optimizing bytecode to machine code. It dynamically compiles parts of the bytecode that are frequently executed into machine code, which can be directly executed by the computer's hardware. This optimization process improves the performance of the Java program by reducing the overhead of interpreting bytecode and allows for faster execution.
5.
In which version release of Java, Lambda expressions were introduced?
Correct Answer
A. Java 8
Explanation
Lambda expressions were introduced in Java 8. They are a new feature that allows developers to write more concise and readable code by providing a way to express instances of single method interfaces more compactly. This feature has greatly enhanced the functionality and flexibility of Java programming language.
6.
When does method overloading is determined?
Correct Answer
B. At Compile Time
Explanation
Method overloading is determined at compile time. During compilation, the compiler checks the method signatures and resolves the method calls based on the number and types of arguments. It determines which overloaded method to call based on the arguments provided. At runtime, the specific implementation of the method is executed based on the determined method signature. Therefore, the correct answer is "At Compile Time."
7.
Which class is the superclass of every class in java?
Correct Answer
A. Object
Explanation
In Java, the class "Object" is the superclass of every class. This means that every class in Java directly or indirectly inherits from the Object class. The Object class provides a set of common methods and behaviors that are inherited by all other classes, such as toString(), equals(), and hashCode(). Therefore, "Object" is the correct answer as it is the superclass of every class in Java.
8.
Which keyword cannot be used for a class which has been declared final?
Correct Answer
A. Abstract
Explanation
The keyword "abstract" cannot be used for a class which has been declared final. The "abstract" keyword is used to declare a class as abstract, which means it cannot be instantiated. However, a class that is declared as final cannot be subclassed or extended, so it cannot have any subclasses that would be able to instantiate it. Therefore, using the "abstract" keyword for a final class would be contradictory and not allowed.
9.
Which package contains of String and StringBuffer class?
Correct Answer
C. Java.lang
Explanation
The package "java.lang" contains the String and StringBuffer classes in Java. This package is automatically imported in every Java program and includes fundamental classes that are essential for the language. String and StringBuffer are both used for manipulating and storing textual data in Java programs.
10.
Which of these classes in Java is used to encapsulate IP address and DNS?
Correct Answer
C. InetAddress
Explanation
In Java, the class used to encapsulate IP address and DNS is InetAddress. This class represents an Internet Protocol (IP) address and provides methods to get the host name, IP address, and perform other operations related to networking. It allows the programmer to work with both IPv4 and IPv6 addresses and supports methods for hostname resolution and address manipulation. Therefore, InetAddress is the correct answer for this question.
11.
Which of these is a wrapper around everything associated with a reply from an HTTP server?
Correct Answer
C. HttpResponse
Explanation
HttpResponse is the correct answer because it is a wrapper around everything associated with a reply from an HTTP server. It encapsulates the response status, headers, and body, allowing the server to send back the necessary information to the client making the request. This includes the response code, such as 200 for a successful request, as well as any additional data or content that needs to be sent back to the client. HttpResponse is an essential component in the communication between an HTTP server and client.
12.
Which of these data members of the HttpResponse class is used to store the response from an HTTP server?
Correct Answer
D. statusCode
Explanation
The data member "statusCode" of the HttpResponse class is used to store the response from an HTTP server. This member is responsible for holding the status code of the HTTP response, which indicates the success or failure of the request made to the server. By examining the value of this data member, developers can determine the outcome of the HTTP request and proceed accordingly in their code.
13.
Which of these classes is not part of Java’s collection framework?
Correct Answer
A. Map
Explanation
The correct answer is Map. Map is not part of Java's collection framework because it is not a class, but rather an interface. The collection framework in Java consists of classes such as Array, LinkedList, and Queue that are used to store and manipulate collections of objects. However, Map is an interface that represents a mapping between keys and values, and it is not considered as a class in the collection framework.
14.
Which of these class objects has an architecture similar to that of an array?
Correct Answer
B. Bitset
Explanation
Bitset has an architecture similar to that of an array. Like an array, a bitset is a fixed-size sequence of bits, where each bit can be either 0 or 1. It allows efficient manipulation of individual bits, such as setting, clearing, or testing their values. Similarly, an array is also a fixed-size sequence of elements, where each element can be accessed using an index. Both bitset and array have a similar structure and allow efficient access and manipulation of their elements.
15.
Which of these keywords is not a part of exception handling?
Correct Answer
C. Thrown
Explanation
The keyword "thrown" is not a part of exception handling. In exception handling, the keywords "try", "finally", and "catch" are used. The "try" block is used to enclose the code that may throw an exception, the "catch" block is used to handle the exception, and the "finally" block is used to execute the code regardless of whether an exception occurs or not. However, "thrown" is not a keyword used in exception handling.
16.
Which of the following is a super class of all exception type classes?
Correct Answer
C. Throwable
Explanation
The correct answer is "Throwable" because it is the superclass of all exception type classes in Java. Throwable is the root class for all exceptions and errors, and it provides common methods and attributes that are inherited by its subclasses. By catching Throwable, we can handle any type of exception or error that may occur in a program.
17.
Thread priority in Java is?
Correct Answer
A. Integer
Explanation
Thread priority in Java is represented by an integer value. The integer value represents the priority level of the thread, with higher values indicating higher priority. The priority levels range from 1 (lowest priority) to 10 (highest priority).
18.
Which of these methods of Thread class is used to find out the priority given to a thread?
Correct Answer
C. GetPriority()
Explanation
The method getPriority() is used to find out the priority given to a thread. This method is a part of the Thread class and it returns the priority of the thread as an integer value. The priority of a thread determines its importance and the order in which it is scheduled to be executed by the operating system. Higher priority threads are given preference over lower priority threads for execution. Therefore, using the getPriority() method allows us to retrieve the priority of a thread and make decisions based on it.
19.
Which of the following is an incorrect statement about interfaces?
Correct Answer
D. All variables are static and methods are public if interface is defined pubic
Explanation
This statement is incorrect because not all variables in an interface are static and methods are public if the interface is defined as public. In an interface, variables are implicitly final and static, but methods are implicitly public and abstract. The access modifiers for variables and methods in an interface can be changed, but by default, variables are static and methods are public.
20.
What is the default type of a variable in an interface?
Correct Answer
D. Public static final
Explanation
The default type of a variable in an interface is "public static final". This means that the variable is accessible from any class, it is a constant, and it can be accessed without creating an instance of the interface.
21.
What will happen if we provide a concrete implementation of the method in the interface?
Correct Answer
C. Compilation failure
Explanation
If we provide a concrete implementation of a method in an interface, it will result in a compilation failure. This is because methods in an interface are by default abstract and do not have a body. Therefore, it is not allowed to provide an implementation for a method in an interface. If we try to do so, the compiler will throw a compilation failure.
22.
What is the substitute of the Rhino javascript engine in Java 8?
Correct Answer
A. Nashorn
Explanation
Nashorn is the substitute for the Rhino JavaScript engine in Java 8. It is a lightweight, high-performance JavaScript runtime that is built into the Java Virtual Machine (JVM). Nashorn provides improved performance and compatibility with the latest ECMAScript standards compared to Rhino. It allows developers to embed JavaScript code within Java applications and provides seamless interoperability between Java and JavaScript.
23.
Which of the following code retrieves the body of the request as binary data?
Correct Answer
C. DataInputStream data = request.getInputStream()
Explanation
The correct answer is "DataInputStream data = request.getInputStream()". This code retrieves the body of the request as binary data by using the "getInputStream()" method of the "request" object. This method returns an InputStream object that allows reading the binary data from the request body. By assigning it to a DataInputStream object, the binary data can be read in a more convenient way.
24.
Which of the following is the correct error when loading the JAR file with a duplicate name?
Correct Answer
C. Java.lang.ClassFormatError
Explanation
The correct error when loading a JAR file with a duplicate name is java.lang.ClassFormatError. This error occurs when the format of the class file is not valid or is incompatible with the JVM (Java Virtual Machine). It typically happens when there are issues with the bytecode structure or version mismatch between the class file and the JVM. This error indicates that there is a problem with the format of the class file being loaded, rather than a null pointer or class not found error.
25.
How are java web applications packaged?
Correct Answer
B. Both jar and war
Explanation
Java web applications can be packaged in both jar and war formats. The jar (Java Archive) format is commonly used for packaging Java libraries and standalone applications. It contains the compiled Java classes, resources, and metadata files. On the other hand, the war (Web Application Archive) format is specifically designed for packaging web applications. It includes the necessary files and directories such as HTML, CSS, JavaScript, JSP, servlets, and configuration files. The war format is typically used for deploying web applications to web servers or application servers. Therefore, both jar and war formats are valid packaging options for Java web applications.
26.
What does MIME stand for?
Correct Answer
B. Multipurpose Internet Mail Extension
Explanation
MIME stands for Multipurpose Internet Mail Extension. It is a standard that allows different types of data, such as text, images, audio, and video, to be exchanged over the Internet. MIME is commonly used in email systems to support the transmission of attachments and to define the content type of messages.
27.
"Application" is an instance of which class?
Correct Answer
D. Javax.servlet.ServletContext
Explanation
A "ServletContext" is an instance of the "javax.servlet.ServletContext" class. The ServletContext interface is used to provide a communication channel between the web container and the servlet. It contains information about the web application and its environment. It is responsible for managing attributes, resources, and configurations of the web application. Therefore, the correct answer is "javax.servlet.ServletContext".
28.
Which two are valid constructors for Thread?
Correct Answer
A. Thread(Runnable r, String name), Thread()
Explanation
The first valid constructor for Thread is Thread(Runnable r, String name), which takes a Runnable object and a String name as parameters. This constructor creates a new thread and associates it with the specified Runnable object, allowing the thread to execute the code defined in the run() method of the Runnable object. It also sets the name of the thread to the specified name.
The second valid constructor is Thread(), which creates a new thread with no parameters. This constructor is used when the thread does not need to be associated with a specific Runnable object or have a specific name.
29.
What allows the programmer to destroy an object x?
Correct Answer
D. Only the garbage collection system can destroy an object
Explanation
In Java, the only way to destroy an object is through the garbage collection system. The garbage collector is responsible for reclaiming memory occupied by objects that are no longer in use. It automatically identifies and destroys objects that are no longer reachable by the program, freeing up memory resources. The other options mentioned, such as x.delete() and x.finalize(), do not directly destroy the object but may perform other operations such as deleting files or executing finalization code respectively. Therefore, the correct answer is that only the garbage collection system can destroy an object.
30.
What happens when the thread's yield() method is called?
Correct Answer
B. Thread returns to the waiting state.
Explanation
When the thread's yield() method is called, it temporarily pauses its execution and allows other threads of the same priority to run. However, it does not return to the ready state, as it is not waiting for any particular event or condition. Therefore, the correct answer is that the thread returns to the waiting state.
31.
The wrapping up of data and functions into a single unit is called
Correct Answer
B. Encapsulation
Explanation
Encapsulation refers to the process of combining data and functions into a single unit called a class. This allows for the hiding of internal details and provides a way to control access to the data. Encapsulation helps in achieving data integrity and code reusability by preventing direct access to the internal implementation of a class. It also enables the concept of information hiding, where the internal workings of an object are hidden from the outside world, and only the necessary information is exposed.
32.
File class is included in which package?
Correct Answer
A. Java.io package
Explanation
The File class is included in the java.io package. This package provides classes for performing input and output operations in Java, including reading and writing files. The java.lang package contains fundamental classes and basic language support, while the java.awt package provides classes for creating graphical user interfaces. The java.net package is used for networking operations.
33.
Which of the following statements are true regarding the finalize( ) method?
Correct Answer
B. The finalize( ) method can be overloaded
Explanation
The finalize() method can be overloaded means that multiple versions of the finalize() method can exist in a class, each with a different set of parameters. Overloading allows the programmer to define different behaviors for the finalize() method depending on the parameters passed to it. This can be useful in situations where different cleanup actions need to be performed depending on the specific instance of the object being finalized.
34.
Which of the following is true about the use of modifiers?
Correct Answer
C. You cannot specify accessibility of local variables.
Explanation
The statement "You cannot specify accessibility of local variables" is true. Local variables are only accessible within the block of code where they are declared. They are not accessible outside of that block, so there is no need to specify their accessibility. Access modifiers like public, private, or protected are used for class members (fields, methods, constructors), not for local variables.
35.
The java run time system automatically calls this method while garbage collection.
Correct Answer
C. finalize()
Explanation
The correct answer is "finalize()". In Java, the finalize() method is called by the garbage collector before an object is destroyed. This method allows the object to perform any necessary cleanup or resource release operations before it is removed from memory. The finalize() method is automatically called by the Java runtime system during garbage collection, making it a crucial method for managing resources and ensuring proper memory management in Java programs.
36.
Which of the following statements about Java Threads is correct?
Correct Answer
D. Ready, running and sleeping are three states that a thread can be in during its life cycle
Explanation
Ready, running, and sleeping are three states that a thread can be in during its life cycle. In the ready state, the thread is waiting to be assigned to a processor by the operating system. In the running state, the thread is actively executing its code. In the sleeping state, the thread is temporarily inactive and waiting for a specified amount of time or for a specific condition to occur before resuming its execution. These three states are fundamental to the life cycle of a thread in Java.
37.
How does applet and servlet communicate?
Correct Answer
D. HTTP Tunneling
Explanation
Applets and servlets communicate using HTTP tunneling. HTTP tunneling is a technique that allows communication between a client (in this case, the applet) and a server (the servlet) through HTTP protocols. It involves encapsulating non-HTTP protocols within HTTP packets, allowing them to be transmitted over the internet. This enables the applet and servlet to exchange data and information securely and efficiently.
38.
Which class provides system independent server-side implementation?
Correct Answer
C. ServerSocket
Explanation
ServerSocket provides system independent server-side implementation. ServerSocket is a class in Java that is used for creating a server socket. It provides a mechanism for the server to listen for incoming client requests. ServerSocket is platform-independent, meaning it can be used on any operating system or platform that supports Java. It allows the server to accept connections from clients and establish a communication channel between them. ServerSocket is specifically designed for server-side implementation and provides the necessary functionality to create a server application.
39.
What is the java method for ping?
Correct Answer
C. IsReachable()
Explanation
The correct answer is "isReachable()". This method in Java is used to check if a particular host is reachable or not. It takes a timeout value as an argument and returns a boolean value indicating whether the host is reachable within the specified time limit. It can be used to test the connectivity to a remote host or to check if a specific network port is open.
40.
Which of the following is stored on client-side?
Correct Answer
D. Cookies
Explanation
Cookies are small text files that are stored on the client-side (i.e., the user's computer) by websites. They are used to store information about the user's preferences, login status, and other data that can be accessed by the website when the user visits it again. This allows websites to personalize the user experience and remember certain information. Therefore, cookies are the correct answer as they are specifically designed to be stored on the client-side.
41.
Which object is used by spring for authentication?
Correct Answer
D. SecurityContextHolder
Explanation
SecurityContextHolder is the object used by Spring for authentication. It provides a convenient way to access the security context, which holds authentication information such as the currently authenticated user and their granted authorities. This object is used throughout the Spring Security framework to retrieve and manipulate the authentication details during the authentication and authorization processes.
42.
How can we delete all files in a directory by Java?
Correct Answer
A. Files.delete(path)
Explanation
The correct answer is Files.delete(path). This method is used to delete a single file or an empty directory specified by the given path. It throws an IOException if the file cannot be deleted for any reason.
43.
Which jar provides FileUtils which contains methods for file operations?
Correct Answer
A. Apache commons
Explanation
The correct answer is "apache commons" because the Apache Commons library provides the FileUtils class, which contains methods for file operations. This library is commonly used in Java development for its extensive collection of reusable components and utilities.
44.
Which of these package is used for the graphical user interface?
Correct Answer
B. Java.awt
Explanation
The correct answer is java.awt. This package is used for creating graphical user interfaces in Java. It provides classes and methods for creating windows, buttons, menus, and other GUI components. The java.awt package allows developers to create interactive and visually appealing user interfaces for their Java applications.
45.
Which of these package is used for analyzing code during run-time?
Correct Answer
A. Java.lang.reflect
Explanation
The java.lang.reflect package is used for analyzing code during run-time. It provides classes and interfaces that allow you to examine and modify the runtime behavior of applications. This package is commonly used for implementing reflection in Java, which enables the program to examine its own structure and behavior at runtime. With java.lang.reflect, you can access and manipulate classes, fields, methods, and constructors dynamically, making it a powerful tool for code analysis and modification during runtime.
46.
Which method is used to generate boolean random values in java?
Correct Answer
B. NextBoolean()
Explanation
The correct answer is nextBoolean(). In Java, the nextBoolean() method is used to generate random boolean values. It returns a random boolean value, either true or false, with equal probability.
47.
Which of the following classes produce objects with respect to geographical locations?
Correct Answer
D. Locale
Explanation
The class "Locale" produces objects with respect to geographical locations. The Locale class in Java represents a specific geographical, political, or cultural region. It is used to customize the behavior of programs based on the user's location or language preferences. By creating a Locale object, you can access information about the user's language, country, and variant, which can be useful for internationalization and localization purposes.
48.
What does AWT stand for?
Correct Answer
C. Abstract Window Toolkit
Explanation
AWT stands for Abstract Window Toolkit. This is a set of application programming interfaces (APIs) provided by Java for creating graphical user interfaces (GUIs) for Java programs. AWT provides a collection of classes and methods that allow developers to create windows, buttons, menus, and other GUI components. It is a fundamental part of Java's GUI programming and allows for the creation of platform-independent GUI applications.
49.
Which of these is a type of stream in Java?
Correct Answer
A. Byte stream
Explanation
A byte stream is a type of stream in Java. Streams are used for reading or writing data in a sequential manner. Byte streams are used for handling binary data, such as reading or writing files in their raw byte format. They are commonly used for input/output operations on files or network sockets, where the data is represented in bytes. Byte streams provide methods for reading and writing individual bytes or arrays of bytes.