Lifecycle of a Java Program

The above figure explains the lifecycle of a Java Program. In words, the figure can be explained as:

  1. A Java program is written using either a Text Editor like Textpad or an IDE like Eclipse and is saved as a .java file. (Program.java)
  2. The .java file is then compiled using Java compiler and a .class file is obtained from it. (Program.class)
  3. The .class file is now portable and can be used to run this Java program in any platform.
  4. Class file (Program.class) is interpreted by the JVM installed on a particular platform. JVM is part of the JRE software

About JVM

java virtual machine(jvm) is a software. which is machine dependent. every machine has a different jvm but the interpreting code is same,
which help for running any java programs.
it is a interpreter

jvm work is following types

    • class loading
    • byte code varification
    • give memory of function one time
    • run the garbage collector
    • generate a exception
  • create a buffer memory for any object

it can secure our java prog. from any unauthorized code.

How java work

As with many other programming languages, Java uses a compiler to convert human-readable source code into executable programs. Traditional compilers produce code that can be executed by specific hardware; for example, a Windows 95 C++ compiler creates executable programs that work with Intel x86–compatible processors. In contrast, the Java compiler generates architecture-independent bytecodes. The bytecodes can be executed by only a Java Virtual Machine (VM), which is an idealized Java architecture, usually implemented in software rather than hardware.To execute Java bytecodes, the VM uses a class loader to fetch the bytecodes from a disk or a network. Each class file is fed to a bytecode verifier that ensures the class is formatted correctly and will not corrupt memory when it is executed. The byte-code verification phase adds to the time it takes to load a class, but it actually allows the program to run faster because the class verification is performed only once, not continuously as the program runs.The execution unit of the VM carries out the instructions specified in the byte-codes. The simplest execution unit is an interpreter, which is a program that reads the bytecodes, interprets their meaning, and then performs the associated function. Interpreters are generally much slower than native code compilers because they continuously need to look up the meaning of each bytecode during execution. Fortunately, there is an elegant alternative to interpreting code, called Just-in-Time (JIT) compilation.The JIT compiler converts the bytecodes to native code instructions on the user’s machine immediately before execution. Traditional native code compilers run on the developer’s machine, are used by programmers, and produce nonportable executables. JIT compilers run on the user’s machine and are transparent to the user; the resulting native code instructions do not need to be ported because they are already at their destination. Figure 1.5 illustrates how JIT compilers work. In the example, both a Macintosh and a Windows PC receive identical bytecodes, and each client performs a local JIT compilation

History of Java

In 1990, Sun Microsystems began a project called Green to develop software for consumer electronics. Sun is best known for its popular Unix workstations but has also engineered several popular software packages, including the Solaris operating system and the Network File System (NFS). James Gosling, a veteran of classic network software design, was assigned to the new Green project.
Gosling began writing software in C++ for embedding into such items as toasters, VCRs, and Personal Digital Assistants (PDAs). The embedded software makes appliances more intelligent, typically by adding digital displays or by using artificial intelligence to better control the mechanisms. However, it soon became apparent to Gosling that C++ was the wrong tool for the job. C++ is flexible enough to control embedded systems, but it is susceptible to bugs that can crash the system. In particular, C++ uses direct references to system resources and requires the programmer to keep track of how these resources are managed, which is a significant burden on programmers. This burden of resource management is a barrier to writing reliable, portable software, and it is a serious problem for consumer electronics. After all, computer users have come to expect their software to have some bugs, but few expect their toasters to crash.

About java

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems’ Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture.
The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun made available most of their Java technologies as free software under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java and GNU Classpath.