aspose file tools*
The moose likes Jobs Discussion and the fly likes Interview Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Careers » Jobs Discussion
Bookmark "Interview Questions" Watch "Interview Questions" New topic
Author

Interview Questions

victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
I want start a list of good interview questions; I will maintain and update the list. It would be available to anybody, particularly those who help me.

Here are some topics

1 What is asynchronous mean; in what context is it used.
2 Difference between process and thread
3 Do interfaces have constructors, non-static fields, static methods
4 Does an abstract class have a constructor; can it have a non-abstract parent
5 Can there be memory leak in java; if so give example
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41803
    
  62
... and it certainly has nothing to do with the SCJP. Off to Jobs Discussion it is.


Ping & DNS - my free Android networking tools app
Mark Herschberg
Sheriff

Joined: Dec 04, 2000
Posts: 6037
I'd recommend taking a look at all previous attempts to do this.

--Mark
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3219
I have already done it........ it has more than 400+ popular questions with answers. Answers are concise with lots of diagrams, examples, cross-referencing etc. It took me over 18 months. It is not a trivial task


Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Difference between process and thread

A running program is called a process.
A thread is a smallest unit of work in the program.

Do interfaces have constructors, non-static fields, static methods

No constructors, No static methods, No non-static fields because by default the interface fields are static & final.
Interfaces doesn't have constructors or static methods as it is not a class.

Does an abstract class have a constructor; can it have a non-abstract parent

Yes it can have a constructor & non-abstract parent class.

Can there be memory leak in java; if so give example

What do you mean by memory leak.
Memory consumption in java is controlled by default garbage collector, a thread which runs implicitly.

What is asynchronous mean; in what context is it used.

Asynchronous means not-synchronized, not in line or not proper.
I use it situations to mean classes which are not synchronized.
For example I'll say StringBuilder is asynchronous in nature compared to StringBuffer which is synchronized.
Hope this is suffice.
Regards.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18824
    
  40

Asynchronous means not-synchronized, not in line or not proper.
I use it situations to mean classes which are not synchronized.
For example I'll say StringBuilder is asynchronous in nature compared to StringBuffer which is synchronized.


Be careful with this... "asynchronous" is more commonly referred to in the context of IO. Asynchronous IO, or non-blocking IO, is a way to deal with IO that does not prevent the application from doing something else.

If this term comes up during an interview, its more likely about the topic of IO, than the topic of threads and syncrhonization.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
1. asynchronous vs synchronous: First of all these have nothing to do with the synchronized keyword. The best example I explaining the difference is this. When you call somebody and you get her on the phone, the conversation is two-sided (and this synchronous). Asynchronous is when you don�t get her on the phone and leave a message; this paradigm is used in Java Messaging. Synchronous also applies to the request/reponse of a browser

2. Thread vs. Process A process is usually defined as an instance of a program that is being executed, including all variables and other information describing the program�s state. Processes have a life cycle: they are spawned, optionally generate one or more child processes, and eventually die. Each process is an independent entity to which system resources (CPU time, memory, etc.) are allocated. And each processes is executed in a separate address space. Thus, one process cannot access variables or data in another process. If two processes want to communicate, they have to use inter-process communication mechanisms like files, pipes, or sockets. Context switching between processes is difficult.
The term thread is short for a thread of execution, and refers to a particular execution path through a process. Threads and processes work differently on different operating systems but, in general, multiple threads can share the state information of a single process. Since threads share memory and other system resources, they can communicate directly via variables and other memory structures. And because threads can share a single address space, context switching between threads is faster than switching between processes.

3 Interfaces do not have constructors, no non-static fields, and no static methods. All fields in an interface are public, static and final.

4. All abstract classes have a constructor. They also can have a non-abstract parent. If the non-abstract parent has a non-abstract method, the abstract child class can make the method abstract.

