File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Technical Interview Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Technical Interview Questions" Watch "Technical Interview Questions" New topic
Author

Technical Interview Questions

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Okay GURUs. What are some good technical interview questions and obviously their answers for Java. They should be pretty general questions. Thanks in advance!
-Dale
------------------

By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Are you going to be the questioner or the questionee??


"JavaRanch, where the deer and the Certified play" - David O'Meara
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
I'll be questioned.
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Name four methods every Java class will have.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
This is my answer without looking at java.lang.Object
public String toString();
public Object clone();
public boolean equals();
public int hashCode();
Am I correct?
BTW, that's a good question. Why not make it more difficult and ask, "Name 4 methods every Java class will have and provide the method signature for each."
Here's my question. Given a text file, input.txt, provide the statement required to open this file with the appropriate I/O stream to be able to read and process this file. (extra credit: use the I/O stream class that will give the best performance).
-Peter
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 570
    
    7

Very nice, we have basic class and io covered.
How about:
Discuss the differences between creating a new class, extending a class and implementing an interface; and when each would be appropriate.
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515

*Creating a new class is simply creating a class with no extensions and no implementations. The signature is as follows
public class MyClass()
{
}
*Extending a class is when you want to use the functionality of another class or classes. The extended class inherits all of the functionality of the previous class. An example of this when you create your own applet class and extend from java.applet.Applet. This gives you all of the functionality of the java.applet.Applet class.
The signature would look like this
public class MyClass extends MyBaseClass
{
}
*Implementing an interface simply forces you to use the methods of the interface implemented. This gives you two advantages. This forces you to follow a standard (forces you to use certain methods) and in doing so gives you a channel for polymorphism. This isn�t the only way you can do polymorphism but this is one of the ways.
public class Fish implements Animal
{
}
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

[I]Creating a new class is simply creating a class with no extensions and no implementations. The signature is
as follows
[/I]
Doesn't this implecitly extend the object class.
Steve ........... any comments abt creating new class ?
regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Yes it does. I was going to mention this. All objects must ultimately branch from the root of Object.
Susan Hoover
Ranch Hand

Joined: Jan 04, 2001
Posts: 64
Originally posted by Dale DeMott:
Okay GURUs. What are some good technical interview questions and obviously their answers for Java. They should be pretty general questions. Thanks in advance!

If you are the one who will be questioned, perhaps it's a good idea to take a few mock exams.
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Of course you're right, Peter. Like there was any doubt.
Here's another. What's the difference between the == operator and the equals() method? What test does Object.equals() use, and why?
The answer is actually in the API if you're not sure, but it's a good one to think about before reading that explanation.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
The == operator would be used, in an object sense, to see if the two objects were actually the same object. This operator looks at the actually memory address to see if it actually the same object. The equals() method is used to compare the values of the object respectively. This is used in a higher level to see if the object values are equal. Of course the the equals() method would be overloaded in a meaningful way for whatever object that you were working with.
-Dale
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Okey doke. My advice, if this were an interview question, would be to better portray the roles by the terms "object" and "object reference." The first thing is the collection of bits in memory; the second is the identifier that allows you to talk to them.
Clean up that answer!
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Then you would answer the question like so...??
---------------------------
The == operator would be used, in an object sense, to see if the two objects were actually the same object. This operator looks at the object references to see if they were actually the same object. The equals() method is used to compare the values of the object respectively. This is used in a higher level to see if the object values are equal. Of course the the equals() method would be overloaded in a meaningful way for whatever object that you were working with.
---------------------------
I have to stop thinking in C++ style
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Well, like this:
The == operator, when used with two object references, tests whether both references point to the same location in memory.
The equals() method applies whatever test for equality the programmer provides. Presumably, the programmer will define this test to be whatever is meaningfully equal in value. In String, for example, equals() tests whether two String objects have the same content.
In java.lang.Object, however, equals() actually looks like this:

