0% found this document useful (0 votes)
4 views10 pages

2211520100

The document consists of a series of multiple-choice questions and answers related to Java programming concepts, including AWT, exception handling, data types, and object-oriented principles. It covers various topics such as Java's platform independence, memory management, and GUI components. Each question is followed by the correct answer, providing a comprehensive overview of fundamental Java knowledge.

Uploaded by

uit95a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

2211520100

The document consists of a series of multiple-choice questions and answers related to Java programming concepts, including AWT, exception handling, data types, and object-oriented principles. It covers various topics such as Java's platform independence, memory management, and GUI components. Each question is followed by the correct answer, providing a comprehensive overview of fundamental Java knowledge.

Uploaded by

uit95a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

For Enrollment 2211520100

1. Which of these methods is a part of Abstract Window Toolkit (AWT)?


Option a) display()
Option b) print()
Option c) drawString()
Option d) transient()
Ans: c) drawString()

2. Which of these operators can be used to get run-time information about an object?
Option a) getInfo
Option b) Info
Option c) instanceof
Option d) getinfoof
Ans: c) instanceof

3. Which of these packages is used for handling security-related issues in a program?


Option a) java.security
Option b) java.lang.security
Option c) java.awt.image
Option d) java.io.security
Ans: a) java.security

4. The order of the three top-level elements of the Java source file are___
Option a) Import, Package, Class
Option b) Class, Import, Package
Option c) Package, Import, Class
Option d) Random order
Ans: c) Package, Import, Class

5. Java programs are_


Option a) Platform-dependent
Option b) Interpreter-dependent
Option c) Platform-independent
Option d) Interpreter-independent
Ans: c) Platform-independent

6. The new operator_


Option a) returns a pointer to a variable
Option b) creates a variable called new
Option c) obtains memory for a new variable
Option d) tells how much memory is available
Ans: c) obtains memory for a new variable

7. Java language has support for which of the following types of comments?
Option a) block, line, and javadoc
Option b) javadoc, literal, and string
Option c) javadoc, char, and string
Option d) single, multiple, and quote
Ans: a) block, line, and javadoc
8. Command to execute a compiled Java program is:
Option a) javac
Option b) java
Option c) run
Option d) execute
Ans: b) java

9. __ is a mechanism for naming and visibility control of a class and its content.
Option a) Object
Option b) Packages
Option c) Interfaces
Option d) None of the mentioned
Ans: b) Packages

10. The Java compiler____


Option a) creates executable
Option b) translates Java source code to byte code
Option c) creates classes
Option d) produces Java Interpreter
Ans: b) translates Java source code to byte code

11. Where are the following four methods commonly used?


Option a) Graphics class
Option b) Component class
Option c) Both A & B
Option d) None of the above
Ans: b) Component class

12. Which is the container that doesn't contain title bars and MenuBars but it can have other
components?
Option a) Window
Option b) Frame
Option c) Panel
Option d) Container
Ans: c) Panel

13. Which is used to store data and partial results, as well as to perform dynamic linking,
return values for methods, and dispatch exceptions?
Option a) Window
Option b) Panel
Option c) Frame
Option d) Container
Ans: d) Container

14. AWT has more powerful components like tables, lists, scroll panes, color chooser, tabbed
panes, etc.
Option a) True
Option b) False
Ans: b) False
15. Which are passive controls that do not support any interaction with the user?
Option a) Choice
Option b) List
Option c) Labels
Option d) Checkbox
Ans: c) Labels

16. For windows, the default layout manager is ____


Option a) BorderLayout
Option b) FlowLayout
Option c) GridLayout
Option d) GridBagLayout
Ans: a) BorderLayout

17. The classes which inherit RuntimeException are known as unchecked exceptions.
Option a) True
Option b) False
Ans: a) True

18. The ____ keyword is used to declare exceptions.


Option a) catch
Option b) throws
Option c) throw
Option d) finally
Ans: b) throws

19. ___ is used to place important code, it will be executed whether an exception is handled or
not.
Option a) Finalize
Option b) Final
Option c) Finally
Option d) None of the above
Ans: c) Finally

20. Java throw keyword is used to explicitly throw an exception.


Option a) True
Option b) False
Ans: a) True

21. JVM (Java Virtual Machine) is an abstract machine.


Option a) True
Option b) False
Ans: a) True

22. JVM is called a virtual machine because it doesn't physically exist.


Option a) True
Option b) False
Ans: a) True
23. The Java Runtime Environment is a set of software tools used for developing Java
applications.
Option a) True
Option b) False
Ans: b) False

24. The Java Development Kit (JDK) is a software development environment used to develop
Java applications and applets.
Option a) True
Option b) False
Ans: a) True

25. Which class is used to access actual bits or content information of a URL?
Option a) URL
Option b) URLConnection
Option c) URLDecoder
Option d) All of the mentioned
Ans: b) URLConnection

26. _ is thrown to indicate that the IP address of a host could not be determined.
Option a) UnknownHostException
Option b) IOException
Option c) HostNotFoundException
Option d) None of these
Ans: a) UnknownHostException

27. What are the types of factory patterns?


Option a) Factory Method
Option b) Abstract Method
Option c) All of the above
Option d) None of the above
Ans: c) All of the above

28. Which class has only one instance?


Option a) Adaptor Class
Option b) Singleton Class
Option c) Factory class
Option d) Proxy Class
Ans: b) Singleton Class

29. A __ variable is shared by all instances of the class. It exists even before an object is
created.
Option a) abstract
Option b) instance
Option c) interface
Option d) static
Ans: d) static

30. ____ is a wrapper around everything associated with a reply from an HTTP server?
Option a) HTTP
Option b) HttpResponse
Option c) Httpserver
Option d) httpserver
Ans: b) HttpResponse

31. ____ is a bundle of information passed between machines.


Option a) Protocol
Option b) Cache
Option c) Datagrams
Option d) Segment
Ans: c) Datagrams

32. ____ class is necessary to implement datagrams.


Option a) DatagramPacket
Option b) DatagramSocket
Option c) Datagram
Option d) Both (a) and (b)
Ans: d) Both (a) and (b)

33. Which of these methods of httpd class is used to read data from the stream?
Option a) getData()
Option b) GetResponse()
Option c) getStream()
Option d) getRawRequest()
Ans: c) getStream()

34. Which of these methods of httpd class is used to get a report on each hit to the HTTP
server?
Option a) log()
Option b) logEntry()
Option c) logHttpd()
Option d) logResponse()
Ans: a) log()

35. Which of these methods are used to find a URL from the cache of httpd?
Option a) findfromCache()
Option b) findFromCache()
Option c) serveFromCache()
Option d) getFromCache()
Ans: b) findFromCache()

36. Which of these variables stores the number of hits that are successfully served out of
cache?
Option a) hits
Option b) hitstocache
Option c) hits_to_cache
Option d) hits.to.cache
Ans: c) hits_to_cache
37. Which of these methods of httpd class is used to write UrlCacheEntry object into the local
disk?
Option a) writeDiskCache()
Option b) writetoDisk()
Option c) writeCache()
Option d) writeDiskEntry()
Ans: a) writeDiskCache()

38. Which of these methods is used to start a server thread?


Option a) run()
Option b) start()
Option c) runThread()
Option d) startThread()
Ans: b) start()

39. Which of the following functions is used to find the column count of a particular ResultSet?
Option a) getMetaData()
Option b) simple
Option c) getColumnCount()
Option d) parameterized
Ans: c) getColumnCount()

40. How can you retrieve information from a ResultSet?


Option a) By invoking the method get( .. , String type) on the ResultSet, where type is the
database type

Option b) By invoking the method get( �, Type type) on the ResultSet, where Type is an
object which represents
Ans: a) By invoking the method get( .. , String type) on the ResultSet, where type is the
database type

41. Which of the following is used to handle database connections in Java?


Option a) Connection
Option b) Statement
Option c) DriverManager
Option d) ResultSet
Ans: c) DriverManager

42. The default value of a boolean variable is ___.


Option a) true
Option b) false
Option c) 0
Option d) null
Ans: b) false

43. Which of the following keywords is used to prevent inheritance in Java?


Option a) final
Option b) static
Option c) transient
Option d) const
Ans: a) final
44. Which of the following classes are used to create GUI components in Java?
Option a) java.awt.Component
Option b) javax.swing.Component
Option c) java.awt.Button
Option d) All of the above
Ans: d) All of the above

45. What is the default value of an instance variable of type String?


Option a) null
Option b) ""
Option c) 0
Option d) undefined
Ans: a) null

46. Which of the following is not a valid access modifier in Java?


