Tuesday 5 July 2016

Basics Interview Questions Of Java For Beginners

Question 1 :- When and who invented java?

Answer:- Java is developed by Sun Microsystems of USA in 1991.

Question 2:- Why is java known as platform-neutral language?

Answer:- It is so because java is not tied to any particular hardware or operating system. Programs developed in java can be executed anywhere on any system.

Question 3:- How is java more secured than other languages?

Answer:- It is so because java systems not only verify all memory access but also ensure that no viruses are communicated with an applet. The absence of pointers in java ensures that programs cannot gain access to memory locations without proper authorization.

Question 4:- What is the difference between java and C?

Answer:-

                               Java                                                                     C

1.It doesn’t have C unique statement keywords       1.It contains the unique keywords sizeof, and
sizeof,andtypedef.                                                        tyedef.

2.It doesn’t have data types struct and union.           2.It contains data types struct and union.

3.It doesn’t support an explicit pointer type.            3.It support an explicit pointer type.

4.It adds labelled break and continue statements    .4.It doesn’t have break and continuestatements.

5.It doesn’t have a preprocessor.                              5.It have preprocessor.


Question 5:- What is the difference between Java and C++?

Answer:-

                      Java                                                                              C++

1. It doesn’t support operator overloading.                1. It supports operator overloading.

2. It doesn’t have template classes.                            2. It has template classes.

3. It doesn’t have multiple inheritance.                      3. It has multiple inheritance.

4. It doesn’t support global variables.                        4. It supports global variables.

5. It doesn’t use pointers.                                           5. It uses pointers.

6. It uses finalize () function.                                     6. It uses destructor () function.

7. There are no header files in java.                           7. It has header files.

Question 6:- Why do we need import statement in java?

Answer:- It is because using import statements we can have access to classes that are part of other named package.

Question 7:- What is the task of main () method in a java program?

Answer:- The main method creates objects of various classes and establishes communication between them. On reaching the end of main, the program terminates and the control passes back to the operating system.

Question 8:- What are separators? What are the various separators used in java?

Answer:- Separators are symbols used to indicate where groups of code are divided and arranged. They basically define the shape and function of our code.

Java includes six types of separators:-

1. Parentheses ()

2, Braces {}

3. Brackets []

4. Semicolon ;

5. Comma ,

6. Period

Question 9:- What are command line arguments? How are they useful?

Answer:- They are the parameters that are supplied to the application program at the time of invoking it for execution. They are useful as we make like our program to act in a particular way depending on the input provided at the time of execution which is achieved by command line arguments.

Question 10 :- Java is a freeform language. Comment.

Answer:- It is a freeform language as we need not have to indent any lines to make the program work properly. Also java system does not care where on the line we begin typing.

Question 11:- List the features of java?

Answer:-Java has the following features:-

 Simple and powerful

 Secure

 Portable

 Object-oriented

 Robust

 Multithreaded

 Architecture-neutral

 Interpreted and High performance

 Distributed

 Dynamic

Question 12:- What are the newly added features in java 2?

Answer:- The following are the newly added features in java 2:-

 Swing

 Collections framework

 Various tools such as javac, java and javadoc have been enhanced.

 Just-In- Time (JIT) compiler

 Policy files

 Digital certificates

 Advanced features for working with shapes, images and text.

 Various security tools

 The user can now play audio files such as MIDI, AU, WAV and RMF files using java programs.

Sub domain:-Fundamentals of java

Question 13 :- What is type casting? Why is it required in programming?

Answer :-The process of converting one data type to another is called casting. It is required because we often encounter situations where there is a need to store a value of one type into a variable of other type. Casting is often necessary when a method returns a type different than the one we require.

Syntax:-

Type variable1 = (type) variable2;

Question 14:- What are wrapper classes? What is their use?

Answer:- Wrapper classes are provided for the primitive data types in order to use these types as objects. The wrapper classes for the primitive data types have the same name as the primitive type, but with the first letter capitalized. The advantage of using wrappers is that when an object is passed to a method, the method is able to work on the object itself. Also the user can derive his/her own classes from java’s built-in wrapper classes.

Question 15:- What is a literal? What are the difference types of literals?

Answer:- A literal represents a value of a certain type where the type describes the behavior of the value. The different types of literals are:-

 Number literals

 Character literals

 Boolean literals

 String literals

Question 16 :- What is a variable? What are the different types of variables?

Answer :- Variables are locations in the memory that can hold values. Java has three kinds of variables namely,

 Instance variable

 Local variable

 Class Variable

Local variables are used inside blocks as counters or in methods as temporary variables. Once the block or the method is executed, the variable ceases to exist. Instance variables are used to define attributes or the state of a particular object. These are used to store information needed by multiple methods in the objects.

Domain: -Classes,Objects, Methods

Question 17:- What is Collection API?

Answer:- The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hash tables if effectively replaces.

Example of classes: Hash Set, Hash Map, Array List, Linked List, Tree Set and Tree Map.

Example of interfaces: Collection, Set, List and Map.

Question 18:- Is Iterator a Class or Interface? What is its use?

Answer:- Iterator is an interface which is used to step through the elements of a Collection.

Question 19 :- What is similarities/difference between an Abstract class and Interface?

Answer:- Differences are as follows:

Interfaces provide a form of multiple inheritances. A class can extend only one other class. Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.

A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.

Interfaces are slow as it requires extra indirection to find corresponding method in in the actual class. Abstract classes are fast.

Similarities:

Neither Abstract classes or Interface can be instantiated.

Question 20:- How to define an Abstract class?

Answer:- A class containing abstract method is called Abstract class. An Abstract class can't be instantiated.

Example of Abstract class:

abstract class testAbstractClass {

protected String myString;

public String getMyString() {

return myString;

}

public abstract string anyAbstractFunction();

}

Question 21 :-When do we create member of a class static?

Answer:- Static variables are used when we want to have a variable common to all instances of a class. Java creates only one copy for static variable which can be used even if the class is never actually instantiated.

Question 22:- Describe the syntax of single inheritance in java?

Answer:-

Syntax:-

Class subclassname extends superclassname

{

Variables declaration;

Methods declaration;

}

Question 23 :- Describe method overloading and method overriding?

Answer :- The process in which methods have same name, but different parameter lists and different definitions is called method overloading. It is used when objects are required to perform similar tasks but using different input parameters. These are the forms of Static polymorphism. Domain:-Arrays and Strings

Question 24 :-What is string Buffer?

Answer :-It is a peer class of string that provides much of the common functionality of strings. Strings represent fixed-length character sequences. String Buffer represents varied length character sequences. String buffer may have characters and substrings inserted in the middle, or appended at the end. The complier automatically creates a String Buffer to evaluate certain expressions, in particular when the overloaded operators + and += are used with string objects.

Question 25:- What are arrays?

Answer:- An array is an object that stores a list of items. Each slot in an array holds individual elements. An array should be of a single type, comprising of integers, strings and so on.

No comments:

Post a Comment