Archive for Java Basic Interview Questions & Answers

You are browsing the archives of Java Basic Interview Questions & Answers.

Java-Fundamental concepts through OOPS

Q) OOPS concepts
Polymorphism
Ability to take more than one form, In java we achieve this using Method Overloading (compile time polymorphism), Method overriding (runtime polymorphism)
Inheritance
Is the process by which one object acquires the properties of another object.
Encapsulation
Wrapping of data and function into a single unit called encapsulation. Ex:- all java programs.
Abstraction
Nothing but representing the essential futures [...]

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 questions on Servlets

1) What is the servlet?
ANSWER : Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.
Servlets are to servers what applets are to browsers. Unlike applets, [...]

Java- Technical questions on Networking

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

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