1.
Which of these package is used for graphical user interface?
Correct Answer
B. java.awt
Explanation
The correct answer is java.awt. The java.awt package is used for creating graphical user interfaces in Java. It provides classes and methods for creating windows, buttons, menus, and other graphical components. The classes in java.awt package are used to handle events, layout components, and perform various other GUI-related tasks.
2.
Which of these access specifiers can be used for an interface?
Correct Answer
A. Public
Explanation
The access specifier "Public" can be used for an interface. This means that the interface can be accessed and implemented by any class in any package. It allows for maximum accessibility and visibility of the interface.
3.
Which of these keywords is used by a class to use an interface defined previously?
Correct Answer
C. implements
Explanation
The "implements" keyword is used by a class to use an interface defined previously. This keyword is used to indicate that a class is implementing an interface and will provide implementations for all the methods defined in that interface. It allows the class to inherit the methods and properties of the interface and ensures that the class follows the contract defined by the interface.
4.
What is debugging an application which runs on another java virtual machine on another machine?
Correct Answer
B. remote debugging
Explanation
Remote debugging refers to the process of debugging an application that is running on a different machine or Java Virtual Machine (JVM). It allows developers to remotely connect to the JVM on the other machine and analyze and debug the code in real-time. This is particularly useful when troubleshooting issues that can only be replicated on a specific environment or when the application is running on a remote server. Remote debugging enables developers to step through the code, set breakpoints, inspect variables, and understand the flow of execution, ultimately helping them identify and fix bugs efficiently.
5.
What happens when the value of variable change?
Correct Answer
D. variable tab shows variables highlighted when values change
Explanation
When the value of a variable changes, the variable tab in the program shows the variables highlighted when their values change. This means that whenever a variable is modified, the variable tab will indicate which variables have been updated by highlighting them. This feature helps the programmer easily track and identify the changes in the values of variables during the execution of the program.
6.
Which of the following contains both date and time?
Correct Answer
D. java.util.dateTime
Explanation
The correct answer is java.util.dateTime because it is the only option that includes both date and time. The other options, java.io.date, java.sql.date, and java.util.date, only represent dates without including the time component.
7.
Which of the following is the correct way of importing an entire package ‘pkg’?
Correct Answer
C. import pkg.*
Explanation
The correct way of importing an entire package 'pkg' is by using the statement "import pkg.*". This statement allows all the classes and interfaces within the 'pkg' package to be accessible in the current code file.
8.
Which of the following is an incorrect statement about packages?
Correct Answer
D. A package can be renamed without renaming the directory in which the classes are stored
Explanation
A package cannot be renamed without renaming the directory in which the classes are stored. This is because in Java, the package name and the directory structure are closely related. The package name must match the directory structure, and if the package is renamed, the corresponding directory must also be renamed to match the new package name.
9.
Which attribute is used to specify initialization method?
Correct Answer
B. init-method
Explanation
The attribute "init-method" is used to specify the initialization method. This attribute is commonly used in frameworks like Spring to define a method that should be called after the bean is instantiated and its dependencies are injected, allowing for any necessary initialization tasks to be performed.
10.
Which attribute is used to specify destroy method?
Correct Answer
B. destroy-method
Explanation
The correct answer is "destroy-method". This attribute is used to specify the method that should be called when the bean is being destroyed. It allows for any necessary cleanup or releasing of resources before the bean is removed from the container.
11.
Which of these instance cannot be created?
Correct Answer
C. Generic type instance
Explanation
A generic type instance cannot be created because a generic type is a template that is used to create specific instances of a class or method. It is not an actual instance itself. Generic types are used to create classes or methods that can work with different types of data, allowing for code reusability. However, the actual instances of these generic types need to be created using specific type arguments.
12.
Which of these data type cannot be type parameterized?
Correct Answer
A. Array
Explanation
Arrays in most programming languages cannot be type parameterized because they are fixed-size data structures that can only store elements of the same type. Unlike other data structures like lists, maps, and sets, which can be dynamically resized and can store elements of different types, arrays have a fixed length and can only hold elements of a single type. Therefore, arrays cannot be type parameterized.
13.
What are generic methods?
Correct Answer
C. Generic methods are methods that introduce their own type parameters
Explanation
Generic methods are methods that introduce their own type parameters. This means that when declaring a generic method, we can specify one or more type parameters that can be used within the method's body. These type parameters allow us to write code that can work with different types, without having to specify the exact type at compile time. This provides flexibility and reusability in our code, as the same method can be used with different types of data.
14.
Which of these Exception handlers cannot be type parameterized?
Correct Answer
D. all of the mentioned
Explanation
All of the mentioned exception handlers cannot be type parameterized. In Java, catch, throw, and throws are used to handle exceptions. However, unlike other parts of the code where type parameters can be specified, exception handlers cannot be type parameterized. This means that you cannot specify the type of exception that a catch block can handle or the type of exception that a method throws. Therefore, the correct answer is that all of the mentioned exception handlers cannot be type parameterized.
15.
Which of the following cannot be Type parameterized?
Correct Answer
A. Overloaded Methods
Explanation
Overloaded methods cannot be type parameterized because type parameters are used to provide flexibility and allow for generic programming. Overloaded methods, on the other hand, are used to provide different implementations of a method with the same name but different parameters. Type parameters are not necessary or applicable in this context, as the method signatures already differentiate between the different overloaded versions of the method.
16.
What should the return type of method where there is no return value?
Correct Answer
B. Empty collection
Explanation
The return type of a method where there is no return value should be an empty collection. This means that the method does not return any specific value, but instead returns an empty collection object. This is often used when a method performs some operation or calculation but does not need to return any data. By returning an empty collection, it allows the caller to still iterate over the collection, even though it is empty.
17.
What data structure should be used when number of elements is fixed?
Correct Answer
A. Array
Explanation
When the number of elements is fixed, the most suitable data structure to use is an array. Arrays have a fixed size and can store a collection of elements of the same data type. They provide constant time access to elements based on their index, making it efficient to retrieve and manipulate data. Additionally, arrays allocate memory in a contiguous manner, allowing for efficient memory management. Therefore, when the number of elements is known and will not change, using an array is the appropriate choice.
18.
What causes the program to exit abruptly and hence its usage should be minimalistic?
Correct Answer
C. Exit
Explanation
The "Exit" statement causes the program to exit abruptly and therefore its usage should be minimalistic. When the "Exit" statement is encountered, the program terminates immediately without executing any further code. This can be useful in certain scenarios, such as when an error occurs and the program needs to be stopped immediately. However, excessive use of the "Exit" statement can lead to unexpected program termination and make it difficult to debug and maintain the code. Therefore, it is recommended to use the "Exit" statement sparingly and only when necessary.
19.
Which one of the following causes memory leak?
Correct Answer
D. Not using Finally block often
Explanation
Not using the Finally block often can cause a memory leak. The Finally block is used to ensure that certain code is executed regardless of whether an exception is thrown or not. If the Finally block is not used, resources such as memory may not be properly released, leading to a memory leak. Therefore, it is important to use the Finally block to ensure proper cleanup and prevent memory leaks.
20.
Which of the following is a best practice to measure time taken by a process for execution?
Correct Answer
B. System.nanoTime()
Explanation
System.nanoTime() is the best practice to measure the time taken by a process for execution. This method returns the current value of the system's high-resolution time source, typically in nanoseconds. It provides a more precise and accurate measurement of time compared to System.currentTimeMillis(), which has a lower resolution. System.getCurrentTime() and System.getProcessingTime() are not valid methods in Java, making them incorrect options.
21.
Which of the below is true about java class structure?
Correct Answer
C. The class should only contain those attribute and functionality which it should; hence keeping it short
Explanation
The correct answer states that the class should only contain those attributes and functionality which it should, hence keeping it short. This means that a class should only have the necessary attributes and methods that are relevant to its purpose, rather than including unnecessary code. This helps in keeping the class focused and easier to understand, maintain, and reuse. It also promotes better code organization and improves overall code quality.
22.
Which of the below is false about java coding?
Correct Answer
A. variable names should be short
Explanation
In Java coding, variable names should not necessarily be short. It is recommended to use meaningful and descriptive variable names that convey the purpose and content of the variable. Short variable names may lead to confusion and make the code harder to understand and maintain.
23.
Which is better in terms of performance for iterating an array?
Correct Answer
B. for(int i=99; i>=0; i--)
Explanation
The correct answer is "for(int i=99; i>=0; i--)". This is because it starts from the highest index (99) and iterates backwards until it reaches the lowest index (0). This approach is more efficient because it avoids unnecessary checks and calculations, resulting in better performance compared to the other options.
24.
Which of the following is not introduced with Java 8?
Correct Answer
B. Serialization
Explanation
Serialization was not introduced with Java 8. Serialization is a concept that allows objects to be converted into a byte stream, which can be stored or transmitted and then reconstructed back into objects. It was introduced in earlier versions of Java and is used for various purposes like object persistence and network communication. Java 8 introduced new features like the Stream API, Spliterator, and Lambda Expressions, which aimed to enhance the functional programming capabilities of the language.
25.
What does Files.lines(Path path) do?
Correct Answer
A. It reads all the files at the path specified as a String