Java Interview Question & Answer Set-1

| Tuesday 14 June 2011

1.What is JAVA ?
      Java is a pure object oriented programming language, which has derived C syntax and C++ object oriented programming features.
Is a compiled and interpreted language and is platform independent and
Can do graphics, networking, multithreading. It was initially called as OAK.

2.What r the four cornerstones of OOP ?
      Abstraction     :           Can manage complexity through abstraction. Gives the complete overview of a particular task and the details are handled by its derived classes. Ex : Car.
Encapsulation        :           Nothing but data hiding, like the variables declared under private of a particular class are accessed only in that class and cannot access in any other the class.
Inheritance            :           Is the process in which one object acquires the properties of another object, ie., derived object.
Polymorphism       :           One method different forms, ie., method overriding and interfaces are the examples of polymorphism.

3.what is downcasting  ?
 Doing a cast from a base class to a more specific class. The cast does not convert the object, just asserts it actually is a more specific extended object.
e.g.  Dalamatian d = (Dalmatian) aDog;
Most people will stare blankly at you if you use the word downcast. Just use cast.


4.What is Java Interpreter ?
It is Java Virtual Machine. ie., a java program compiles the Unicode to intermediary code called as Bytecode which is not an executable code. that is executed by Java interpreter.

5.What are Java Buzzwords ?
Simple       :           Easy to learn.
Secure                   :           Provided by firewalls between networked applications.
Portable     :           Can be dynamically downloaded at various platforms connect to internet.
OOP                      :           Four Corner stones.
Multithread           :           Can perform more than one task concurrently in a single program.
Robust                   :           overcomes problems of de-allocation of memory and exceptions.
Interpreted            :           Convert into byte code and the executes by JVM.
Distributed            :           Concept of RMI.
Dynamic    :           Verifying and accessing objects at run time.


6.What are public static void main(String args[]) and System.out.println() ?
Public keyword is an access specifier.
Static allows main() to be called without having to instantiate a particular instance of class.
Void does not return any value.
main() is the method where java application begins.
String args[] receives any command line arguments during runtime.

System is a predefined class that provides access to the system.
out is output stream connected to console.
println displays the output.

7.What are identifiers and literals ?
Identifiers are the variables that are declared under particular datatype.
Literals are the values assigned to the Identifiers.

8.What is Typed language ?
This means that the variables are at first must be declared by a particular datatype whereas this is not the case with javascript.

9.Scope and lifetime of variables ?
scope of variables is only to that particular block
lifetime will be till the block ends.
variables declared above the block within the class are valid to that inner block also.

10.Casting Incompatible types ?
Can be done either implicitly and explicitly. ie., int b = (int) c; where c is float.
There are two types of castings related to classes : 1) unicast      and      2)multicast.

11.Declaration of Arrays ?
int a[] = new int[10];                     int a[][] = new int[2][2];

12.What does String define ?
String is an array of characters, but in java it defines an object.
and the variable of type string can be assigned to another variable of type String.

13.What r bitwise operators and bitwise logical operators ?
~, &, |, ^, >>, >>>, <<, &=, !=      and      ~, &, |

14.How do you define break and Label ?
We can declare as break <label name > and the label is declared as <label name> : { ….. };
The break statement can be declared anywhere in the program ie either inside the label or outside the label.

15.Define class ?
A class is a one which defines new datatype, and is template of an object, and is a protoype.

16.Types of Constructors ?
Default Constructor,         Parameterized Constructor,    Copy Constructors
Garbage collector takes the responsibility releasing the memory of object implicitly.

17.Define this , finalize, and final( for variables, methods, classes ) ?
this is used inside any method to refer to the current object. and is mostly avoided.
finalize method is used to perform the actions specified in this method just before an object is destroyed. ie just before garbage collector process.
final with variables is we cant change the literals of the variables ie nothing but const.
final with method means we cant override that method.
final with class means we cannot have derived classes of that particular class.

18.What is passed by reference ?
 Objects are passed by reference.
In java we can create an object pointing to a particular location ie NULL location by specifying :        <class name> <object name>;
and also can create object that allocates space for the variables declared in that particular class by specifying :      <object name > = new <class name>();

19.Explain about Static ?
When a member is declared as static it can be accessed before any objects of its class are created and without any reference to any object.
these are global variables, no copy of these variables can be made.
static can also be declared for methods. and cannot refer to this or super.

20.What r nested classes ?
There are two types : static and non-static.
static class means the members in its enclosing class (class within class)  can be accessed by creating an object and cannot be accessed directly without creating the object.
non-static class means inner class and can be accessed directly with the object created for the outer class no need to create again an object like static class.

21.Briefly about super() ?
This is used to initialize constructor of base class from the derived class and also access the variables of base class like super.i = 10.

method overloading : same method name with different arguments.
method overriding :  same method name and same number of arguments.

22.What is Dynamic Method Dispatch ?
this is the mechanism by which a call to an overridden function is resolved at runtime rather than at compile time. And this is how Java implements runtime polymorphism.

23.What r abstract classes ?
 To create a superclass that only defines generalized form that will be shared by all its subclasses, leaving it to each subclass to fill in the details.
we cannot declare abstract constructors and abstract static methods.
An abstract class contains at least one abstract method.
And this abstract class is not directly instantiated with new operator.
Can create a reference to abstract class and can be point to subclass object.

24.What is Object class and java.lang ?
Object class is the superclass of all the classes and means that reference variable of type object can refer to an object of any other class. and also defines methods like finalise,wait.
java.lang contains all the basic language functions and is imported in all the programs implicitly.

25.What r packages and why ? how to execute a program in a package ?
Package is a set of classes, which can be accessed by themselves and cannot be accessed outside the package. and can be defined as package <pkg name>.
Package name and the directory name must be the same.
And the execution of programs in package is done by : java mypack.account
where mypack is directory name and account is program name

0 comments:

Post a Comment

Popular Posts

Company Placement Papers

 

Copyright © 2010 All Question Papers Blogger Template by Dzignine