JDK(Java Development Kit):
Java Developer Kit contains tools needed to develop the Java
programs, and JRE to run the programs. The tools include compiler (javac.exe),
Java application launcher (java.exe), Appletviewer, etc…
Compiler converts java code into byte code. Java application
launcher opens a JRE, loads the class, and invokes its main method.
You need JDK, if at all you want to write your own programs, and
to compile them. For running java programs, JRE is sufficient.
JRE is targeted for execution of Java files
i.e. JRE = JVM + Java
Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries.
JDK is mainly targeted for java development. I.e. You can create
a Java file (with the help of Java packages), compile a Java file and run a
java file.
JRE(Java Runtime
Environment):
Java Runtime Environment contains JVM, class libraries, and
other supporting files. It does not contain any development tools such as
compiler, debugger, etc. Actually JVM runs the program, and it uses the class
libraries, and other supporting files provided in JRE. If you want to run any
java program, you need to have JRE installed in the system
The Java Virtual Machine provides a platform-independent way of
executing code; That mean compile once in any machine and run it any where(any
machine).
JVM(Java Virtual Machine):
The JVM interprets
the byte code into the machine code depending upon the underlying
operating system and hardware combination. It is responsible for all the things
like garbage collection, array bounds checking, etc… Java Virtual Machine
provides a platform-independent way of executing code.
What is JIT Compiler:
In Java you have to write and compile a
program only once. The Java on any platform will interpret the compiled
bytecode into instructions understandable by the particular processor. However
java virtual machine handles only one bytecode instruction at a time that makes
execution slow. But Using the Java just-in-time compiler at the particular
system platform compiles the bytecode into the particular system code. After
the code has been recompiled by the JIT compiler, it will usually run more
quickly on the computer.
what is Class Loader:
how many memory areas
allocated by JVM:
what is platform
independent and Platform dependent:
Exception Handling:
what is an Exception
An Exception can be anything which interrupts the normal flow of the program. When an exception occurs program processing gets terminated and doesn’t continue further. In such cases we get a system generated error message. The good thing about exceptions is that they can be handled
Exception Handling:
what is an Exception
An Exception can be anything which interrupts the normal flow of the program. When an exception occurs program processing gets terminated and doesn’t continue further. In such cases we get a system generated error message. The good thing about exceptions is that they can be handled
How to handling Exception:
To handle Eceptions java suports five keywords
1)throw
2)throws
3)try
4)catch
5)finally
Example Program to generate Excepton
This Example generate following posible 3 exceptions
1)ArrayIndexOutOfBoundsException------------------------
2)NumberFormatException ---------------------------------
3)ArithmeticException --------------------------------------
class Edivision
{
public static void main(String args[])
{
int a=Integer.parseInt(args[0]);
int b=Integer.parseInt(args[1]);
int c=a/b;
System.out.println("'result"+c);
}
}
output:
Example Program to handling the Exception
To handle Exception by using try and catch block
class Edivision
{
public static void main(String args[])
{
try
{
int a=Integer.parseInt(args[0]);
int b=Integer.parseInt(args[1]);
int c=a/b;
System.out.println("'result"+c);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("please give two values");
}
catch(NumberFormatException e)
{
System.out.println("please enter only numbers");
}
catch(ArithmeticException e)
{
System.out.println("please do not enter second value is zero");
}
}
}
output:
No comments:
Post a Comment