Option a) private
Option b) public
Option c) protected
Option d) restricted
Ans: d) restricted

47. Which of these methods is used to add an element to an ArrayList in Java?


Option a) addElement()
Option b) push()
Option c) add()
Option d) insert()
Ans: c) add()

48. What does the 'super' keyword do in Java?


Option a) It refers to the current object
Option b) It calls the constructor of the parent class
Option c) It creates a new object
Option d) It makes a class static
Ans: b) It calls the constructor of the parent class

49. Which of the following methods is used to get the length of an array in Java?
Option a) getLength()
Option b) length()
Option c) size()
Option d) length()
Ans: b) length()

50. Which of these keywords is used to handle exceptions in Java?


Option a) try
Option b) catch
Ans: b) catch

51. In Java, the default value of a float variable is:


Option a) 0
Option b) 0.0
Option c) null
Option d) NaN
Ans: b) 0.0

52. Which of these classes is used to handle the reading and writing of files in Java?
Option a) FileReader
Option b) BufferedReader
Option c) FileWriter
Option d) All of the above
Ans: d) All of the above

53. Which of these is the correct way to create a thread in Java?


Option a) new Thread()
Option b) start()
Option c) new Runnable()
Option d) new Thread(Runnable)
Ans: d) new Thread(Runnable)

54. What is the default value of an integer in Java?


Option a) 0
Option b) null
Option c) 1
Option d) NaN
Ans: a) 0

55. Which of these is used to create an array of integers in Java?


Option a) int[] arr = new int[10];
Option b) int arr[] = new int(10);
Option c) int[] arr = int[10];
Option d) int arr[] = new int[10];
Ans: a) int[] arr = new int[10];

56. Which of these methods is used to start a thread in Java?


Option a) run()
Option b) start()
Option c) begin()
Option d) execute()
Ans: b) start()

57. Which of the following is true about the String class in Java?
Option a) Strings are mutable
Option b) Strings are immutable
Option c) Strings can be changed directly
Option d) None of the above
Ans: b) Strings are immutable

58. Which of the following is the correct syntax for a comment in Java?
Option a) /* comment */
Option b) // comment
Option c) # comment
Option d) Both a and b
Ans: d) Both a and b

59. What is the output of the following code:


String str = "Java";
System.out.println(str.substring(2));
Option a) va
Option b) Jav
Option c) a
Option d) Java
Ans: a) va

60. What does the keyword 'this' refer to in Java?


Option a) The current method
Option b) The current class
Option c) The current object
Option d) None of the above
Ans: c) The current object

61. Which of these methods is used to determine the length of a string in Java?
Option a) length()
Option b) size()
Option c) getLength()
Option d) getSize()
Ans: a) length()

62. Which of these statements about Java is correct?


Option a) Java is a compiled language
Option b) Java is an interpreted language
Option c) Java is a platform-independent language
Option d) Java requires special hardware
Ans: c) Java is a platform-independent language

63. Which of the following is used to declare an array in Java?


Option a) array[] a = new int[10];
Option b) int[] a = new int(10);
Option c) int[] a = int[10];
Option d) int a[] = new array[10];
Ans: a) array[] a = new int[10];

64. Which of the following is an example of an abstract data type (ADT)?


Option a) LinkedList
Option b) Array
Option c) HashMap
Option d) Both a and c
Ans: d) Both a and c

65. In Java, which of the following is used to check whether two strings are equal?
Option a) equals()
Option b) ==
Option c) compareTo()
Option d) isEqual()
Ans: a) equals()

66. Which of the following is the parent class of all classes in Java?
Option a) Object
Option b) Class
Option c) Java
Option d) Main
Ans: a) Object

67. What is the purpose of the finalize() method in Java?


Option a) To finalize a class
Option b) To close resources before garbage collection
Option c) To prevent garbage collection

68. Which of the following interfaces is implemented by the List class in Java?
Option a) Set
Option b) Collection
Option c) Iterator
Option d) Queue
Ans: b) Collection

69. What is the output of the following code?


System.out.println(5 + 3 + "Java");
Option a) 8Java
Option b) 53Java
Option c) Java8
Option d) Java53
Ans: a) 8Java

70. Which of the following is not a feature of Java?


Option a) Object-oriented
Option b) Platform-independent
Option c) Uses pointers
Option d) Robust
Ans: c) Uses pointers

You might also like