Java Multiple Choice Questions & Answers on Core Java API Packages for Freshers

1. Which of these package is used for graphical user interface?

a) java.applet
b) java.awt
c) java.awt.image
d) java.io
Answer: b

Explanation: java.awt provides capabilities for graphical user interface.
2. Which of these package is used for analyzing code during run-time?

a) java.applet
b) java.awt
c) java.io
d) java.lang.reflect
Answer: d

Explanation: Reflection is the ability of a software to analyze itself. This is provided by java.lang.reflevt package.
3. Which of these package is used for handling security related issues in a program?

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

Explanation: java.security handles certificates, keys, digests, signatures, and other security functions.
4. Which of these class allows us to get real time data about private and protected member of a class?

a) java.io
b) GetInformation
c) ReflectPermission
d) MembersPermission
Answer: c

Explanation: The ReflectPermission class allows reflection of a private or protected members of a class. This was added after java 2.0 .
5. Which of these package is used for invoking a method remotely?

a) java.rmi
b) java.awt
c) java.util
d) java.applet
Answer: a

Explanation: java.rmi provides capabilities for remote method invocation.
6. Which of these package is used for all the text related modifications?

a) java.text
b) java.awt
c) java.lang.text
d) java.text.mofify
Answer: a

Explanation: java.text provides capabilities for formatting, searching and manipulating text.
7. What is the output of this program?
  1.     import java.lang.reflect.*;
  2.     class Additional_packages {  
  3.          public static void main(String args[]) {
  4.       try {
  5.           Class c = Class.forName("java.awt.Dimension");
  6.    Constructor constructors[] = c.getConstructors();
  7.    for (int i = 0; i < constructors.length; i++)
  8.        System.out.println(constructors[i]);
  9.    }
  10.       catch (Exception e){
  11.              System.out.print("Exception");
  12.              }
  13.         }
  14.     }
a) Program prints all the constructors of ‘java.awt.Dimension’ package.
b) Program prints all the possible constructors of class ‘Class’.
c) Program prints “Exception”
d) Runtime Error
Answer: a
8. What is the output of this program?
  1.     import java.lang.reflect.*;
  2.     class Additional_packages {  
  3.          public static void main(String args[]) {
  4.       try {
  5.           Class c = Class.forName("java.awt.Dimension");
  6.    Field fields[] = c.getFields();
  7.    for (int i = 0; i < fields.length; i++)
  8.        System.out.println(fields[i]);
  9.    }
  10.       catch (Exception e){
  11.              System.out.print("Exception");
  12.              }
  13.         }
  14.     }
a) Program prints all the constructors of ‘java.awt.Dimension’ package.
b) Program prints all the methods of ‘java.awt.Dimension’ package.
c) Program prints all the data members of ‘java.awt.Dimension’ package.
d) program prints all the methods and data member of ‘java.awt.Dimension’ package.
Answer: c
9. What is the length of the application box made by this program?
  1.     import java.awt.*;
  2.     import java.applet.*;
  3.     public class myapplet extends Applet {
  4.         Graphic g;
  5.         g.drawString("A Simple Applet",20,20);    
  6.     }
a) 20
b) Default value
c) Compilation Error
d) Runtime Error
Answer: c

Explanation: To implement the method drawString we need first need to define abstract method of AWT that is paint() method. Without paint() method we cannot define and use drawString or any Graphic class methods.
10. What is the output of this program?
  1.     import java.lang.reflect.*;
  2.     class Additional_packages {  
  3.          public static void main(String args[]) {
  4.       try {
  5.           Class c = Class.forName("java.awt.Dimension");
  6.    Method methods[] = c.getMethods();
  7.    for (int i = 0; i < methods.length; i++)
  8.        System.out.println(methods[i]);
  9.    }
  10.       catch (Exception e){
  11.              System.out.print("Exception");
  12.              }
  13.         }
  14.     }
a) Program prints all the constructors of ‘java.awt.Dimension’ package.
b) Program prints all the methods of ‘java.awt.Dimension’ package.
c) Program prints all the data members of ‘java.awt.Dimension’ package.
d) program prints all the methods and data member of ‘java.awt.Dimension’ package.
Answer: b

Related

Data Structures Multiple Choice Questions and Answers on Linear Search Iterative

1. Where is linear searching used? a) When the list has only a few elementsb) When performing a single search in an unordered listc) Used all the timed) Both a and b Answer: d Explanation: It is ...

Data Structures Multiple Choice Questions and Answers on Binary Decision Diagrams & And Inverter Graph

1. Binary Decision Diagram is a type of __________ a) Multigraphb) Cyclic Graphc) Directed Acyclic Graphd) Directed Acyclic Word Graph Answer: c Explanation: An Inverter is a directed graph which...

Data Structure Questions and Answers on Selection Sort for Freshers

1. What is an in-place sorting algorithm? a) It needs O(1) or O(logn) memory to create auxiliary locationsb) The input is already sorted and in-placec) It requires additional storaged) None of the...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item