James Gosling developed JAVA at Sun Microsystems in May 1995. The main purpose of the JAVA programming language is to provide programmers with one-time write and run, anywhere functionality. The compiled Java code can be run on any platform that supports Java without recompiling.
The importance of JAVA are:
- Develop applications and platforms for a variety of devices such as computers, laptops, game consoles, Blu-ray players, car navigation systems, medical monitors, parking meters, lottery terminals, smartphones, etc.
- It is also an important language for networks, especially data centers that store and send web-based data.
- Java is also used to create dynamic miniature programs that run with or embed web pages.
MCQs on Java Programming
Practise Java MCQ questions to prepare better for your GATE exam. We also advise all the aspirants to practise question papers from previous years to understand the Java MCQ questions and their patterns. Meanwhile, check out a list of questions that will help you practise it:
Java MCQ Questions
1. Which of these components are used in a Java program for compilation, debugging, and execution?
Answer: (a) JDK
2. Which of these literals can be contained in a float data type variable?
Answer: (b) -3.4e+038
3. What is BigDecimal.ONE?
a. it is a custom-defined statement
b. it is a wrong statement
c. it is a static variable that has a value of 1 on a scale of 0
d. it is a static variable that has a value of 1 on a scale of 10
Answer: (c) it is a static variable that has a value of 1 on a scale of 0
4. When an expression consists of int, double, long, float, then the entire expression will get promoted into a data type that is:
Answer: (b) double
5. Which of the following operators can operate on a boolean variable?
a) C & B
b) A & D
c) A, B & D
d) A, B & C
Answer: (d) A, B & C
6. Out of these statements, which ones are incorrect?
a. The Brackets () have the highest precedence
b. The equal to = operator has the lowest precedence
c. The addition operator + and the subtraction operator – have an equal precedence
d. The division operator / has comparatively higher precedence as compared to a multiplication operator
Answer: (d) The division operator / has comparatively higher precedence as compared to a multiplication operator
7. What will be the output of the following Java program?
public static void main(String args)
int p = 1;
int q = 2;
int r = 3;
p |= 4;
q >>= 1;
r <<= 1;
p ^= r;
System.out.println(q + ” ” + q + ” ” + r);
a. 3 3 6
b. 2 3 4
c. 2 2 3
d. 3 1 6
Answer: (d) 3 1 6
8. What will be the output of the following Java code snippet?
enum Enums extends P
PQR, QRS, RST, STU;
a) Compilation Error
b) Runtime Error
c) EnumNotDefined Exception
d) It runs successfully
Answer: (a) Compilation Error
9. When does Overloading not occur?
a. When more than a single method have the same name, yet different types or number of parameters and different method signature
b. When more than a single method have the same name, the same signature, but have different numbers of signature
c. When more than a single method have the same signature, same name, and the same number of parameters have different types
d. When more than a single method have the same name, the same number and types of parameters, and yet different signatures
Answer: (d) When more than a single method have the same name, the same number and types of parameters, and yet different signatures
10. What is it called when the child object also gets killed when the parent object is killed in the program?
Answer: (d) Composition
11. How does one identify if a compilation unit is an interface or class from a .class file?
a. Extension of the compilation unit
b. Java source file header
c. The class and interface cannot be differentiated
d. The unit type must be used to postfix interface or class name
Answer: (b) Java source file header
12. Out of these methods of the String class, which one can be used for testing the strings for equality?
Answer: (c) equals()
13. What would happen to the thread whenever the garbage collection kicks off?
a. The garbage collection won’t happen until the running of the thread
b. The thread would continue its operation
c. The garbage collection and the thread don’t interfere with each other
d. The thread would be paused while the running of the garbage collection
Answer: (d) The thread would be paused while the running of the garbage collection
14. Out of these, which one is the correct way of calling a constructor that has no parameters of the superclass A by the subclass B?
Answer: (c) super();
15. Out of these methods of the Object class, which one can clone an object?
a. Object clone()
c. Object copy()
Answer: (a) Object clone()
16. Out of these packages, which one contains an abstract keyword?
Answer: (b) java.lang
17. Out of these methods, which one can be used for converting all the characters present in a String into an Array of characters?
a. both getChars() & toCharArray()
b. both charAt() & getChars()
d. all of the mentioned
Answer: (a) both getChars() & toCharArray()
18. What value is returned by the compareTo() function in case the invoking string happens to be greater than the compared string?
a. a value that is greater than zero
b. a value that is less than zero
d. none of the above
Answer: (a) a value that is greater than zero
19. Out of these exceptions, which one is thrown by the compareTo() method that is defined in a double wrapper?
Answer: (b) ClassCastException
20. Where does the String Pool get stored?
b. Java Stack
c. Java Heap
d. Permanent Generation
Answer: (c) Java Heap
21. Out of these data members of the HttpResponse class, which one is used for the storage of the response that is from an http server?
Answer: (c) statusCode
22. Out of these methods, which one makes the raw MIME formatted string?
Answer: (c) parse()
23. The remover() method throws which of these exceptions:
Answer: (b) IllegalStateException
24. Out of the following, which one is a superclass of all the exception type classes?
Answer: (d) Throwable
25. What happens when we call two threads that have the same priority to process simultaneously?
a. Both of the threads will be simultaneouslyexecuted
b. Any one of the threads can be executed first lexicographically
c. Itdepends on the OS
d. There will be no execution of threads
Answer: (c) Itdepends on the OS
26. Out of these classes, which one is used for reading strings and characters in Java from the console?
Answer: (b) BufferedReader
27. Out of these operators, which one can be used to get the run time info about an object?
Answer: (d) instanceof
28. Out of these classes, which one allows a user to define their own formatting pattern for time and dates?
Answer: (c) SimpleDateFormat
29. Which method can we use in an applet to output a string?
Answer: (b) drawString()
30. The public int start() returns what?
a. the start index of the previous match
b. the start index of the current match
c. the start index of the input string
d. None of the above
Answer: (a) the start index of the previous match
31. Which one is a superclass of the ContainerEvent class out of the following?
Answer: (a) ComponentEvent
32. _______ is a superclass of all the Adapter classes.
Answer: (b) Applet
33. Which method in Java generates boolean random values?
Answer: (b) nextBoolean()
34. Which class produces objects with respect to their geographical locations?
a. Simple TimeZone
Answer: (c) Locale
35. Which method is used for notifying the observer about the change in the observed object?
Answer: (b) update()
36. Which package is used to remotely invoke a method?
Answer: (b) java.rmi
37. What are the uses of generics?
a. The generics make a code more readable and optimised
b. The generics make a code faster
c. The generics add stability to a code. They do so by making more bugs detectable at the runtime
d. The generics add stability to a code. They do so by making more bugs detectable at the compile time
Answer: (d) The generics add stability to a code. They do so by making more bugs detectable at the compile time
38. Which mechanism helps in the process of naming as well as visibility control of the classes and their content?
d. None of the above
Answer: (a) Packages
39. The configuration is stored in which of the file database tables:
Answer: (c) .hbm
40. The primary use of Files.lines(Path path) is that it:
a. reads the lines that are from a file as the Stream
b. reads the files that are at the path specified as the String
c. counts the total number of lines for the files at the specified path
d. reads the filenames at the specified path
Answer: (a) reads the lines that are from a file as the Stream
41. Which keywords for the purpose of upper bound a wildcard?
Answer: (d) extends
42. Out of the following statements, which one is not true about the Java beans?
a. It extends the java.io.Serializable class
b. It implements the java.io.Serializable interface
c. It provides getter and setter methods for its properties
d. It provides us with no argument constructor
Answer: (a) It extends the java.io.Serializable class
43. What does the abbreviation MVC pattern stand for?
a. Model View Class
b. Mock View Class
c. Mock View Controller
d. Model View Control
Answer: (d) Model View Control
44. The advantage of using the PreparedStatement in Java is:
a. More memory usage
b. Prevents SQL injection
c. Encourages SQL injection
d. Slow performance
Answer: (b) Prevents SQL injection
45. How does one move from some desired step to another one?
Answer: (d) breakpoints
46. What would happen if the IP Address of the host can’t be determined?
a) IOException is thrown
b) The system will exit with no message
c) Temporary IP Address will be assigned
d) UnknownHostException is thrown
Answer: (d) UnknownHostException is thrown
47. The storage capacity of a single cookie is:
a) 4095 MegaBytes
b) 4095 bytes
c) 2048 bytes
d) 2048 MegaBytes
Answer: (b) 4095 bytes
48. Which action variable helps in including a file in the JSP?
Answer: (b) jsp:include
49. ______ file defines dependency in maven.
Answer: (d) pom.xml
50. The main difference between AutoCloseable and Closeable is that:
a) AutoCloseable throws IOException; Closeable throws Exception
b) AutoCloseable is an implementation; Closeable is a concept
c) AutoCloseable throws Exception; Closeable throws IOException
d) AutoCloseable is a concrete class and Closeable is an interface
Answer: (c) AutoCloseable throws Exception; Closeable throws IOException
Keep learning and stay tuned to get the latest updates on the GATE Exam along with Eligibility Criteria, GATE Syllabus for CSE (Computer Science Engineering), GATE CSE Notes, GATE CSE Question Paper, and more.