×

Multiple-Choice Questions

Web Technologies MCQs

Computer Science Subjects MCQs

Databases MCQs

Programming MCQs

Testing Software MCQs

Digital Marketing Subjects MCQs

Cloud Computing Softwares MCQs

AI/ML Subjects MCQs

Engineering Subjects MCQs

Office Related Programs MCQs

Management MCQs

More

Java Multiple-Choice Questions (MCQs)

Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.

Java MCQs: This section contains multiple-choice questions and answers on Java programming language. It will help the students and developers to prepare well for their exams, and enhance their skills.

List of Java MCQs

1. JDK stands for ____.

  1. Java development kit
  2. Java deployment kit
  3. JavaScript deployment kit
  4. None of these

Answer: A) Java development kit

Explanation:

JDK stands for Java Development Kit. It is a platform to develop and run Java applications.

Discuss this Question


2. JRE stands for ___.

  1. Java run ecosystem
  2. JDK runtime Environment
  3. Java Runtime Environment
  4. None of these

Answer: C) Java Runtime Environment

Explanation:

JRE stands for Java Runtime Environment which provides an environment to run a java program.

Discuss this Question


3. What makes the Java platform independent?

  1. Advanced programming language
  2. It uses bytecode for execution
  3. Class compilation
  4. All of these

Answer: B) It uses bytecode for execution

Explanation:

In Java, programs are compiled into byte code and that byte code is platform-independent.

Discuss this Question


4. Can we keep a different name for the java class name and java file name?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can keep different names for java filename and java class name if and only if the class is not public.

Discuss this Question


5. What are the types of memory allocated in memory in java?

  1. Heap memory
  2. Stack memory
  3. Both A and B
  4. None of these

Answer: C) Both A and B

Explanation:

Memory allocation in java occurs in two ways, mainly, stack and heap space.

Discuss this Question


6. Multiline comment is created using ___.

  1. //
  2. /* */
  3. <!--  -- >
  4. All of these

Answer: B) /* */

Explanation:

Multi-line comments start with /* and ends with */. Any text between /* and */ will be ignored by Java.

Discuss this Question


7. What is the entry point of a program in Java?

  1. main() method
  2. The first line of code
  3. Last line of code
  4. main class

Answer: A) main() method

Explanation:

Generally, the main() method is treated as the point where the flow of code starts.

Discuss this Question


8. Can we write a program without a main method in Java?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can write a java program without the main() method but there is a condition if and only if java JDK version till JDK 5.

Discuss this Question


9. Can the main() method be overloaded in Java?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, We can overload the main method in java but JVM only calls the original main method, it will never call our overloaded main method.

Discuss this Question


10. Which keyword in java is used for exception handling?

  1. exep
  2. excepHand
  3. throw
  4. All of these

Answer: C) throw

Explanation:

the throw is a keyword introduced in java for exception handling.

Discuss this Question


11. Which class in Java is used to take input from the user?

  1. Scanner
  2. Input
  3. Applier
  4. None of these

Answer: A) Scanner

Explanation:

The Scanner class is used to get user input, and it is found in the java. util package.

Discuss this Question


12. Method used to take a string as input in Java?

  1. next()
  2. nextLine()
  3. Both A. and B.
  4. None of these

Answer: B) Both A. and B.

Explanation:

The next() method can read the input only till the space. It can't read two words separated by space, while the nextLine() reads input including space between the words (that is, it reads till the end of line \n).

Discuss this Question


13. Which of the following is the correct syntax to create a variable in Java?

  1. var name;
  2. int name;
  3. var name int;
  4. All of these

Answer: B) int name;

Explanation:

Read here: Java variable declarations

Discuss this Question


14. Is string mutable in Java?

  1. Yes
  2. No

Answer: B) No

Explanation:

String in Java is immutable i.e., once defined the value cannot be changed.

Discuss this Question


15. Which of these is a type of variable in Java?

  1. Instance Variable
  2. Local Variable
  3. Static Variable
  4. All of these

Answer: D) All of these

Explanation:

There are three types of variables in Java:

  1. Instance variable
  2. Local variable
  3. Class/Static variable

Discuss this Question


16. What will be the output of following Java code?

public class Main {
  public static void main(String[] args) {
    String str = "Hello";
    str = "Bye";
    System.out.println(str);
  }
}
  1. Hello
  2. Bye
  3. Error
  4. All of these