In other words, Object.equals() defines equality in value in the narrowest possible sense: two objects in memory will equal if their references point to the same thing.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
How about - why do you create interfaces, and when MUST you use one.
Nitin Shivaram
Ranch Hand

Joined: Jan 17, 2001
Posts: 71
You would create interfaces when you have two or more functionalities talking to each other. Doing it this way help you in creating a protocol between the parties involved.
Here are some of my questions..
1) What is the difference between instanceof and isInstance?
2) How many methods do u implement if implement the Serializable Interface?
have fun !!
------------------
Nitin S


Nitin S<br />Sun Certified Java Programmer for the Java 2 platform.<br />Tekmetrics Certified Java Programmer For the Java 2 Platform.
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Very good question. I like these that make me look deeping into the language. instanceof is used to check to see if an object can be cast into a specified type without throwing a cast class exception. As for isInstance, it sounds like its similar but slightly different. Where would I find info on isInstance? Not sure about that one. Help me out here
sunil choudhary
Ranch Hand

Joined: Nov 10, 2000
Posts: 141

Dale ,Michael, Cindy and everyine else ....

this series is fascinating......
ANyway back to work
I searched in API for isinstance. and I got
for isInstance()
Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false otherwise.
Specifically, if this Class
However in API index there is only one entry for Instanceof and that is
isInstanceOf(Object,class)??? is that the method Nitin asked for ...

[This message has been edited by sunil choudhary (edited January 25, 2001).]


"Learning is weightless, a treasure you can always carry easily." -Chinese Proverb
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
BTW, I wasn't sure about the Serializable question that Cindy had. I implemented the Serializable interface and it didn't force me to use any type of methods. Not sure why. Maybe someone can explain this to me.
I have some technical interview questions for the others out there.
*What are the advantages of developing an n-tiered system?
*Why is it often difficult to separate the business layer from the data access layer?


------------------
ryan burgdorfer
Ranch Hand

Joined: Jan 24, 2001
Posts: 219
Dale,
The Serializable interface is just a "marker" interface, with no methods of its own to implement.
~Ryan


<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Ryan's right. Serializable is used to stream an object into a line of bits. The VM agrees to do the work if you simply implement Serializable. The only caution: that which is not reasonably serializable to begin with isn't magically cured by using this interface. That aside, imagine some code inside the VM that might look like this:
We don't have to tell the VM how to serialize, so there's no need to implement any methods.
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Are there any other 'marker' interfaces? If so, what are they?
------------------
What's this H2SO4 doing in my fridge?? ( thud )
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

java.rmi.Remote
java.util.EventListener
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
[This message has been edited by Michael Ernest (edited February 06, 2001).]
Hema Sukumar
Greenhorn

Joined: Dec 22, 2000
Posts: 22
I remember reading in Nutshell..
Even java.lang.Cloneable is a marker interface.
Here are some questions that I could think of.
1. Diff between ArrayList and Vector
2. Variable shadowing with example
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Just one more thing...
If your class implements Serializable, any instance and class variables (objects) that you define in your class must also implement Serializable. Or you have to mark it transient. Otherwise, I think you will get a runtime exception.
Originally posted by Michael Ernest:
[B]Ryan's right. Serializable is used to stream an object into a line of bits. The VM agrees to do the work if you simply implement Serializable. The only caution: that which is not reasonably serializable to begin with isn't magically cured by using this interface. That aside, imagine some code inside the VM that might look like this:
We don't have to tell the VM how to serialize, so there's no need to implement any methods.[/B]

Asuthosh Borikar
Ranch Hand

Joined: Sep 29, 2000
Posts: 75
Another question - if you have to use collapsible/expandable arrays as a member variable of an EJB class, what collection would you choose - Vector or ArrayList? Why?
If your servlet implements SingleThreadModel, does it guarantee against concurrent access problems? For ex: if your servlet reads from/writes to a files, is it a good choice to have your servlet implement Single Thread Model?
elavazhagan selvaraj
Greenhorn