5. There can be memory leaks in Java. Consider a Swing app. The user opens a GUI which stores an object in a static HashMap. When the GUI shuts down the object is not removed from the HashMap. Voila we have a memory leak. One way to handle this is to use WeakReferences and WeakHashMap
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
How long do you think you can keep this information in your memory while also continuosly learning new information and technologies?
Luke Kolin
Ranch Hand

Joined: Sep 04, 2002
Posts: 336
Originally posted by James Clark:
How long do you think you can keep this information in your memory while also continuosly learning new information and technologies?


Easily. Have you forgotten how to tie your shoes or the way home from work one day because you learned a lot that day?

Cheers!

Luke
Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1874
Originally posted by James Clark:
How long do you think you can keep this information in your memory while also continuosly learning new information and technologies?


Employers(sepcially in India) always look for the keywords/textbook definitions.Recently in telephonic interview I was asked definitions of Thread and Process.When I told about java thread/examples, he was not happy.He was precisely looking for text book definition:"Thread is a lightweight process".After telling that he was convinced.
So even if you are learning new technologies,remembering textbook definitions are must if planning for job change.



MH
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38763
    
  23
Originally posted by Arjun Shastry:
. . . So even if you are learning new technologies,remembering textbook definitions are must if planning for job change.


Presumably that means use of correct jargon; saying "non-abstract parent" instead of "concrete superclass" would be a bad move.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Employers(sepcially in India) always look for the keywords/textbook definitions.


We would rather hire software developers that can produce clean code and can articulate expierence and knowledge effectively.

The ability to recite memorized definitions cannot be interpreted as the ability to acutally effectively use the technologies in a real-world situation. To do so is nonsensical, in my opinion.

This way of thinking leans to individuals that are attempting to hide inexperience or present false (phony) qualifications to get a job or a contract.

The ability to copy and paste Internet code examples and continously search for answers with Google is NOT a software engineering skill.

The ability to recite definitons is also NOT software engineering skill. Employers that search for the best "recital" skills typically fail at hiring the best candidates. Beware!

No offense intended to anyone.
[ December 13, 2008: Message edited by: James Clark ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187


This is a poor definition of what a thread is. And, I doubt it appears as a definition in any text book this way. "lightweight" is not a real word and in the phrase below it is slang. The phrase implies that a thread is a process. However, there are significant differences between them that this so-called "definition" does not address.

However, the phrase is easy for recruiters to memorize. And it is easy for interview crammers to memorize also.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18824
    
  40

Originally posted by James Clark:

This is a poor definition of what a thread is. And, I doubt it appears as a definition in any text book this way. "lightweight" is not a real word and in the phrase below it is slang. The phrase implies that a thread is a process. However, there are significant differences between them that this so-called "definition" does not address.

However, the phrase is easy for recruiters to memorize. And it is easy for interview crammers to memorize also.



To make matters worst, some operating systems define a "lightweight process" as a particular type of thread. For example, Solaris may use multiple levels of threads -- a thread is a path of execution at the user level, that may be assigned to a LWP, at the kernal level. In this case, to say it's a LWP isn't entirely correct.

Henry
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
3 Interfaces do not have constructors, no non-static fields, and no static methods. All fields in an interface are public, static and final.

Since interface is not a class, I understand that it doesnot have any constructors.
But all its fields are public , static and final



so here the property of the interface legs is implicitly final & static.
1)Since it is static does it means that an implicit synchronisation is applied on that field i.e in a multi-thread process not more than one thread will be able to access that property.

2) Why they have made the interface's methods as non-static , if they could have made it as static , then also it could have been over-ridden.
Right!

Kindly clarify!
Regards.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Any replies?
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3219
Ramya, If you learn the following OO concepts, your doubts will be clear

-- inheritance
-- interface inheritance
-- polymorphism
-- composition

Also learn instance variables, static variables, static key word and synchronization.

You will find the answers to the above questions. When you find your answers yourself, you will remember it better.
victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
Ramya - with regard to your questions

1. synchronization is not required to access the field; no need to since it
is a final field nobody can change it.

2. I really do not have a good explanation for why interface methods are
non-static.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interview Questions