Answer: B) Bye

Discuss this Question


17. What is type casting in Java?

  1. It is converting type of a variable from one type to another
  2. Casting variable to the class
  3. Creating a new variable
  4. All of these

Answer: A) It is converting type of a variable from one type to another

Explanation:

Type casting is when you assign a value of one primitive data type to another type.

Discuss this Question


18. Which type of casting is lossy in Java?

  1. Widening typecasting
  2. Narrowing typecasting
  3. Manual typecasting
  4. All of these

Answer: B) Narrowing typecasting

Explanation:

In Narrowing typecasting data loss is there.

Discuss this Question


19. Which of the following can be declared as final in java?

  1. Class
  2. Method
  3. Variable
  4. All of these

Answer: D) All of these

Explanation:

Class, method, and variables all can be declared as final in Java.

Discuss this Question


20. Finally block is attached to?

  1. Try-catch block
  2. Class block
  3. Method block
  4. All of these

Answer: A) Try-catch block

Explanation:

Finally, block of code runs at the end of the try-catch block.

Discuss this Question


21. The break statement in Java is used to ___.

  1. Terminates from the loop immediately
  2. Terminates from the program immediately
  3. Skips the current iteration
  4. All of these

Answer: A) Terminates from the loop immediately

Explanation:

The break statement in Java is used to terminate from the loop immediately.

Discuss this Question


22. What will be the output of following Java code?

public class Main {
  public static void main(String arg[]) {
    int i;
    for (i = 1; i <= 12; i += 2) {
      if (i == 8) {
        System.out.println(i);
        break;
      }
    }
  }
}
  1. 1
  2. No output
  3. 8
  4. 1357911

Answer: B) No output

Explanation:

The condition (i == 8) could not be satisfied hence nothing cannot be printed.

Discuss this Question


23. Can the Java program accept input from the command line?

  1. Yes, using command-line arguments
  2. Yes, by access command prompt
  3. No
  4. None of these

Answer: A) Yes, using command-line arguments

Explanation:

In Java, we can also provide values (arguments) while calling the program through the command line. These arguments are known as Command Line Arguments.

Discuss this Question


24. Array in java is ___.

  1. Collection of similar elements
  2. Collection of elements of different types
  3. The data type of consisting of characters
  4. None of these

Answer: A) Collection of similar elements

Explanation:

Array is a collection of similar elements.

Discuss this Question


25. Which of these is the correct method to create an array in java?

  1. int[] arr = {1, 3, 5};
  2. int[] arr;
  3. arr = new int[] {3, 1, 8};
  4. int arr[] = {1, 4, 6};
  5. All of these

Answer: E) All of these

Explanation:

Read here: How to declare and initialize an array in Java?

Discuss this Question


26. Object in java are ___.

  1. Classes
  2. References
  3. Iterators
  4. None of these

Answer: B) References

Explanation:

Objects in Java are Reference Variables.

Discuss this Question


27. What is garbage collection in java?

  1. Method to manage memory in java
  2. Create new garbage values
  3. Delete all values
  4. All of these

Answer: A) Method to manage memory in java

Explanation:

Garbage collection in Java is the process by which Java programs perform automatic memory management.

Discuss this Question


28. Static variables in java are declared as ___.

  1. final variables
  2. new variables
  3. Constants
  4. All of these

Answer: C) Constants

Explanation:

The static variables declarations just like constants, they required static keyword and an initial value.

Discuss this Question


29. BigInteger Class is used to ___.

  1. Store very long range of number
  2. Store integer values
  3. A class that stores large range of integer
  4. All of these

Answer: D) All of these

Explanation:

All of the above points are correct with respect to a BigInteger class.

Discuss this Question


30. 'this' keyword in java is ___.

  1. Used to hold the reference of the current object
  2. Holds object value
  3. Used to create a new instance
  4. All of these

Answer: A) Used to hold the reference of the current object

Explanation:

Java this keyword is used to hold the reference of the current object.

Discuss this Question


31. What will be the output of following Java code?

import java.util.Scanner;

class ThisKeyword {
  private int a = 4;
  private int b = 1;

  void getSum(int a, int b) {
    this.a = a;
    this.b = b;
    System.out.println(this.a + this.b);
  }
}

