Pages

Sunday, September 15, 2013

Java Interview questions on exceptional handling

1.)What happens if main() is written with out String args[]?
--The code compiles but JVM cannot run it,as it cannot see the main() with String args[]

2.)What are checked exceptions?
--Exceptions that are checked by compiler at the compilation time are called as checked exceptions.

3.)What are unchecked exceptions?
--Exceptions that are checked by JVM are called as unchecked exceptions.

4.)What is Throwable?
--Throwable is a class that represents  all errors and exceptions that occur in java

5.)What is the superclass for all exceptions?
--Exception is the superclass for all the exceptions.

6)What is the difference between exception and an error?
--Exception is a situation which can be handled using try catch
--Error cannot be handled by the programmer and leads to abnormal program termination.
    Ex: OutOfMemory 

7)Difference between throws and throw?
--throws clause is used when the programmer does not want to handle the exception and throw it out of method.
--throw clause is used when the programmer wants to throw an exception explicitly and wants to handle it using catch block.

8)Can we rethrow an exception??
--Yes ,we can rethrow an exception from catch block to another class where it can be handled

Points on exceptional handling

  •  Exceptions  can be handled using try and catch blocks.
  • A try block can be followed with any number of catch blocks.
  • Statements are not allowed in between try and catch blocks
  • It is possible to handle multiple exceptions using  multiple catch blocks
  • Catch block cannot  exist independently ..it should be preceded with a  try block whereas try block need not be followed compulsorily by catch block ,a finally block may follow it.
  •  Nested try blocks are supported in java


Saturday, September 14, 2013

how to install eclipse IDE

  • Go to http://www.eclipse.org/downloads/ and select the version of eclipse you want to install.
  • I recommend Eclipse IDE for EE developers which has many perspectives like EE , java  etc.
  • Based on your system OS configuration choose 32 bit or 64 bit respectively
  • Click on the windows 32 bit or windows 64 bit (For Windows users) to download.
  • It downloads eclipse as a zip file.
  • Extract the zip file into a folder For Ex:C:\eclipse
  • Go to eclipse folder ,you can see the eclipse application type file.See the snapshot below.



  • Click on it to start the eclipse .
  • Give the workspace location to start 
Happy programming  :)




How to format code in Eclipse

Step 1:
---------
  • Highlight the part of code you wish to format
  • Click Ctrl-Shift-F to format the code

Step 2:
--------
  •  Highlight the part of code you wish to format
  • Go to Source tab beside Edit tab in eclipse and select Format

 Step 1 is just a key board Shortcut:)