Joined: Jan 23, 2001
Posts: 5
hi all,
Its nice here, but everybody asks questions but only few answers... thats the worst thing. i think variable hiding
is that one using the this operator inside the methods.
My question is what is the purpose of the implementing the dummy interfaces(marker interface) like serializable.....??
regards,
elavazhagan

Elavazhagan Selvaraj<BR>elavazhagan@rediffmail.com
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Originally posted by Cindy Glass:
How about - why do you create interfaces, and when [b]MUST you use one.[/B]

You create interfaces to force an standard. This standard might be to implement polymorphism or it might be for using other classes that expect an certain parameters and thus require the use of an interface.
You must use an interface for the use of serializable and clonable. In order to do this, you implement these marker classes. This tells the system you want to do something "special" with your class.
Dale

------------------
By failing to prepare, you are preparing to fail.
Benjamin Franklin (1706 - 1790)
aminur rashid
Ranch Hand

Joined: Sep 21, 2001
Posts: 79
Shall we start it again???
Diff b/w arraylist and vector...
ArrayList is not synchronized but Vector is. Vector is slow...


Regards<br />Aminur
siva krishnan
Greenhorn

Joined: Apr 26, 2003
Posts: 21
My Question !!
What are some basic differences between STRING & STRINGBUFFER Classes ?
What are areas where one is more effective than the other?


Cheers<br />Siva<br />SCJP 1.4<br />SCWCD 1.3
D. Paul Allen
Greenhorn

Joined: Jan 04, 2004
Posts: 3
Some major differences between String and StringBuffer classes are:
Strings are immutable and StringBuffers are not. This means that the content of a String can not change, but that in a StringBuffer can. There are no getters or setters or other mutators set up for strings. When you "change" the content of a String via:
String s1 = "First String";
s1 = "Something Else";
In effect, what you are doing is assigning the reference s1 to a different String object, not changing the contents of s1.
Perhaps most importantly (at least the certification study guide made a BIG deal of it) is String class overrides Object.equals() method and StringBuffer does not. This means that:
StringBuffer s1 = new StringBuffer();
StringBuffer s2 = new StringBuffer();
s1.equals(s2)
will only return true if the two StringBuffers are referring to the same object (i.e. s1==s2).
The questions I would ask are:
Given the following:

what is printed? (Polymorphism detail).
aminur rashid
Ranch Hand

Joined: Sep 21, 2001
Posts: 79

will not compile as no method eat in Animal

any way if we call the correct method it will be the method of Dog is being called as we are creating instance of Dog.
My question...
when we should go for over-ridden method and when we should go for method with different names.
Like we could have had dogEat method in Dog instead of simple eat.
What are the criteria that needs to be considered before we design classes
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
To answer the below question
"When we should go for over-ridden method and when we should go for method with different names"
Maybe the question should be... When do you push common methods together? Whether if you design up front and creating the superclass methods up front or if you end up designing and getting a change of design later on only to refactor it and do a PUSH METHOD UP, I find that the criteria of naming methods and where to put them lies in the functionality of the system. Try and design your objects to have one function. Then try to arrange those methods in a common hierarchy in the superclasses. If I can't refactor the methods to act in a similar way or if it gets in my way to refactor them to act in a similar way, then I leave them separate. I also often try to create method names that read like a sentence or are a verb. Example eat(Food) or maybe something like getDatabaseConnectionFor(DB2Instance). Thats my 2 cents worth.
Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
Oh Good Now I can go for the walk-in on Saturday!
Thanks a lot,Ranchers!
elvis chuah
Greenhorn

Joined: Nov 18, 2003
Posts: 2
I guess one of the most important quesion to newbie Java programmer. Ask them to construct two string of "Hello world" and "my name is elvis".
Then finally make them into one string.
It will test the Java programmer to understand the important of memory allocation in VM.
regards,
elvis
Mahesh G Patil
Greenhorn

