Home »
MCQs
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 ____.
- Java development kit
- Java deployment kit
- JavaScript deployment kit
- 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 ___.
- Java run ecosystem
- JDK runtime Environment
- Java Runtime Environment
- 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?
- Advanced programming language
- It uses bytecode for execution
- Class compilation
- 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?
- Yes
- 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?
- Heap memory
- Stack memory
- Both A and B
- 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 ___.
- //
- /* */
- <!-- -- >
- 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?
- main() method
- The first line of code
- Last line of code
- 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?
- Yes
- 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?
- Yes
- 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?
- exep
- excepHand
- throw
- 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?
- Scanner
- Input
- Applier
- 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?
- next()
- nextLine()
- Both A. and B.
- 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?
- var name;
- int name;
- var name int;
- All of these
Answer: B) int name;
Explanation:
Read here: Java variable declarations
Discuss this Question
14. Is string mutable in Java?
- Yes
- 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?
- Instance Variable
- Local Variable
- Static Variable
- All of these
Answer: D) All of these
Explanation:
There are three types of variables in Java:
- Instance variable
- Local variable
- 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);
}
}
- Hello
- Bye
- Error
- All of these
Answer: B) Bye
Discuss this Question
17. What is type casting in Java?
- It is converting type of a variable from one type to another
- Casting variable to the class
- Creating a new variable
- 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?
- Widening typecasting
- Narrowing typecasting
- Manual typecasting
- 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?
- Class
- Method
- Variable
- 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?
- Try-catch block
- Class block
- Method block
- 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 ___.
- Terminates from the loop immediately
- Terminates from the program immediately
- Skips the current iteration
- 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
- No output
- 8
- 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?
- Yes, using command-line arguments
- Yes, by access command prompt
- No
- 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 ___.
- Collection of similar elements
- Collection of elements of different types
- The data type of consisting of characters
- 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?
- int[] arr = {1, 3, 5};
- int[] arr;
- arr = new int[] {3, 1, 8};
- int arr[] = {1, 4, 6};
- 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 ___.
- Classes
- References
- Iterators
- None of these
Answer: B) References
Explanation:
Objects in Java are Reference Variables.
Discuss this Question
27. What is garbage collection in java?
- Method to manage memory in java
- Create new garbage values
- Delete all values
- 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 ___.
- final variables
- new variables
- Constants
- 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 ___.
- Store very long range of number
- Store integer values
- A class that stores large range of integer
- 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 ___.
- Used to hold the reference of the current object
- Holds object value
- Used to create a new instance
- 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);
}
}
- 5
- 9
- 8
- 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 ___.
- Access instance of the parent class
- Access instance of the same class
- Access instance of child class
- 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 ___.
- Call constructor of friend class
- Is a declared method
- Call constructor of the parent class
- 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 ___.
- Used to encapsulate primitive data types
- Declare new classes called wrapper
- Create a new instance of the class
- 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 ___.
- Creating new box
- Creating object
- Converting primitive type of object instance
- 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 ___.
- Created using abstract keyword
- Contains only abstract method
- Needs to be inherited to be used
- 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?
- It is creating, deleting, and modifying files using a java program.
- Creating new method
- Filing method to different file to extract them better
- 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?
- Java.files
- Java.io
- Java.io.File
- 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?
- C:\Program Files\Java\jdk1.8.0_131\bin\file_name.txt
- C:\Program Files\Java\file_name.txt
- C:\Program Files\Java\jdk1.8.0_131\file_name.txt
- 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?
- file.addLine()
- file.nextLine()
- file.write()
- 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?
- file.delete()
- file.remove()
- file.garbage()
- 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?
- file.read()
- file.nextLine()
- file.getLine()
- 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 ___.
- import java.lang.math
- import math
- import java.math
- 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?
- max()
- cbrt()
- log10()
- 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?
- random.nextInt()
- random()
- rand()
- 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 ___.
- Method
- A process allowing methods to call itself
- The process to call methods
- 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?
- Class to create a string array
- Class to create a mutable string in java
- Class to create a string from i/o buffer
- 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?
- Array
- List
- Vector
- 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?
- Vector < string > names = new Vector < String > ();
- Vector name = new string;
- int name = new vector ()
- 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);
}
}
- Error
- 8
- 5
- 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?
- The keyword interface is used to create a method
- All the methods of an interface are abstract
- It does not contain constructors
- 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 ___.
- Wrapping up of data and related functions into a single entity
- Creating special methods
- Creating special data structure
- 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?
- createString()
- toString()
- object.string()
- 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?
- Interface to compare integer
- Comparison method for lists
- Interface to compare two objects in java
- 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?
- compare()
- equate()
- isEqual()
- All of these
Answer: A) compare()
Explanation:
The comparator interface contains the following two methods,
Discuss this Question
56. Which of the following statements is not correct for vectors in Java?
- It was created using vector keyword
- It can store an object of different classes
- It is asynchronous
- 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);
}
}
- Error
- include
- help
- 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?
- State when all processes have complete working and are dead
- State when threads are in hold state forever
- State when threads are not ready
- 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?
- Deadlock graph
- Time graph
- Wait-for-graph
- 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 ___.
- 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
- Used to processing multiple queries can be executed at once
- Used to increase program's performance
- All of these
Answer: D) All of these
Explanation:
Read more: Batch Processing in Java.
Discuss this Question
61. Null in Java is ___.
- Reserved keyword
- Literal value
- Used in exception handling
- 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 ___.
- Data type which contains fixed set of constants
- Method
- Class
- 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?
- Yes
- 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?
- Using the new keyword
- Using newInstance() method
- clone() method
- 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:
- Using the new keyword
- Using newInstance() method of Class
- Using clone() method
- Using newInstance() method of Constructor class
- 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?
- Access outside the class is allowed
- Any class can access
- Declared using private keyword
- 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?
- extends
- inheritance
- isChild
- 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?
- Single
- Multiple
- Multi-level
- Hierarchical
Answer: B) Multiple
Explanation:
Java doesn't allow multiple inheritance.
Discuss this Question
68. The 'implements' keyword is used to ___.
- Implement the function of a class
- Inherit an interface in Java
- Inherit a class in java
- 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?
- Performing a single task in multiple ways
- Performing multiple tasks using multiple methods
- Creating a new class for each task
- 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?
- Methods of a friend class
- Methods of the main class
- Way to encapsulate a group of classes, sub-packages, and interface
- 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?
- Marker interface
- Abstract class
- Derived class
- 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?
- public
- private
- native
- 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?
- Try block is executed without any exception
- Exception has occurred
- Executed at last
- 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?
- A value consisting of only true and false value
- A value consisting of 8 values
- Truthy value in java
- 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?
- equals() method
- hashCode() method
- toString() method
- 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?
- isNan()
- checkNan()
- isNotNan()
- 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?
- Multiple threads can be executed concurrently
- Has its own priority
- Both A. and B.
- 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?
- New thread
- User-created thread
- Daemon thread
- All of these
Answer: C) Daemon thread
Explanation:
The daemon thread is executed in the background.
Discuss this Question
79. Multithreading in java is ___.
- Executing multiple processes simultaneously
- Creating more threads at a time
- Blocking threads
- 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));
}
}
- 100.6
- -100.6
- -200.6
- 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?
- convertRadtoDeg()
- toDegrees()
- degree()
- 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?
- length()
- len()
- sizeof()
- 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 ___.
- Remove the given character
- Remove the values after the given index
- Remove leading and trailing spaces
- 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?
- API to define a pattern for searching strings
- String
- Array to create a new integer
- 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?
- Data structure
- Defined in java.util package
- Represented using key-value pairs
- 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?
- Represented in the form of values
- Used to store key-value pairs
- Primary structures
- 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);
}
}
- {10 =Java, 3 =C, 4 =C++, 6 =null, 5 =Ruby}
- {10 =Java, 6 =null, 5 =Ruby, 4 =C++, 3 =C}
- {3 =C, 4 =C++, 5 =Ruby, 6 =null, 10 =Java}
- 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?
- Hashtable
- Map
- Array
- 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?
- deleteAll()
- delete()
- clearAll()
- 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?
- addValue()
- copy()
- cpy()
- 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?
- system.getOSdetails()
- system.get(os.name)
- system.getProperties("os.name")
- 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?
- UTF-32
- UTF-16
- UTF-12
- 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?
- System.getProperties("java.vm.name")
- System.vmName
- Sytem.getVmName
- 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?
- System.vm.version
- System.getProperties("vm.version")
- System.getProperties("java.vm.version")
- 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?
- Absolute window toolKit
- Abstract window toolKit
- Absolute wear kit
- 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?
- /w
- /c
- /str
- /?
Answer: A) /w
Explanation:
The escape character /w is used for word character in Regex.
Discuss this Question
97. Jar in java stands for ___.
- Java ARchive
- Java application runtime
- Java application runner
- 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?
- get
- import
- extends
- 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 ___.
- Error
- Expectation
- Infinite
- 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);
}
}
- includehelp
- include
- help
- None of these
Answer: A) includehelp
Explanation:
In the above code, the "+" operator is concatenating both of the strings.
Discuss this Question