• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Interview Questions

 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and it certainly has nothing to do with the SCJP. Off to Jobs Discussion it is.
 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd recommend taking a look at all previous attempts to do this.

--Mark
 
Author
Posts: 3473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
victor kamat
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How long do you think you can keep this information in your memory while also continuosly learning new information and technologies?
 
Ranch Hand
Posts: 343
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 1907
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any replies?
 
arulk pillai
Author
Posts: 3473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic