Archive for java aptitude questions
You are browsing the archives of java aptitude questions.
You are browsing the archives of java aptitude questions.
41. Listing the Main Attributes in a JAR File Manifest
Jar Manifest file is the main section of a jar file. This file contains the detailed information about the specific individual jar file. It contains the complete information about the jar file, each and every section or particular information is separated by new line.
42. Creating a ZIP File
Zip [...]
21. Creating a Copy of a Collection
This tells how to create and then copy the collection. The copied collection contains the reference to the object. In-fact, objects are not cloned.
22. Making a Collection Read-Only
This section describes you how to make a collection read-only. In this section, list (component of the collection) has been represented for making it [...]
The util package or java provides many utility interfaces and classes for easy manipulation of in-memory data. The java util package tutorials at RoseIndia.net introduces you with the Java util package of JDK. All the examples are with free source code. It includes many examples that demonstrate the syntax and example code of java [...]
Java Features
Platform Independent
The concept of Write-once-run-anywhere (known as the Platform independent) is one of the important key feature of java language that makes java as the most powerful language. Not even a single language is idle to this feature but java is more closer to this feature. The programs written on one platform can run [...]
There are four main pillars of an Object Oriented Programming Language :
• Inheritance:
Inheritance provide the facility to drive one class by another using simple syntax. You can say that it is a process of creating new class and use the behavior of the existing class by extending them for reuse the existing code and adding the [...]
Java Virtual Machine (JVM)
It is the principal component of Java architecture that provides the cross platform functionality and security to Java. This is a software process that converts the compiled Java byte code to machine code. Byte code is an intermediary language between Java source and the host system.
Most programming language like C [...]
What is Java?
Java is a high-level object-oriented programming language developed by the Sun Microsystems. Though it is associated with the World Wide Web but it is older than the origin of Web. It was only developed keeping in mind the consumer electronics and communication equipments. It came into existence as a part of web application, [...]
Q: What if the main method is declared as private?
A: The program compiles properly but at runtime it will give “Main method not public.” message.
Q: What if the static modifier is removed from the signature of the main method?
A: Program compiles. But at runtime throws an error “NoSuchMethodError”.
Q: What if I write static public void instead of public static [...]
What is the difference between URL instance and URLConnection instance?
ANSWER : A URL instance represents the location of a resource, and a URLConnection instance represents a link for accessing or communicating with the resource at the location.
2) How do I make a connection to URL?
ANSWER : You obtain a URL instance and then invoke openConnection [...]
1) The API doesn’t list any constructors for InetAddress- How do I create an InetAddress instance?
ANSWER : In case of InetAddress the three methods getLocalHost, getByName, getByAllName can be used to create instances.
E.g.
InetAddress add1;
InetAddress add2;
try{
add1 = InetAddress.getByName(”java.sun.com”);
add2 = InetAddress.getByName(”199.22.22.22″);
}catch(UnknownHostException e){}
2) Is it possible to get the Local host IP?
ANSWER : Yes. Use InetAddress’s getLocalHost method.
3) [...]
1) What is the Vector class?
ANSWER : The Vector class provides the capability to implement a growable array of objects.
2) What is the Set interface?
ANSWER : The Set interface provides methods for accessing the elements of a finite mathematical set.Sets do not allow duplicate elements.
3) What is Dictionary class?
ANSWER : The Dictionary class is the [...]
What is the result of executing the following Java class:
import java.awt.*;
public class FrameTest extends Frame {
public FrameTest() {
add (new Button("First"));
add (new Button("Second"));
add (new Button("Third"));
pack();
setVisible(true);
}
public static void main(String args []) {
new FrameTest();
}
}
1) Nothing happens.
2) Three buttons are displayed across a window.
3) A runtime exception is generated (no layout manager specified).
4) Only the “first” button is [...]
What is meant by Controls and what are different types of controls?
Ans : Controls are componenets that allow a user to interact with your application.The AWT supports the following types of controls:
Labels
Push buttons
Check boxes
Choice lists
Lists
Scroll bars
Text components
These controls are subclasses of Component.
You want to construct a text area that is 80 character-widths wide and 10 [...]
How would you set the color of a graphics context called g to cyan?
g.setColor(Color.cyan);
g.setCurrentColor(cyan);
g.setColor(”Color.cyan”);
g.setColor(”cyan’);
g.setColor(new Color(cyan));
Ans : a.
The code below draws a line. What color is the line?
g.setColor(Color.red.green.yellow.red.cyan);
g.drawLine(0, 0, 100,100);
Red
Green
Yellow
Cyan
Black
Ans : d.
What does the following code draw?
g.setColor(Color.black);
g.drawLine(10, 10, 10, 50);
g.setColor(Color.RED);
g.drawRect(100, 100, 150, 150);
A red vertical line that is 40 pixels long and a red square with [...]
The event delegation model, introduced in release 1.1 of the JDK, is fully compatible with the event model.
True
False
Ans : b.
A component subclass that has executed enableEvents( ) to enable processing of a certain kind of event cannot also use an adapter as a listener for the same kind of event.
True
False
Ans : b.
What is the highest-level [...]
java.lang package is automatically imported into all programs.
True
False
Ans : a
What are the interfaces defined by java.lang?
Ans : Cloneable, Comparable and Runnable.
What are the constants defined by both Flaot and Double classes?
Ans : MAX_VALUE,
MIN_VALUE,
NaN,
POSITIVE_INFINITY,
NEGATIVE_INFINITY and
TYPE.
What are the constants defined by Byte, Short, Integer and Long?
Ans : MAX_VALUE,MIN_VALUE and TYPE.
What are the constants defined by [...]
1) What are the two types of multitasking?
Ans : 1.process-based
2.Thread-based
2) What are the two ways to create the thread?
Ans : 1.by implementing Runnable
2.by extending Thread
3) What is the signature of the constructor of a thread class?
Ans : Thread(Runnable threadob,String threadName)
4) What are all the methods available in the Runnable Interface?
Ans : run()
5) What is the [...]
1) What is the difference between ‘throw’ and ‘throws’ ?And it’s application?
Ans : Exceptions that are thrown by java runtime systems can be handled by Try and catch blocks. With throw exception we can handle the exceptions thrown by the program itself. If a method is capable of causing an exception that it does not [...]
1) What are the programming constructs?
Ans: a) Sequential
b) Selection — if and switch statements
c) Iteration — for loop, while loop and do-while loop
2) class conditional {
public static void main(String args[]) {
int i = 20;
int j = 55;
int z = 0;
z = i < j ? i : j; // ternary operator
System.out.println(”The value assigned is ” [...]
1) What are operators and what are the various types of operators available in Java?
Ans: Operators are special symbols used in expressions.
The following are the types of operators:
Arithmetic operators,Assignment operators, Increment & Decrement operators, Logical operators, Biwise operators, Comparison/Relational operators and Conditional operators.
2) The ++ operator is used for incrementing and the — operator is [...]
1) What is meant by variable?
Ans: Variables are locations in memory that can hold values. Before assigning any value to a variable, it must be declared.
2) What are the kinds of variables in Java? What are their uses?
Ans: Java has three kinds of variables namely, the instance variable, the local variable and the class variable.
Local [...]
26)What is a package?
Ans: A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management.
27)What is a reflection package?
Ans: java.lang.reflect package has the ability to analyze itself in runtime.
28)What is interface and its use?
Ans:Interface is similar to a class which may contain method’s [...]