Collections of Java Interview Questions

What  are  checked  and  unchecked  exceptions?

Java  defines  two  kinds  of  exceptions  :

Checked exceptions : Exceptions that inherit from the Exception class are checked exceptions. Client code has to handle the checked exceptions thrown by the API, either in a catch clause or by forwarding it outward with the throws clause. Examples - SQLException, IOxception

Unchecked exceptions : RuntimeException also extends from Exception. However, all of the exceptions that inherit from RuntimeException get special treatment. There is no requirement for the client code to deal with them, and hence they are called unchecked exceptions. Example Unchecked exceptions are NullPointerException, OutOfMemoryError, DivideByZeroException typically, programming errors.
 

What  is  a  user  defined  exception?

User-defined  exceptions  may  be  implemented  by

* defining  a  class  to  respond  to  the  exception  and 

* embedding a throw statement in the try block where the exception can occur or declaring that the method throws the exception (to another method where it is handled). 

The throw statement is used to signal the occurance of the exception within a try block. Often, exceptions are instantiated in the same statement in which they are thrown using the syntax.

throw  new  MyException("I  threw  my  own  exception.")

To handle the exception within the method where it is thrown, a catch statement that handles MyException, must follow the try block. If the developer does not want to handle the exception in the method itself, the method must pass the exception using the syntax:

public  myMethodName()  throws  MyException
 

What  is  the  difference  between  C++  &  Java?

Well as Bjarne Stroustrup says "..despite the syntactic similarities, C++ and Java are very different languages. In many ways, Java seems closer to Smalltalk than to C++..". Here are few I discovered:

* Java  is  multithreaded 

* Java  has  no  pointers 

* Java  has  automatic  memory  management  (garbage  collection) 

* Java is platform independent (Stroustrup may differ by saying "Java is a platform" 

* Java  has  built-in  support  for  comment  documentation 

* Java  has  no  operator  overloading 

* Java  doesn  t  provide  multiple  inheritance 

* There  are  no  destructors  in  Java 
 
 

What  are  statements  in  JAVA ?

*expression statements-Assignment expressions,Any use of ++ or --,Method calls,Object creation

expressions

*declaration statement-Varible declaration. *control flow statements-For and if statment.
 

What  is JAR  file?

JavaARchive files are a big glob of Java classes, images, audio, etc., compressed to make one simple, smaller file to ease Applet downloading. Normally when a browser encounters an applet, it goes and downloads all the files, images, audio, used by the Applet separately. This can lead to slower downloads.
 

What  is JNI?

JNI is an acronym of Java Native Interface. Using JNI we can call functions which are written in other languages from Java. Following are its advantages and disadvantages.

Advantages:

* You want to use your existing library which was previously written in other language. 

* You  want  to  call  Windows  API  function. 

* For  the  sake  of  execution  speed. 

* You want to call API function of some server product which is in c or c++ from java client. 

Disadvantages: 

* You  can  t  say  write  once  run  anywhere. 

* Difficult  to  debug  runtime  error  in  native  code. 

* Potential  security  risk. 

* You  can  t  call  it  from  Applet. 
 

Why there are some null interface in java ? What does it mean ? Give me some null interfaces in JAVA?

Null interfaces act as markers..they just tell the compiler that the objects of this class need to be treated differently..some marker interfaces are : Serializable, Remote, Cloneable
 

Is synchronised a modifier, indentifier? What is  it?

It's a modifier. Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.