public class Main {
  public static void main(String args[]) {
    ThisKeyword T = new ThisKeyword();
    T.getSum(3, 5);
  }
}
  1. 5
  2. 9
  3. 8
  4. 4

Answer: C) 8

Explanation:

The above Java program is an example to demonstrate the use of this keyword.

Discuss this Question


32. The 'super' keyword is used to ___.

  1. Access instance of the parent class
  2. Access instance of the same class
  3. Access instance of child class
  4. Access instance of friend class

Answer: A) Access instance of the parent class

Explanation:

The super keyword refers to superclass (parent) objects. It is used to call superclass methods, and to access the superclass constructor.

Discuss this Question


33. The super() method is used to ___.

  1. Call constructor of friend class
  2. Is a declared method
  3. Call constructor of the parent class
  4. Call constructor

Answer: C) Call constructor of the parent class

Explanation:

In Java programming language, the super() is a reference variable that is used to refer parent class constructors. The super can be used to call parent class's variables and methods. The super() can be used to call parent class' constructors only.

Discuss this Question


34. Wrapper class in java is ___.

  1. Used to encapsulate primitive data types
  2. Declare new classes called wrapper
  3. Create a new instance of the class
  4. None of these

Answer: A) Used to encapsulate primitive data types

Explanation:

A Wrapper class is a class whose object wraps or contains primitive data types.

Discuss this Question


35. Boxing is ___.

  1. Creating new box
  2. Creating object
  3. Converting primitive type of object instance
  4. All of these

Answer: C) Converting primitive type of object instance

Explanation:

In Java programming language, the wrapper classes are those whose objects wraps a primitive data type within them. The wrapper class is used for converting primitive datatype to object is called boxing.

Discuss this Question


36. Abstract class is ___.

  1. Created using abstract keyword
  2. Contains only abstract method
  3. Needs to be inherited to be used
  4. All of these

Answer: D) All of these

Explanation:

An abstract class is a class that contains an abstract method. It is defined using abstract keyword only has method declarations and to use these methods, the abstract class needs to be inherited.

Discuss this Question


37. What is file handling in java?

  1. It is creating, deleting, and modifying files using a java program.
  2. Creating new method
  3. Filing method to different file to extract them better
  4. All of these

Answer: A) It is creating, deleting, and modifying files using a java program

Explanation:

File handling is used for creating, deleting, and modifying files using a java program.

Discuss this Question


38. How can we access methods for file handling in java?

  1. Java.files
  2. Java.io
  3. Java.io.File
  4. Java.FileHandling

Answer: C) Java.io.File

Explanation:

To access the file handling methods, we need to use Java.io.File.

Discuss this Question


39. Which is the correct absolute path of a file in Java?

  1. C:\Program Files\Java\jdk1.8.0_131\bin\file_name.txt
  2. C:\Program Files\Java\file_name.txt
  3. C:\Program Files\Java\jdk1.8.0_131\file_name.txt
  4. C:\Program Files\Java\jdk1.8.0_131\bin\File Handling\file_name.txt

Answer: A) C:\Program Files\Java\jdk1.8.0_131\bin\file_name.txt

Explanation:

The correct absolute path of a file in Java is:

C:\Program Files\Java\jdk1.8.0_131\bin\file_name.txt

Discuss this Question


40. Which method is used to add a new line to file in Java?

  1. file.addLine()
  2. file.nextLine()
  3. file.write()
  4. file.line()

Answer: C) file.write()

Explanation:

The file.write() method is used to add a new line to file in Java.

Discuss this Question


41. Which method deletes a file in Java?

  1. file.delete()
  2. file.remove()
  3. file.garbage()
  4. file.dump()

Answer: A) file.delete()

Explanation:

The file.delete() method is used to delete a file in Java.

Discuss this Question


42. Which method in java is used to read lines from file?

  1. file.read()
  2. file.nextLine()
  3. file.getLine()
  4. All of these

Answer: C) file.getLine()

Explanation:

The file.getLine() method is used to read lines from a file.

Discuss this Question


43. The correct syntax to import the math library in java is ___.

  1. import java.lang.math
  2. import math
  3. import java.math
  4. All of these

Answer: A) import java.lang.math

Explanation:

The correct syntax to import the math library in java is:

import java.lang.math

Discuss this Question


44. Which is/are valid method(s) of math library in java?

  1. max()
  2. cbrt()
  3. log10()
  4. All of these

