Jump to content
ChetanaSforum
Sign in to follow this  
Ravi

(FAQ) Interview FAQ in JAVA

Recommended Posts

Try to answer these questions frens. All these are asked in various interviews.ravi^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^What is the difference between an Abstract class and Interface? What is user defined exception? What do you know about the garbage collector? What is the difference between java and c++? In an HTML form I have a button which makes us to open another page in 15 seconds. How will you do that? What is the difference between process and threads? What is update method called? Have you ever used HashTable and Directory? What are statements in Java? What is a JAR file? What is JNI? What is the base class for all swing components? What is JFC? What is the difference between AWT and Swing? Considering notepad/IE or any other thing as process, What will happen if you start notepad or IE 3 times ? Where three processes are started or three threads are started? How does thread synchronization occur in a monitor? Is there any tag in HTML to upload and download files? Why do you canvas? How can you know about drivers and database information ? What is serialization? Can you load the server object dynamically? If so what are the 3 major steps involved in it? What is the layout for toolbar? What is the difference between Grid and Gridbaglayout? How will you add panel to a frame? Where are the card layouts used? What is the corresponding layout for card in swing? What is light weight component? Can you run the product development on all operating systems? What are the benefits if Swing over AWT? How can two threads be made to communicate with each other? What are the files generated after using IDL to java compiler? What is the protocol used by server and client? What is the functionability stubs and skeletons? What is the mapping mechanism used by java to identify IDL language? What is serializable interface? What is the use of interface? Why is java not fully objective oriented? Why does java not support multiple inheritance? What is the root class for all java classes? What is polymorphism? Suppose if we have a variable 'I' in run method, if I can create one or more thread each thread will occupy a separate copy or same variable will be shared? What are virtual functions? Write down how will you create a Binary tree? What are the traverses in binary tree? Write a program for recursive traverse? What are session variable in servlets? What is client server computing? What is constructor and virtual function? Can we call a virtual function in a constructor? Why do we use oops concepts? What is its advantage? What is middleware? What is the functionality of web server? Why is java not 100% pure oops? When will you use an interface and abstract class? What is the exact difference in between Unicast and Multicast object? Where will it be used? What is the main functionality of the remote reference layer? How do you download stubs from Remote place? I want to store more than 10 objects in a remote server? Which methodology will follow? What is the main functionality of Prepared Statement? What is meant by Static query and Dynamic query? What are Normalization Rules? Define Normalization? What is meant by Servelet? What are the parameters of service method? What is meant by Session? Explain something about HTTP Session Class? In a container there are 5 components. I want to display all the component names, how will you do that? Why there are some null interface in JAVA? What does it mean? Give some null interface in JAVA? Tell some latest versions in JAVA related areas? What is meant by class loader? How many types are there? When will we use them? What is meant by flickering? What is meant by distributed application? Why are we using that in our application? What is the functionality of the stub? Explain about version control? Explain 2-tier and 3-tier architecture? What is the role of Web Server? How can we do validation of the fields in a project? What is meant by cookies? Explain the main features? Why java is considered as platform independent? What are the advantages of java over C++? How java can be connected to a database? What is thread? What is difference between Process and Thread? Does java support multiple inheritance? if not, what is the solution? What are abstract classes? What is an interface? What is the difference abstract class and interface? What are adapter classes? what is meant wrapper classes? What are JVM.JRE, J2EE, JNI? What are swing components? What do you mean by light weight and heavy weight components? What is meant by function overloading and function overriding? Does java support function overloading, pointers, structures, unions or linked lists? What do you mean by multithreading? What are byte codes? What are streams? What is user defined exception?

Share this post


Link to post
Share on other sites

byte codes:generally we compile the java file by giving the command javac filename.java.while compiling this java file is converted into class file.the class file contains certain codes called as byte codes.at the run time only the class file will be called andit will give the corresponding o/p.only because this feature java is platform independentjava does not support multiple inheritance directlyfor that we have a concept called interface where we can only declare the method,we can't define a method r we can't intialize a value in the interface.ex interface add { public void addition(int a,int B) } java is not 100% oops coz it does not support the concept of multiple inheritance.i hope so

Share this post


Link to post
Share on other sites

garbage collector: in java we have an auomatic garbage collection system.the runtime system keeps track of the memory that is being allocated and also determineswhether that memory is still useable r not.this determination is done by a low priority thread called garbage collector.if the garbage collector finds a memory that is no longer accessible it calls for the detructor method called finalize() method and then frees he memory.

Share this post


Link to post
Share on other sites

>What is the difference between an Abstract class and Interface? a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract.B) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods. c) Abstract class must have subclasses whereas interface can’t have subclasses.d)Interfaces : Only constants & method declarations allowed Allowed access modifier is publicAbstract class : Default implementations can be provided Different access modifiers can be usedAlso..In real abstract classes are used to create similar objects that share similar behavious, yet are different, but need to be connected in some way. I mean...Abstract classes are useful in a situation that Some general methods should be implemented and specialization behaviour should be implemented by child classes. Interafaces are useful in a situation that all properties should be implemented we can use this scenario

