Unit1 Introduction JAVa
Unit1 Introduction JAVa
CIE-306T
-By Miss Sakshi Jha
Assistant Professor
Department of Computer Science and Engineering
SYLLABUS
OVERVIEW OF JAVA
• Java programming language was originally developed by Sun Microsystems which was initiated by James
Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]).
• With the advancement of Java and its widespread popularity, multiple configurations were built to suit
various types of platforms. For example: J2EE for Enterprise Applications, J2ME for Mobile Applications.
• The new J2 versions were renamed as Java SE, Java EE, and Java ME respectively. Java is guaranteed to
be Write Once, Run Anywhere.
• Java is a technology consisting of both a programming language and a software platform. To create an
application using Java, you need to download the Java Development Kit (JDK), which is available for
Windows, macOS, and Linux. You write the program in the Java programming language, then a compiler
turns the program into Java bytecode—the instruction set for the Java Virtual Machine (JVM) that is a part of
the Java runtime environment (JRE). Java bytecode runs without modification on any system that supports
JVMs, allowing your Java code to be run anywhere.
• The Java software platform consists of the JVM, the Java API, and a complete development environment. The
JVM parses and runs (interprets) the Java bytecode. The Java API consists of an extensive set of libraries
including basic objects, networking and security functions; Extensible Markup Language (XML) generation;
and web services. Taken together, the Java language and the Java software platform create a powerful, proven
technology for enterprise software development.
CHARACTERISTICS OF JAVA
• Object Oriented − In Java, everything is an Object. Java can be easily extended since it is based on the Object model.
• Platform Independent − Unlike many other programming languages including C and C++, when Java is compiled, it is not
compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web
and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.
• Simple − Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master.
• Secure − With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on
public-key encryption.
• Architecture-neutral − Java compiler generates an architecture-neutral object file format, which makes the compiled code
executable on many processors, with the presence of Java runtime system.
• Portable − Being architecture-neutral and having no implementation dependent aspects of the specification makes Java portable.
Compiler in Java is written in ANSI C with a clean portability boundary, which is a POSIX subset.
• Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and
runtime checking.
• Multithreaded − With Java's multithreaded feature it is possible to write programs that can perform many tasks simultaneously.
This design feature allows the developers to construct interactive applications that can run smoothly.
• Interpreted − Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development
process is more rapid and analytical since the linking is an incremental and light-weight process.
• High Performance − With the use of Just-In-Time compilers, Java enables high performance.
• Distributed − Java is designed for the distributed environment of the internet.
• Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java
programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-
time.
C++ V/S JAVA
Comparison Index C++ Java
Platform-independent C++ is platform-dependent. Java is platform-independent.
Mainly used for C++ is mainly used for system programming. Java is mainly used for application programming. It is widely used in
Windows-based, web-based, enterprise, and mobile applications.
Design Goal C++ was designed for systems and applications programming. It was Java was designed and created as an interpreter for printing systems
an extension of the C programming language. but later extended as a support network computing. It was designed to
be easy to use and accessible to a broader audience.
Goto C++ supports the goto statement. Java doesn't support the goto statement.
Multiple inheritance C++ supports multiple inheritance. Java doesn't support multiple inheritance through class. It can be
achieved by using interfaces in java.
Operator Overloading C++ supports operator overloading. Java doesn't support operator overloading.
Pointers C++ supports pointers. You can write a pointer program in C++. Java supports pointer internally. However, you can't write the pointer
program in java. It means java has restricted pointer support in java.
Compiler and Interpreter C++ uses compiler only. C++ is compiled and run using the compiler Java uses both compiler and interpreter. Java source code is converted
which converts source code into machine code so, C++ is platform into bytecode at compilation time. The interpreter executes this
dependent. bytecode at runtime and produces output. Java is interpreted that is
why it is platform-independent.
Call by Value and Call by C++ supports both call by value and call by reference. Java supports call by value only. There is no call by reference in java.
reference
Structure and Union C++ supports structures and unions. Java doesn't support structures and unions.
Thread Support C++ doesn't have built-in support for threads. It relies on third-party Java has built-in thread support.
libraries for thread support.
Documentation comment C++ doesn't support documentation comments. Java supports documentation comment (/** ... */) to create
documentation for java source code.
Virtual Keyword C++ supports virtual keyword so that we can decide whether or not to Java has no virtual keyword. We can override all non-static methods by
override a function. default. In other words, non-static methods are virtual by default.
unsigned right shift >>> C++ doesn't support >>> operator. Java supports unsigned right shift >>> operator that fills zero at the
top for the negative numbers. For positive numbers, it works same like
>> operator.
Inheritance Tree C++ always creates a new inheritance tree. Java always uses a single inheritance tree because all classes are the
child of the Object class in Java. The Object class is the root of the
inheritance tree in java.
Hardware C++ is nearer to hardware. Java is not so interactive with hardware.
Object-oriented C++ is an object-oriented language. However, in the C language, a Java is also an object-oriented language. However, everything (except
single root hierarchy is not possible. fundamental types) is an object in Java. It is a single root hierarchy as
everything gets derived from java.lang.Object.
In Java, any line starting with // is a
comment. Comments are intended for
JAVA PROGRAM users reading the code to understand the
intent and functionality of the program.
It is completely ignored by the Java
compiler (an application that translates
// Your First Program Java program to Java bytecode that
class HelloWorld computer can execute).
2. An implementation Its implementation is known as JRE (Java Runtime Environment). Fig. Relationship between JDK,JVM & JRE
3. Runtime Instance Whenever you write java command on the command prompt to run
the java class, an instance of JVM is created.
4. Loads code
5. Verifies code
6. Executes code
• Java processor can be implemented as software! It is implemented as a program that reads the bytecodes and performs the operations they
specify. This is another type of interpreter. Some interpreters run source code written in a high level language like Basic; others (like the Java
interpreter) run bytecodes.
• This second type of interpreter is sometimes called an emulator because it emulates hardware, but in fact is software. A Java bytecode
interpreter can be created for any computer system. Once you have a Java compiler and a Java interpreter you can run any Java program no
matter what type of computer you have.
• JVM stands for Java Virtual Machine and is the part of a Java system which emulates a platform independent system. It hides all aspects of the
underlying system from the Java code. This allows Java code to run on completely different platforms such as an AS/400 or a Sun workstation
as easily as it would on a PC or Macintosh. Normal software would have to have specific versions built for each different machine, especially
when different CPU’s are involved. In essence the JVM replaces the CPU specifics and OS tasks with a generic Java CPU and Java OS that
works the same on any machine.
• The designers of Java chose to use a combination of compiling and interpreting. Programs written in Java are compiled into machine language,
but it is a machine language for a computer that doesn't really exist. This so-called "virtual" computer is known as the Java Virtual Machine, or
JVM. The machine language for the Java Virtual Machine is called Java bytecode. There is no reason why Java bytecode couldn't be used as
the machine language of a real computer, rather than a virtual computer. But in fact the use of a virtual machine makes possible one of the
main selling points of Java: the fact that it can actually be used on any computer. All that the computer needs is an interpreter for Java
bytecode. Such an interpreter simulates the JVM in the same way that a C64 emulator simulates a Commodore 64 computer. (The term JVM is
also used for the Java bytecode interpreter program that does the simulation, so we say that a computer needs a JVM in order to run Java
programs. Technically, it would be more correct to say that the interpreter implements the JVM than to say that it is a JVM.)
JRE (Java Runtime Environment)
•Case 1:
• In case 1 you can see that we are at the intepretation phase (Step 5 of the overall
program execution). Lets assume we have 5 lines which are supposed to be
interpreted to their corresponding machine code lines. So as you can see in the Case
1 there is no JIT involved. thus the interpreter converts each line into its
corresponding machine code line. However if you notice the last 2 lines are the same
(consider it a redundant line inserted by mistake). Clearly that line is redundant and
does not have any effect on the actual output but yet since the interpreter works line
by line it still creates 5 lines of machine code for 5 lines of the bytecode.
• Now this is inefficient right? lets see case 2
•Case 2:
• In case 2 we have the JIT compiler. Now before the bytecode is passed onto the
interpreter for conversion to machine code, the JIT compiler scans the full code to
see if it can be optimized. As it finds the last line is redundant it removes it from the
bytecode and passes only 4 lines to the interpreter thus making it
more efficient and faster as the interpreter now has 1 line less to interpret.
• So this is how JIT compiler speeds up the overall execution process.
This was just one scenario where JIT compiler can help in making the execution process fast and
efficient. There are other cases like inclusion of only those packages needed in the code, code
optimizations, redundant code removal etc which overall makes the process very fast and
efficient. Also different JITs developed by different companies work differently and JIT
compilers are an optional step and not invoked every time.
So this was the complete Execution Process of Java Program in Detail with the Working of JIT
Compiler.