Answer: D) All of these

Explanation:

Some common methods of the math library are max(), min(), cbrt(), pow(), log(), log10(), etc.

Discuss this Question


45. Which method in java is used to generate random numbers in Java?

  1. random.nextInt()
  2. random()
  3. rand()
  4. All of these

Answer: A) random.nextInt()

Explanation:

The Java method random.nextInt() is used to generate random numbers.

Discuss this Question


46. In java, recursion is ___.

  1. Method
  2. A process allowing methods to call itself
  3. The process to call methods
  4. None of these

Answer: B) A process allowing methods to call itself

Explanation:

The recursion is a process by which a process allow methods to call itself.

Discuss this Question


47. What is stringBuffer in java?

  1. Class to create a string array
  2. Class to create a mutable string in java
  3. Class to create a string from i/o buffer
  4. All of these

Answer: B) Class to create a mutable string in java

Explanation:

StringBuffer class is used to create modifiable strings in java.

Discuss this Question


48. Which of the following is a valid data structure in java?

  1. Array
  2. List
  3. Vector
  4. All of these

Answer: D) All of these

Explanation:

All of the above (Array, List, and Vector) are valid data structures in Java.

Discuss this Question


49. Which syntax is valid to create a vector in java?

  1. Vector < string > names = new Vector < String > ();
  2. Vector name = new string;
  3. int name = new vector ()
  4. All of these

Answer: A) Vector < string > names = new Vector < String > ();

Explanation:

The hex2bin() function is used to convert hexadecimal values to the ASCII characters.

The syntax to create a vector in Java is:

Vector < string > names = new Vector < String > ();

Discuss this Question


50. What will be the output of following Java code?

import java.util.Scanner;

class ThisKeyword {
  private int a = 4;
  private int b = 1;

  void getSum(int a, int b) {
    this.a = a;
    this.b = b;
    System.out.println(this.a + this.b);
  }
}

public class Main {
  public static void main(String args[]) {
    ThisKeyword T = new ThisKeyword();
    T.getSum(3, 5);
  }
}
  1. Error
  2. 8
  3. 5
  4. None of these

Answer: B) 8

Explanation:

The output of the above program is:

8

Discuss this Question


51. Which of these is true for interfaces in java?

  1. The keyword interface is used to create a method
  2. All the methods of an interface are abstract
  3. It does not contain constructors
  4. All of these

Answer: D) All of these

Explanation:

All of the above points are true for interfaces in Java.

Discuss this Question


52. Encapsulation is ___.

  1. Wrapping up of data and related functions into a single entity
  2. Creating special methods
  3. Creating special data structure
  4. All of these

Answer: A) Wrapping up of data and related functions into a single entity

Explanation:

In Java programming language, the encapsulation is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. It is a object-oriented programming concept.

Discuss this Question


53. Which Java method is used to convert an object to string?

  1. createString()
  2. toString()
  3. object.string()
  4. newString()

Answer: B) toString()

Explanation:

Java method toString() is used to convert an object to string.

Discuss this Question


54. What is a comparator in Java?

  1. Interface to compare integer
  2. Comparison method for lists
  3. Interface to compare two objects in java
  4. All of these

Answer: C) Interface to compare two objects in java

Explanation:

Java Comparator interface is used to order the objects of a user-defined class.

Discuss this Question


55. Which of the following methods are present in comparator interface?

  1. compare()
  2. equate()
  3. isEqual()
  4. All of these

Answer: A) compare()

Explanation:

The comparator interface contains the following two methods,

  • compare()
  • equals()

Discuss this Question


56. Which of the following statements is not correct for vectors in Java?

  1. It was created using vector keyword
  2. It can store an object of different classes
  3. It is asynchronous
  4. None of these

Answer: C) It is asynchronous

Explanation:

Read more: Vector Class in Java

Discuss this Question


57. What will be the output of following Java code?

public class Main {
  public static void main(String[] args) {
    StringBuffer sb = new StringBuffer("include");
    sb.append("help");
    System.out.println(sb);
  }
}
  1. Error
  2. include
  3. help
  4. Includehelp

Answer: D) Includehelp

Explanation:

The string here is a StringBuffer hence the contents can be edited which makes the append method work on it by adding 'help' to the end of the string.

Discuss this Question


