Java Environment
Java Environment
Includes a large number of development tools and hundreds of classes and methods.
The development tools are the part of the system known as JDK (Java Development Kit).
The classes and methods are the part of Java Standard library (JSL) known as Application
Programming Interface(API)
I. JDK
JDK is a superset of JRE, and contains everything that is in JRE, plus tools such as the
compilers and debuggers necessary for developing applets and applications.
JDK (Java Development Kit) is a software development kit to develop applications
in Java. When you download JDK, JRE is also downloaded, and don't need to download
it separately. In addition to JRE, JDK also contains number of development tools
(compilers, JavaDoc, Java Debugger etc).
If you want to develop Java applications, download JDK.
COMPONENTS OF JAVA DEVELOPMENT KIT (JDK)
javac is the Compiler used in Java, javac tool it is location in the /bin folder of the JDK
installation directory. Java Compiler reads all the class informations, interfaces and the other
codes written in Java programming language and compiles them into byte code (.class file).
javac <<filename.java>>
2. Java interpreter (java)
command is used to compile a Java program, it creates a class file which can be run by using
java command.
Example:
c:java TestFile.class
javap is also located in the /bin folder of the JDK installation directory. Java Disassembler
disassembles one or more classes which is passed. The javap command prints
the package, protected and public fields, and methods of the classes passed to it.
The javap command prints its output to stdout.
Java Debugger (jdb) is a command-line debugger for Java classes it helps us in debugging our
Java code. In order to start debugging we simply need to give the class name after jdb
Jdb Sample
Output :
c:\JIP>jdb Sample
Initializing jdb ...
> run
run Sample
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Hello World!!
javah command generates C header and source files (.h file) which is needed to implement
native methods. The generated header and source files can be used by C programs to reference
an object’s instance variables from native source code. The package name is added in the header
of the generated file, package name and Java Class name is seperated by underscore (_)
delimiter.
javah Sample
Sample.h file will be created in the current directory the content will look like below
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_javainterviewpoint_Sample */
#ifndef _Included_com_javainterviewpoint_Sample
#define _Included_com_javainterviewpoint_Sample
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif
javadoc tool parses the declarations and documentation comments in the Java source files and
produces a corresponding set of HTML pages. It describes public, default and protected
classes, interfaces, constructors, methods, and fields except anonymous inner classes.
The javadoc tool can be directly called on a single or multiple files, however using the below
three ways you can run the javadoc tool without specifying the file name.
Class Library
Java contains an extensive library of pre-written classes you can use in your programs. These
classes are divided into groups called packages.
java.applet
java.awt
java.awt.datatransfer
java.awt.event
java.awt.image
java.awt.peer
java.beans
java.io
java.lang
java.lang.reflect
java.math
java.net
java.rmi
java.rmi.dgc
java.rmi.registry
java.rmi.server
java.security
java.security.acl
java.security.interfaces
java.sql
java.text
java.util
java.util.zip
III. JVM?
JVM (Java Virtual Machine) is an abstract machine that enables your computer to run a
Java program.
When you run the Java program, Java compiler first compiles your Java code to
bytecode. Then, the JVM translates bytecode into native machine code (set of
instructions that a computer's CPU executes directly).
Java is a platform-independent language. It's because when you write Java code, it's
ultimately written for JVM but not your physical machine (computer). Since, JVM
executes the Java bytecode which is platform independent, Java is platform-independent.
Java Virtual Machine is important part of the JRE, which actually runs the programs
(.class files), it uses the java class libraries and the run-time libraries to execute those
programs. Every operating system(OS) or platform will have a different JVM.
1. Class Loader Subsystem – Loading (loads the required class/jar files), Linking (assigning
references and verification) and Initialization (initializing static variable and execution
of static block )
2. Runtime Data Area – Provides memory for all variables, operators etc.
3. Execution Engine – Performs the interpretation and execution
What is JIT Compiler in Java ?
Before knowing about JIT Compiler we need to have some basic knowledge about how
anInterpreter works in Java. Interpreter Reads the bytecode interprets it and executes it one by
one. The interpreter interprets the Java bytecode faster but executes slowly. The disadvantage of
an interpreter is that when one method is called multiple times,each and every time interpretation
is required.
JIT Compiler helps us to overcome the disadvantage of the Interpreter ( the single method is
interpreted multiple times for multiple calls ), The Execution Engine uses Interpreter to read and
interprets the bytecode but when it came across repeated code it uses JIT compilerwhich
compiles the entire Java bytecode once and changes it to native code. This native code will be
used directly from next time onwards for repeated method calls.