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

Multiple Choice Questions 6311236555741372058

Post a Comment

emo-but-icon

item