58. What is a deadlock in Java?

  1. State when all processes have complete working and are dead
  2. State when threads are in hold state forever
  3. State when threads are not ready
  4. All of these

Answer: B) State when threads are in hold state forever

Explanation:

Deadlock in Java is a condition when two or more threads try to access the same resources at the same time.

Discuss this Question


59. Which graph is used to check for deadlock in Java?

  1. Deadlock graph
  2. Time graph
  3. Wait-for-graph
  4. None of these

Answer: C) Wait-for-graph

Explanation:

The wait-for-graph is used to check for deadlock in Java.

Discuss this Question


60. Batch processing in java is ___.

  1. Used to execute a group of queries or a batch as executing a single query, again and again, is time taking and reduce the performance
  2. Used to processing multiple queries can be executed at once
  3. Used to increase program's performance
  4. All of these

Answer: D) All of these

Explanation:

Read more: Batch Processing in Java.

Discuss this Question


61. Null in Java is ___.

  1. Reserved keyword
  2. Literal value
  3. Used in exception handling
  4. All of these

Answer: D) All of these

Explanation:

All of the mentioned points are true about the Null in Java.

Discuss this Question


62. Enumeration in Java is ___.

  1. Data type which contains fixed set of constants
  2. Method
  3. Class
  4. None of these

Answer: A) Data type which contains fixed set of constants

Explanation:

In Java, the Enumeration is a data type which contains a fixed set of constants, they are used to create our own data type like classes.

Discuss this Question


63. Can we pass objects to method arguments in Java?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

We use call-by-reference to pass objects as arguments to methods in java. Read more: Object as an Argument in Java

Discuss this Question


64. Which of the following ways is the correct way to create an object in Java?

  1. Using the new keyword
  2. Using newInstance() method
  3. clone() method
  4. All of these

Answer: D) All of these

Explanation:

All of the above-mentioned ways are the correct way to create an object Java.

There are five different ways to create an object and we will see the ways to create an object given below:

  1. Using the new keyword
  2. Using newInstance() method of Class
  3. Using clone() method
  4. Using newInstance() method of Constructor class
  5. Using deserialization

Read more: Different ways to create an object in Java

Discuss this Question


65. Which statement is correct for private member in Java?

  1. Access outside the class is allowed
  2. Any class can access
  3. Declared using private keyword
  4. All of these

Answer: C) Declared using private keyword

Explanation:

The private members are declared using the private keyword.

Discuss this Question


66. Which keyword is used to inherit classes in Java?

  1. extends
  2. inheritance
  3. isChild
  4. None of these

Answer: A) extends

Explanation:

The extends keyword is used to inherit classes in Java.

Discuss this Question


67. Which of the following inheritance of class is invalid in Java?

  1. Single
  2. Multiple
  3. Multi-level
  4. Hierarchical

Answer: B) Multiple

Explanation:

Java doesn't allow multiple inheritance.

Discuss this Question


68. The 'implements' keyword is used to ___.

  1. Implement the function of a class
  2. Inherit an interface in Java
  3. Inherit a class in java
  4. All of these

Answer: B) Inherit an interface in Java

Explanation:

The implements keyword is used to inherit an interface in Java.

Discuss this Question


69. What is polymorphism in Java?

  1. Performing a single task in multiple ways
  2. Performing multiple tasks using multiple methods
  3. Creating a new class for each task
  4. All of these

Answer: A) Performing a single task in multiple ways

Explanation:

Polymorphism in Java is the ability of an object to take many forms.

Discuss this Question


70. What are packages in Java?

  1. Methods of a friend class
  2. Methods of the main class
  3. Way to encapsulate a group of classes, sub-packages, and interface
  4. All of these

Answer: C) Way to encapsulate a group of classes, sub-packages, and interface

Explanation:

Java packages are the ways to encapsulate a group of classes, sub-packages, and interface.

Discuss this Question


71. Empty interface in Java is called?

  1. Marker interface
  2. Abstract class
  3. Derived class
  4. None of these

Answer: A) Marker interface

Explanation:

Empty interface is called Marker interface in Java.

Discuss this Question


72. Which of these is a non-access modifier?

  1. public
  2. private
  3. native
  4. All of these

Answer: C) native

Explanation:

The native is a non-access modifier in Java.

Discuss this Question


73. When a finally block executed in Java?

  1. Try block is executed without any exception
  2. Exception has occurred
  3. Executed at last
  4. None of these