Share this post


Link to post
Share on other sites

>What is user defined exception?

User defined exceptions are those exceptions which an application provider or an API provider defines by subclassing java.lang.Throwable class.

>What do you know about the garbage collector?

Garbage collector frees up the memory by destroying unused objects. The only thing to remember in GC is even though we call garbage collector in a code..we cannot ensure that it runs & frees up memory at that particular time. Every class inherits the finalize() method from java.lang.Object ....

this method is called by the garbage collector when it determines no more references to the object exist

>What is the difference between process and threads?

A Process has its own memory space, runtime enivorment and process ID.

A Thread run inside a Process and shares its resources with other threads.

>What is a JAR file?

Jar file allows to efficiently deploy a set of classes and their associated resources. The elements in a jar file are compressed, which makes downloading a Jar file much faster than separately downloading several uncompressed files.

The package java.util.zip contains classes that read and write jar files.

>what is Serialization?

Serialization allows you to create a JVM-independent binary representation of an in-memory Java object. This external representation may be used to transfer or store the object and to recreate it in another JVM.

>Why is java not fully objective oriented?

Java is not fully object oriented because it doesn't implement primitive datatypes as objects. Also it doesn't support multiple inheritance of classes(though alternatives are provided i.e,interfaces)

>What is the use of interface?

Helps us to achieve Multiple Inheritance partially

>Why does java not support multiple inheritance?

The fact is that Java separates implementation inheritance from interface inheritance. Interface inheritance deals with the "contract" or "agreement " which a class should adhere & on the other hand implementation inheritance deals with the reuse of code and the contract which a class adheres to.

Share this post


Link to post
Share on other sites

>What is the difference between an Abstract class and Interface? a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract.B) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods. c) Abstract class must have subclasses whereas interface can’t have subclasses.d)Interfaces : Only constants & method declarations allowed Allowed access modifier is publicAbstract class : Default implementations can be provided Different access modifiers can be usedAlso..In real abstract classes are used to create similar objects that share similar behavious, yet are different, but need to be connected in some way. I mean...Abstract classes are useful in a situation that Some general methods should be implemented and specialization behaviour should be implemented by child classes. Interafaces are useful in a situation that all properties should be implemented we can use this scenario

We can declare a class as abstract without a single abstract method in it(that is it can contain only concrete classes).

Share this post


Link to post
Share on other sites

What is the role of Web Server? A web server takes a client request and gives something back to client. If the requested resource is already there in server(static pages), it returns it to the client.Otherwise it asks the helper applications(eg:servlets) to provide the required information.What is meant by cookies? In a web-session, in order to identify a client in a particulor session, web container generates a unique session id for that client. When the client's first request comes in, container generates a session ID and give it to the client with the response. When the client sends the second request, it sends back this session id also with its request. Then the container understand that this client belongs to this session . In order to exchange this session id between container and client, they use cookies. To send and recieve session cookie we want to only use request.getSession(). All the other work dealing with cookies will be done by the container.

Share this post


Link to post
Share on other sites

garbage collector: in java we have an auomatic garbage collection system.the runtime system keeps track of the memory that is being allocated and also determineswhether that memory is still useable r not.this determination is done by a low priority thread called garbage collector.if the garbage collector finds a memory that is no longer accessible it calls for the detructor method called finalize() method and then frees he memory.

he name garbage collection implies that objects no longer needed by the program are "garbage" and can be thrown away. When an object is no longer referenced by the program, the heap space it occupies can be recycled so that the space is made available for new objects. The garbage collector must somehow determine which objects are no longer referenced by the program and make available the heap space occupied by such unreferenced objects. In the process of freeing unreferenced objects, the garbage collector must run any finalizers of objects being freed.

Share this post


Link to post
Share on other sites

How java can be connected to a database? What all we need to do to connect from java to database.....I am enclosing a sample program to connect to MYSQL using java/* A Sample program to connect to Mysql Using Java*/import java.sql.*;public class Test{ public static void main(String args[]) { try { /* Test loading driver */ Hashtable members = new Hashtable(); String driver = "com.mysql.jdbc.Driver"; System.out.println( "----->loading driver:------->" ); Class.forName( driver ); /* Test the connection Here test is the name of the database you want to connect to*/ String url = "jdbc:mysql://localhost/test"; /*root is the user name and kris is the password of MYSql*/ DriverManager.getConnection( url, "root", "kris" ); System.out.println("connection established"); /* Create a statement*/ Statement statement = connection.createStatement(); /* Execute a statement for selecting values from database here details is the tables name in database "test"*/ ResultSet resultSet = statement.executeQuery("select * from details"); while (resultSet.next()){ members.put(resultSet.getString(1),resultSet.getString(2)); System.out.println(resultSet.getString(1) + "\t" + resultSet.getString(2) ); } catch( Exception x ) { x.printStackTrace(); } }}Why java is considered as platform independent? When ever you compile the java program using javac programname.java it generates a byte code.....unlike a c or c++ compiler it will not generate an executable code, and the code generated is independent of the system, later this code will be interpreted by JVM and generates the output, so compile once and use any where works for java.....

Share this post


Link to post
Share on other sites

Hi RaviThe FAQs posted by you are really nice and helpful. But there are some people who need answers also.Nice that all people are actively participating here. I have some questions on VB.Net. I am posting them with answers on Forum. Hope it would help. Thanks and keep contributing to the group.Enu Mittal :)

