Home

UPSC IES - Java Programming 1000+ MCQ [Solved] PDF Download

Thursday 9th of March 2023

Sharing is caring

1. Give file is a file object, which of the following are legal statements to create a new file.
A. file.create();
B. FileOutputStream fos=new FileOutputStream(file);
C. FileInputStream fis=new FileInputStream(file);
D. all of the above
Answer : B
2. Any method in a supper class can be over ridden in its subclass.
A. True
B. False
C.
D.
Answer : B
3. DataInput is
A. An abstract class defined is java.io.
B. A class we can use to read primitive data types.
C. An interface that defines methods to open files.
D. An interface that defines methods to read primitive data types.
Answer : D
4. Java is fully object oriented programme.
A. true
B. false
C.
D.
Answer : A
5. Which key word can protect a class in package from accessibility by the classes outside the package?
A. private
B. protected
C. final
D. don't use any keyword at all(make it default)
Answer : D
6. Which are the valid ways to create DataInputStream streams?
A. new DataInputStream(new File("in.dat"));
B. new DataInputStream(new FileInputStream("in.dat"));
C. new DataInputStream("in.dat");
D. new DataInputStream("in.data","r");
Answer : B
7. The name of a Java program file must match the name of the class with the extension Java.
A. True
B. False
C.
D.
Answer : A
8. Which of the following methods belong to the String class?
A. length()
B. compareTo()
C. substring()
D. all of the them
Answer : D
9. executeUpdate automatically updates data because___________
A. auto commit is on, by default
B. It performs a hidden commit statement as well
C. Does not commit
D. None of the above.
Answer : A
10. Every call to wait has a corresponding call to notify that will eventually end the wafting.
A. True
B. False
C.
D.
Answer : A
11. A Java monitor must either extend thread class or implement Runnable interface.
A. True
B. False
C.
D.
Answer : B
12. We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?
A. private
B. protected
C. public
D. private protected
Answer : D
13. Session bean
A. Represents a single client inside the application server
B. Can not be shared
C. Is not persistent
D. Satisfies all of the above conditions
Answer : D
14. Connection, Statement are interfaces and ResultSet is a class.
A. True.
B. False.
C.
D.
Answer : B
15. For all insert, update, delete, query operations on a database, ResultSet object creation is mandatory.
A. True.
B. False.
C.
D.
Answer : B
16. With javadoc, which of the following denotes a javadoc comment?
A. //#
B. /*
C. /**
D. //**
Answer : C
17. Java always provides a default constructor to a class.
A. True
B. False
C.
D.
Answer : B
18. When we implement the Runnable interface, we must define the method
A. start()
B. init()
C. runnable()
D. run()
Answer : D
19. Message-Driven beans act as a listener for the Java Message Service API, processing messages synchronously
A. True
B. False
C.
D.
Answer : B
20. putValue(...) method takes _____________________-
A. Two arguments of object type
B. First one is of a character type and second one is of an object type
C. First one is of an object type and second one is of a character type
D. None of the above.
Answer : A
21. To delete a file, we can use an instance of class file.
A. True
B. False
C.
D.
Answer : A
22. The import statement is always the first no comment statement in a Java program files.
A. True
B. False
C.
D.
Answer : B
23. Which of the following methods can be used to remove a component from the display?
A. remove()
B. desappear()
C. hide()
D. move()
Answer : C
24. Which of the following will produce a value of 22 if x=22.9:
A. Ceil(x)
B. Round(x)
C. Rint(x)
D. Abs(x)
Answer : C
25. It is an error if a class with one or more abstract methods is not explicitly declared abstract.
A. True
B. False
C.
D.
Answer : A
26. What is java -g used for?
A. Using the jdb tool
B. Executing a class with optimization turned off
C. To provided information about deprecated methods
D. Non of the above
Answer : B
27. Two methods cannot have the same name in Java.
A. True
B. False
C.
D.
Answer : B
28. It is an error to catch the same type of exception in two different catch blocks associated with a particular try block.
A. True
B. False
C.
D.
Answer : A
29. Objects are passed to a method by use of call-by-reference.
A. True
B. False
C.
D.
Answer : A
30. What is error in the following class definitions? 
abstract class xy { 
abstract sum(int x, int y) {
}
}

A. class header is not define properly
B. constructor is no defined
C. method is not defined properly
D. no error
Answer : C
31. In order to connect to a database through java program we must create _______-
A. Connection, Statement, ResultSet
B. Connection, ResultSet
C. Statement< ResultSet
D. Connection, Statement
Answer : D
32. All methods in an abstract class must be declared abstract.
A. True
B. False
C.
D.
Answer : B
33. What is wrong in the following class definitions? 
abstract class print { 
abstract show();
}
class Display extends print {
}

A. Nothing is wrong
B. Wrong Method show() should have a return type
C. Wrong Methods show() is not implemented in Display
D. Wrong Display does not contain any members.
Answer : C
34. Servlet has ___________
A. init method
B. doGet(------) method
C. All of the above methods.
D.
Answer : C
35. Which of the following statements are valid array declarations?
A. int number();
B. float average[];
C. double[] marks;
D. counter int[];
Answer : B
36. A panel can not be added to another panel.
A. True
B. False
C.
D.
Answer : B
37. If you want to assign a value of 99 to the variable year, then which of the following lines can be used within an <applet> tags?
A. number=getParameter(99)
B. <number==99>
C. D. <param = radius value ==99>
Answer : C
38. When we implement an interface method, it should be declared as public.
A. True
B. False
C.
D.
Answer : A
39. We can add more than one class(es) at the time of compilation Java Beans.
A. True.
B. False.
C.
D.
Answer : A
40. The keywords reserved but not used in the initial version of Java re:
A. Synchronized
B. Boolean
C. union
D. goto
Answer : D
41. Submit button always fires doPost(...)
A. True
B. False
C.
D.
Answer : B
42. The methods wait() and noify() are defined in
A. java.lang.Thread
B. java.lang.Runnable
C. java.lang.Object
D. java.lang.ThreadGroup
Answer : C
43. Consider the following class definitions:
 class maths { 
student student1;
}
class student {
String name;
}

This code represents:


A. an 'is a' relationship
B. a 'has a' relationship
C. both
D. neither
Answer : B
44. Consider the following class definition.
Class Student extends String
{
}
What happens when we try to compile this class?

A. Will not compile because class body is not defined
B. Will not compile because class is not declared public
C. Will compile successfully.
D. Will not compile because String is abstract
Answer : D
45. Consider the following statements:
int x = 10, y = 15; 
x = ((x < y) ? (y + x) : (y - x);

What will be the value of x after executing these statements?

A. 25
B. 15
C. 5
D. Error can't be executed.
Answer : A
46. A JSP file can be stored_________________
A. With the extension .jsp in servlets folder of the jws
B. With the extension .html in public_html folder of the jws
C. With the extension .jsp in public_html folder of the jws
D. None of the above.
Answer : C
47. When the string objects are compared with ==, the result is true If the strings contain the same values.
A. True
B. False
C.
D.
Answer : B
48. Which of the following keywords are used to control access to a class member?
A. default
B. protected
C. interface
D. None of the above
Answer : B
49. A variable declared inside the for loop control can not be referenced out side the loop.
A. True
B. False
C.
D.
Answer : A
50. Which of the following command lines options generates documentation for all classes and methods?
A. -protected
B. -public
C. -private
D. -encoding
Answer : C

Sharing is caring