Answer: C) Executed at last

Explanation:

Finally block is executed at the last.

Discuss this Question


74. What is boolean in Java?

  1. A value consisting of only true and false value
  2. A value consisting of 8 values
  3. Truthy value in java
  4. All of these

Answer: A) A value consisting of only true and false value

Explanation:

In Java, the boolean keyword is a primitive data type. It is used to store only two possible values, either true or false.

Discuss this Question


75. Which of these is not a valid Boolean method in Java?

  1. equals() method
  2. hashCode() method
  3. toString() method
  4. All of these

Answer: D) All of these

Explanation:

All are valid Boolean class methods. Some common methods are equals(), hashCode(), toString(), valueOf(), etc.

Discuss this Question


76. Which method in Java is used to check for NaN values?

  1. isNan()
  2. checkNan()
  3. isNotNan()
  4. All of these

Answer: A) isNan()

Explanation:

The isNaN() method is used to check for NaN values.

Discuss this Question


77. Which of these is a property of threads in Java?

  1. Multiple threads can be executed concurrently
  2. Has its own priority
  3. Both A. and B.
  4. None of these

Answer: C) Both A. and B.

Explanation:

The multiple threads can be executed concurrently and it has own property.

Discuss this Question


78. Which thread is executed in the background?

  1. New thread
  2. User-created thread
  3. Daemon thread
  4. All of these

Answer: C) Daemon thread

Explanation:

The daemon thread is executed in the background.

Discuss this Question


79. Multithreading in java is ___.

  1. Executing multiple processes simultaneously
  2. Creating more threads at a time
  3. Blocking threads
  4. All of these

Answer: A) Executing multiple processes simultaneously

Explanation:

Multithreaded programming a process in which two or more parts of the same process run simultaneously.

Discuss this Question


80. What will be the output of following Java code?

public class Main {
  public static void main(String[] args) {
    System.out.println(Math.copySign(100.6, -200.6));
  }
}
  1. 100.6
  2. -100.6
  3. -200.6
  4. 200.6

Answer: B) -100.6

Explanation:

The Math.copySign() returns the first floating-point argument with the sign of the second floating-point argument.

Discuss this Question


81. Which method is used to convert radians to degree in Java?

  1. convertRadtoDeg()
  2. toDegrees()
  3. degree()
  4. All of these

Answer: B) toDegrees()

Explanation:

The Java method toDegrees() is used to convert radians to degree.

Discuss this Question


82. Which of the following methods is used to extract the length of a string in Java?

  1. length()
  2. len()
  3. sizeof()
  4. size()

Answer: A) length()

Explanation:

The Java method length() is used to extract the length of a string in Java.

Discuss this Question


83. The trim() method in Java used to ___.

  1. Remove the given character
  2. Remove the values after the given index
  3. Remove leading and trailing spaces
  4. None of these

Answer: C) Remove leading and trailing spaces

Explanation:

The Java method trim() is a built-in function that eliminates leading and trailing spaces.

Discuss this Question


84. What are regexes in Java?

  1. API to define a pattern for searching strings
  2. String
  3. Array to create a new integer
  4. Wrapper class

Answer: A) API to define a pattern for searching strings

Explanation:

Java Regular Expressions or Regex is an API for defining String patterns that can be used for searching, manipulating, and editing a string.

Discuss this Question


85. What is a map in Java?

  1. Data structure
  2. Defined in java.util package
  3. Represented using key-value pairs
  4. All of these

Answer: D) All of these

Explanation:

Read more: Differences between Set and Map interface in Java.

Discuss this Question


86. What is a set in Java?

  1. Represented in the form of values
  2. Used to store key-value pairs
  3. Primary structures
  4. All of these

Answer: A) Represented in the form of values

Explanation:

Read more: Differences between Set and Map interface in Java

Discuss this Question


87. What will be the output of following Java code?

import java.util.Hashtable;

public class HashTableClass {
  int hashcode;
  HashTableClass(int hashcode) {
    this.hashcode = hashcode;
  }
  public int hashCode() {
    return hashcode;
  }
  public String toString() {
    return hashcode + " ";
  }

