[go: up one dir, main page]

0% found this document useful (0 votes)
41 views12 pages

Java Environment

java environment

Uploaded by

Kongu B K Riot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views12 pages

Java Environment

java environment

Uploaded by

Kongu B K Riot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

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)

1. Java Compiler (javac)

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

3. Java Disassembler (javap)

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.

javap <<.class file1>> <<.class file2>>


Output :

javap Sample will give the below output

Compiled from "Sample.java"


public class Sample
{
java.lang.String name;
public Sample(java.lang.String);
public void show();
public static void main(java.lang.String[]);
}

4. Java Debugger (jdb) :

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 <<class name>>


Once jdb is initialized we can give any of the jdb basic commands such as run, cont, print etc…
You can get the complete list of jdb commands <– here. On running jdb over the
above Sample code we will get output like below

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!!

The application exited


}

5. Java Header File Generator (javah) :

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 <<.class file1>> <<.class file2>>


Usually javah command creates a header file for each class listed on the command line and puts
the files in the current directory.

When we run javah for our Sample class

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

6. Java Documentation (javadoc) :

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.

javadoc <<source file1>> <<source file2>>

1. Giving the package name itself


2. Using -subpackage option of javadoc
3. Using * wildcard character in front of source filename (*.java)

7. Java Applet Viewer:


This is used to view the Java applets. The appletviewer command connects to the documents or
resources designated by urls and displays each applet referenced by the documents in its own
window. Note: if the documents referred to by urls do not reference any applets with the
OBJECT, EMBED, or APPLET tag, then appletviewer does nothing. For details on the HTML
tags that appletviewer supports,
II. JRE
JRE (Java Runtime Environment) is a software package that provides Java class libraries, along
with Java Virtual Machine (JVM), and other components to run applications written in Java
programming. JRE is the superset of JVM.

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.

The Java 1.1 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

Each package defines a number of classes, interfaces, exceptions, and errors.


Packages can be split into sub-packages. for example, the java.lang package has a sub-package
called java.lang.reflect. These are really completely different packages. A class in a sub-package
has no more access to a class in the parent package (or vice versa) than it would to a class in a
completely different package.

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.

JVM has the below three major components.

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.

Application Programming Interface (API)


 An application programming interface (API), in the context of Java, is a collection of
prewritten packages, classes, and interfaces with their respective methods, fields
and constructors. Similar to a user interface, which facilitates interaction between
humans and computers, an API serves as a software program interface facilitating
interaction.
 In Java, most basic programming tasks are performed by the API’s classes and packages,
which are helpful in minimizing the number of lines written within pieces of code.
RELATIONSHIP BETWEEN JVM, JRE, AND JDK.

Process of building and running Java application programs


To create a java program,we need to create a source code file using a text editor. The source code
is then complied using the javac compiler and executed using the Java interpreter java. The java
debugger jdb is used to find errors, if any in the source code. A compiled Java program can be
converted into a source code with the help of java disassembler javap.

The Java Program Life Cycle


Java requires the source code of your program to be compiled first. It gets converted to
either machine-specific code or a byte code that is understood by some run-time engine or a java
virtual machine.
Not only will the program be checked for syntax errors by a Java compiler, but some
other libraries of Java code can be added (linked) to your program after the compilation is
complete (deployment stage).
Step1 : Create a source document using any editor and save file as .java (e.g. abc.java)
Step2 : Compile the abc.java file using “javac” command or eclipse will compile it
automatically.
Step3 : Byte Code (abc.class) will be generated on disk.
Step4 : This byte code can run on any platform or device having JVM (java.exe convert byte
code in machine language)
Let’s get familiar with various terminologies used by java programmers.
JDK (Java Development Kit) : JDK contains JRE along with various development tools like
Java libraries, Java source compilers, Java debuggers, bundling and deployment tools
JRE (Java Runtime Environment) : It is part of JDK but can be used independently to run any
byte code (compiled java program). It can be called as JVM implementation.
JVM (Java Virtual Machine) : ‘JVM’ is software that can be ported to various hardware
platforms. JVM will become an instance of JRE at runtime of java program. Byte codes are the
machine language for the JVM. Like a real computing machine, JVM has an instruction set
which manipulates various memory areas at run time. Thus for different hardware platforms, one
has corresponding the implementation of JVM available as vendor supplied JREs.
Java API (Application Programming Interface) : Set of classes’ written using Java
programming language which runs on JVM. These classes will help programmers by providing
standard methods like reading from the console, writing to the console, saving objects in data
structure etc.

Advantages of Java programming language


 Built-in support for multi-threading, socket communication, and memory management
(automatic garbage collection).
 Object Oriented (OO).
 Better portability than other languages across operating systems.
 Supports Web-based applications (Applet, Servlet, and JSP), distributed applications
(sockets, RMI, EJB etc.) and network protocols (HTTP, JRMP etc.) with the help of
extensive standardized APIs (Application Programming Interfaces)

You might also like