Share this post


Link to post
Share on other sites

Two Tier-Architecture:

The desire to share data between multiple applications installed on different machines. To do this, a separate database server machine was required. The application now consists of presentation and business logic. Data is accessed by connecting to a database on another machine. Any changes to the Data Access logic should not affect the Presentation or Business logic in the application.

Consequences of the 2-Tier Design:

Client is still full of business code and it still needs to know details about the location of its data sources. Because there is such a concentration of functionality on the client, so client application have much of the application code installed on their local systems, there is a need to install fresh copies of the updated

application when changes are made.

Benefits of the 3-Tier Scenario:

It involves the separation of functionality both by using layers and tiers and also the use of components

within those layers.

The presentational developers need not know anything of the business rules in the system, and any changes to any of the layers should not impact the effectiveness of any of the others. This aids in maintenance of the system and promotes scalability and extensibility.The separation into components helps with the division of tasks even further.

Share this post


Link to post
Share on other sites

OverLoading and Overriding:

Overriding:

when a method in a subclass has the same name and type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass. When an overridden method is called from within a subclass, it will always refer to the version of that method defined by the subclass.

Overloading:

When an overloaded method is called, Java looks for a match between the arguments used to call the method and the method's parameters. However, this match need not always be exact. In some cases Java's automatic type conversions can play a role in overload resolution, it chesks for the number of arguments and then the type of arguments

Share this post


Link to post
Share on other sites

wrapper classes:it is a class that encapsulates a single immutable value.it can be constructed by passing the value to be wrapped into appropriate constructor.ex: boolean primitiveBoolean = true; Boolean wrappedBoolean=new Boolean(primitiveBoolean);

Share this post


Link to post
Share on other sites

HI,

 

 

Q >What is base class of all classes in java?

 

A>The base class is java.lang

 

which means java language

 

Q>What is polymorphism

 

A>Polymorphism means "many form". A object or data can behave differently at different situation depend upon how we use that object or data. A good example of polymorphism is method overriding.

A method with same name behave differently or give different output according to how we invoked it.

 

 

class FirstClass

{

 

public void m1()

{

 

System.out.println("method in FirstClass that is super class");

 

 

}

 

}

 

class SecondClass extends FirstClass

{

 

public void m1()

{

System.out.println("method in SecondClass that is in child class");

 

}

}

 

public class Test{

 

public static void main(String [] args)

{

 

 

FirstClass fc = new FirstClass();

SecondClass sc = new SecondClass();

 

 

fc.m1(); // method invoked in super class

//so output -------------method in FirstClass that is super class

 

sc.m1(); // method invoked in child class

//ouput is------method in SecondClass that is in child class

 

 

 

 

}

 

}

 

 

So, in above example same method give different output according to how we invoked it.So this is calles polymorphism.Remember polymorphism doesn't apply to method overloading.

 

From

Aarti Gupta

Bye

Share this post


Link to post
Share on other sites

HI,

 

 

hi

this is josna

aarti, i had seen u r answer for polymorphism.

i did nt get one point at last

polymorphism doesnt apply to methodoverloading,can u tell me briefly why?.

method overloading and operator overloading s are examples of polymorphism.

and give me answer with example program.

 

 

 

 

 

 

 

 

Q >What is base class of all classes in java?

 

A>The base class is java.lang

 

which means java language

 

Q>What is polymorphism

 

A>Polymorphism means "many form". A object or data can behave differently at different situation depend upon how we use that object or data. A good example of polymorphism is method overriding.

A method with same name behave differently or give different output according to how we invoked it.

 

 

class FirstClass

{

 

public void m1()

{

 

System.out.println("method in FirstClass that is super class");

 

 

}

 

}

 

class SecondClass extends FirstClass

{

 

public void m1()

{

System.out.println("method in SecondClass that is in child class");

 

}

}

 

public class Test{

 

public static void main(String [] args)

{

 

 

FirstClass fc = new FirstClass();

SecondClass sc = new SecondClass();

 

 

fc.m1(); // method invoked in super class

//so output -------------method in FirstClass that is super class

 

sc.m1(); // method invoked in child class

//ouput is------method in SecondClass that is in child class

 

 

 

 

}

 

}

 

 

So, in above example same method give different output according to how we invoked it.So this is calles polymorphism.Remember polymorphism doesn't apply to method overloading.

 

From

Aarti Gupta

Bye

Share this post


Link to post
Share on other sites
Thanks for posting Questions and better to post answers also.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  



×