  public static void main(String[] args) {
    Hashtable ht = new Hashtable();
    
    ht.put(new HashTableClass(10), "Java");
    ht.put(new HashTableClass(3), "C");
    ht.put(new HashTableClass(4), "C++");
    ht.put(new HashTableClass(5), "Ruby");
    ht.put(new HashTableClass(6), "null");
    
    System.out.println(ht);
  }
}
  1. {10 =Java, 3 =C, 4 =C++, 6 =null, 5 =Ruby}
  2. {10 =Java, 6 =null, 5 =Ruby, 4 =C++, 3 =C}
  3. {3 =C, 4 =C++, 5 =Ruby, 6 =null, 10 =Java}
  4. None of these

Answer: B) {10 =Java, 6 =null, 5 =Ruby, 4 =C++, 3 =C}

Discuss this Question


88. Which of the following sorts the elements were inserted?

  1. Hashtable
  2. Map
  3. Array
  4. None of these

Answer: A) Hashtable

Explanation:

Hashtable sorts the elements were inserted.

Discuss this Question


89. Which Java method is used to clear element of ArrayList?

  1. deleteAll()
  2. delete()
  3. clearAll()
  4. clear()

Answer: D) clear()

Explanation:

The clear() method of ArrayList in Java is used to remove all the elements from a list.

Discuss this Question


90. Which Java method is used to add all of the specified elements to the specified collection?

  1. addValue()
  2. copy()
  3. cpy()
  4. addAll()

Answer: D) addAll()

Explanation:

The addAll() method of java.util.Collections class is used to add all of the specified elements to the specified collection.

Discuss this Question


91. Which Java method is used to detect the OS in which Java program is being run?

  1. system.getOSdetails()
  2. system.get(os.name)
  3. system.getProperties("os.name")
  4. system.getProperties("os")

Answer: C) system.getProperties("os.name")

Explanation:

The Java method system.getProperties("os.name") is used to detect the OS in which Java program being run.

Discuss this Question


92. What is the default encoding of OutstreamWriter?

  1. UTF-32
  2. UTF-16
  3. UTF-12
  4. Based on the host platform

Answer: D) Based on the host platform

Explanation:

The encoding of OutstreamWriter is based on the host platform.

Discuss this Question


93. Which method in java is used to get the name of running java VM?

  1. System.getProperties("java.vm.name")
  2. System.vmName
  3. Sytem.getVmName
  4. System.getProperties("vm.name")

Answer: A) System.getProperties("java.vm.name")

Explanation:

The Java method System.getProperties("java.vm.name") is used to get the name of the running Java VM.

Discuss this Question


94. Which Java method is used to get the version of running java VM?

  1. System.vm.version
  2. System.getProperties("vm.version")
  3. System.getProperties("java.vm.version")
  4. System.getVmVersion

Answer: C) System.getProperties("java.vm.version")

Explanation:

The Java method System.getProperties("java.vm.version") is used to get the versions of the running Java VM.

Discuss this Question


95. What is the full form of AWT?

  1. Absolute window toolKit
  2. Abstract window toolKit
  3. Absolute wear kit
  4. Abstract window tools

Answer: B) Abstract window toolKit

Explanation:

The full form of AWT is "Abstract window toolKit".

Discuss this Question


96. Which escape character is used for word character in regex?

  1. /w
  2. /c
  3. /str
  4. /?

Answer: A) /w

Explanation:

The escape character /w is used for word character in Regex.

Discuss this Question


97. Jar in java stands for ___.

  1. Java ARchive
  2. Java application runtime
  3. Java application runner
  4. None of these

Answer: A) Java ARchive

Explanation:

Jar stands for "Java ARchive".

Discuss this Question


98. Which Java keyword is used to access features of a package?

  1. get
  2. import
  3. extends
  4. All of these

Answer: B) import

Explanation:

The import keyword is used to access features of a package.

Discuss this Question


99. The result of dividing by 0 in Java is ___.

  1. Error
  2. Expectation
  3. Infinite
  4. None of these

Answer: B) Expectation

Explanation:

Dividing an integer by zero will result in an ArithmeticException.

Discuss this Question


100. What will be the output of following Java code?

public class ConcatNull {
  public static void main(String[] args) {
    String str1 = "include";
    String str2 = "help";
    System.out.println(str1 + str2);
  }
}
  1. includehelp
  2. include
  3. help
  4. None of these

Answer: A) includehelp

Explanation:

In the above code, the "+" operator is concatenating both of the strings.

Discuss this Question




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.