Joined: Oct 21, 2003
Posts: 10
Here are some questions, have fun
What is meant by Java ?
What is meant by a class ?
What is meant by a method ?
What are the OOPS concepts in Java ?
What is meant by encapsulation ? Explain with an example
What is meant by inheritance ? Explain with an example
What is meant by polymorphism ? Explain with an example
Is multiple inheritance allowed in Java ? Why ?
What is meant by Java interpreter ?
What is meant by JVM ?
What is a compilation unit ?
What is meant by identifiers ?
What are the different types of modifiers ?
What are the access modifiers in Java ?
What are the primitive data types in Java ?
What is meant by a wrapper class ?
What is meant by static variable and static method ?
What is meant by Garbage collection ?
What is meant by abstract class
What is meant by final class, methods and variables ?
What is meant by interface ?
What is meant by a resource leak ?
What is the difference between interface and abstract class ?
What is the difference between public private, protected and static
What is meant by method overloading ?
What is meant by method overriding ?
What is singleton class ?
What is the difference between an array and a vector ?
What is meant by constructor ?
What is meant by casting ?
What is the difference between final, finally and finalize ?
What is meant by packages ?
What are all the packages ?
Name 2 calsses you have used ?
Name 2 classes that can store arbitrary number of objects ?
What is the difference between java.applet.* and java.applet.Applet ?
What is a default package ?
What is meant by a super class and how can you call a super class ?
What is anonymous class ?
Name interfaces without a method ?
What is the use of an interface ?
What is a serializable interface ?
How to prevent field from serialization ?
What is meant by exception ?
How can you avoid the runtime exception ?
What is the difference between throw and throws ?
What is the use of finally ?
Can multiple catch statements be used in exceptions ?
Is it possible to write a try within a try statement ?
What is the method to find if the object exited or not ?
What is meant by a Thread ?
What is meant by multi-threading ?
What is the 2 way of creating a thread ? Which is the best way and why ?
What is the method to find if a thread is active or not ?
What are the thread-to-thread communcation ?
What is the difference between sleep and suspend ?
Can thread become a member of another thread ?
What is meant by deadlock ?
How can you avoid a deadlock ?
What are the three typs of priority ?
What is the use of synchronizations ?
Garbage collector thread belongs to which priority ?
What is meant by time-slicing ?
What is the use of �this� ?
How can you find the length and capacity of a string buffer ?
How to compare two strings ?
What are the interfaces defined by Java.lang ?
What is the purpose of run-time class and system class
What is meant by Stream and Types ?
What is the method used to clear the buffer ?
What is meant by Stream Tokenizer ?
What is serialization and de-serialisation ?
What is meant by Applet ?
How to find the host from which the Applet has originated ?
What is the life cycle of an Applet ?
How do you load an HTML page from an Applet ?
What is meant by Applet Stub Interface ?
What is meant by getCodeBase and getDocumentBase method ?
How can you call an applet from a HTML file
What is meant by Applet Flickering ?
What is the use of parameter tag ?
What is audio clip Interface and what are all the methods in it ?
What is the difference between getAppletInfo and getParameterInfo ?
How to communicate between applet and an applet ?
What is meant by event handling ?
What are all the listeners in java and explain ?
What is meant by an adapter class ?
What are the types of mouse event listeners ?
What are the types of methods in mouse listeners ?
What is the difference between panel and frame ?
What is the default layout of the panel and frame ?
What is meant by controls and types ?
What is the difference between a scroll bar and a scroll panel.
What is the difference between list and choice ?
How to place a component on Windows ?
What are the different types of Layouts ?
What is meant by CardLayout ?
What is the difference between GridLayout and GridBagLayout
What is the difference between menuitem and checkboxmenu item.
What is meant by vector class, dictionary class , hash table class,and property class ?
Which class has no duplicate elements ?
What is resource bundle ?
What is an enumeration class ?
What is meant by Swing ?
What is the difference between AWT and Swing ?
What is the difference between an applet and a Japplet
What are all the components used in Swing ?
What is meant by tab pans ?
What is the use of JTree ?
How can you add and remove nodes in Jtree.
What is the method to expand and collapse nodes in a Jtree ?
What is the use of JTable ?
What is meant by JFC ?
What is the class in Swing to change the appearance of the Frame in Runtime.
How to reduce flicking in animation ?
What is JDBC ?
How do you connect to the database ? What are the steps ?
What are the drivers available in JDBC ? Explain
How can you load the driver ?
What are the different types of statement s ?
How can you created JDBC statements ?
How will you perform transactions using JDBC ?
What are the two drivers for web apllication?
What are the different types of 2 tier and 3 tier architecture ?
How can you retrieve warning in JDBC ?
What is the exception thrown by JDBC ?
What is meants by PreparedStatement ?
What is difference between PreparedStatement and Statement ?
How can you call the stored procedures ?
What is meant by a ResultSet ?
What is the difference between ExecuteUpdate and ExecuteQuery ?
How do you know which driver is connected to a database ?
What is DSN and System DSN and differentiate these two ?
What is meant by TCP, IP, UDP ?
What is the difference between TCP and UDP ?
What is a proxy server ?
What is meant by URL
What is a socket and server sockets ?
When MalformedURLException and UnknownHost Exception throws ?
What is InetAddress ?
What is datagram and datagram packets and datagram sockets ?
Write the range of multicast socket IP address ?
What is meant by a servlet ?
What are the types of servlets ? Explain
What is the different between a Servlet and a CGI.
What is the difference between 2 types of Servlets ?
What is the type of method for sending request from HTTP server ?
What are the exceptions thrown by Servlets ? Why ?
What is the life cycle of a servlet ?
What is meant by cookies ?
What is HTTP Session ?
What is the difference between GET and POST methods ?
How can you run a Servlet Program ?
How to commuincate between an applet and a servlet ?
What is a Servlet-to-Servlet communcation ?
What is Session Tracking ?
What are the security issues in Servlets ?
What is HTTP Tunneling
How do you load an image in a Servlet ?
What is Servlet Chaining ?
What is URL Rewriting ?
What is context switching ?
What is meant by RMI ?
Explain RMI Architecture ?
What is meant by a stub ?
What is meant by a skelotn ?
What is meant by serialisation and deserialisation ?
What is meant by RRL ?
What is the use of TL ?
What is RMI Registry ?
What is rmic ?
How will you pass parameter in RMI ?
What exceptions are thrown by RMI ?
What are the steps involved in RMI ?
What is meant by bind(), rebind(), unbind() and lookup() methods
What are the advanatages of RMI ?
What is JNI ?
What is Remote Interface ?
What class is used to create Server side object ?
What class is used to bind the server object with RMI Registry ?
What is the use of getWriter method ?
What is meant by Javabeans ?
What is JAR file ?
What is meant by manifest files ?
What is Introspection ?
What are the steps involved to create a bean ?
Say any two properties in Beans ?
What is persistence ?
What is the use of beaninfo ?
What are the interfaces you used in Beans ?
What are the classes you used in Beans ?

Cheers,
Mahesh
John Ipe
Greenhorn

Joined: Dec 29, 2003
Posts: 25
Hi Dale,
I guess it would be neat to hear what questions you were actually faced with in the interview in 2001 (and any interviews you took after)?!
Thanks!
John
aminur rashid
Ranch Hand

Joined: Sep 21, 2001
Posts: 79
So what is reflection in java and its use??? Still looking for a good answer of it...
John Ipe
Greenhorn

Joined: Dec 29, 2003
Posts: 25
Originally posted by aminur rashid:
So what is reflection in java and its use???

reflection is used mostly in tool development, such as class browsers, debuggers etc. when you want to retrieve information about classes and objects at runtime.
here's a good link:
http://www-106.ibm.com/developerworks/java/library/j-dyn0603/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Technical Interview Questions