Archive for java technical questions

You are browsing the archives of java technical questions.

Java Util Examples List part-I (data structures in java)

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 [...]

Advantages of Java in brief

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 [...]

Object Oriented Programming Language- basic concepts

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 [...]

What is JVM in java……….a brief description

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 …… A brief description!!!!

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, [...]

Java questions with one word answers

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 [...]

Java- Technical question on Networking Concepts

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) [...]

Java-Technical questions on Utility Package

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 [...]

Java- error finding questions Part-I

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 [...]

Java-Programitical questions, logical questions,technical questions part-II

This paper gives an idea about Java programmatic questions and logicals that are being asked in interviews for freshers and experienced people.
And also don’t forget to read another part of this series here,
also check out complete Java section if you want to be master in Java

Examine the following class definition:

public class [...]

Java-Programitical questions, logical questions,technical questions part-I

This paper gives an idea about java coding questions for freshers which are helpful for interview exams…

What class must an inner class extend:
1) The top level class
2) The Object class
3) Any class or interface
4) It must extend an interface
Answer 3
In the following code, which is the earliest statement, where the object originally held in e, [...]

Java- Programmitical questions, logical questions

Which colour is used to indicate instance methods in the standard “javadoc” format documentation:
1) blue
2) red
3) purple
4) orange
Answer : 2

explain
In JDK 1.1 the variabels, methods and constructors are colour coded to simplifytheir identification.
endExplain
What is the correct ordering for the import, class and package declarations when found in a single file?
1) package, import, class
2) [...]

Java- Technicl questions on AWT: CONTROLS, LAYOUT MANAGERS AND MENUS

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 [...]

Java- Technical questions on AWT : WINDOWS, GRAPHICS AND FONTS

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 [...]

Java-Technical questions on APPLETS

What is an Applet? Should applets have constructors?
Ans : Applet is a dynamic and interactive program that runs inside a Web page displayed by a Java capable browser. We don’t have the concept of Constructors in Applets.
How do we read number information from my applet’s parameters, given that Applet’s getParameter() method returns a [...]

Java-Technical questions on EVENT HANDLING

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-Technical question on INPUT / OUTPUT : EXPLORING JAVA.IO

What is meant by Stream and what are the types of Streams and classes of the Streams?
Ans : A Stream is an abstraction that either produces or consumes information.
There are two types of Streams. They are:
Byte Streams : Byte Streams provide a convenient means for handling input and output of bytes.
Character Streams : Character [...]

Java-Technical questions on EXPLORING JAVA.LANG

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 [...]

Java- Technical questions on STRING HANDLING

Which package does define String and StringBuffer classes?
Ans : java.lang package.
Which method can be used to obtain the length of the String?
Ans : length( ) method.
How do you concatenate Strings?
Ans : By using ” + ” operator.
Which method can be used to compare two strings for equality?
Ans : equals( ) method.
Which [...]

Java- Technical questions on Inheritance

1) What is the difference between superclass & subclass?
Ans : A super class is a class that is inherited whereas subclass is a class that does the inheriting.
2) Which keyword is used to inherit a class?
Ans : extends
3) Subclasses methods can access superclass members/ attributes at all times?
True/False
Ans : False
4) When can subclasses not [...]

Java - Technical questions on MULTI THREADING

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 [...]

Java-Technical questions on packages and interfaces

1) What are packages ? what is use of packages ?
Ans :The package statement defines a name space in which classes are stored.If you omit the package, the classes are put into the default package.
Signature… package pkg;
Use: * It specifies to which package the classes defined in a file belongs to. * Package is both [...]

Java-Technical questions on control strutures,methods,classes

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 ” [...]

Java- Technical questions on Operators

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 [...]

Java- questions on Data types,variables and Arrays

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 [...]