0% found this document useful (0 votes)
34 views8 pages

Java

Java is a high-level, object-oriented programming language developed by Sun Microsystems, known for its portability and widespread use in various applications. It has four main editions: Java SE, Java EE, Java ME, and JavaFX, each catering to different development needs. The Java environment includes the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM), which together facilitate the development and execution of Java applications.

Uploaded by

anilajose
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)
34 views8 pages

Java

Java is a high-level, object-oriented programming language developed by Sun Microsystems, known for its portability and widespread use in various applications. It has four main editions: Java SE, Java EE, Java ME, and JavaFX, each catering to different development needs. The Java environment includes the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM), which together facilitate the development and execution of Java applications.

Uploaded by

anilajose
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

INTRODUCTION TO JAVA

Java
Java is a high-level programming language originally developed by James Gosling at Sun Microsystems and
released in 1995 as a core component of Sun Microsystems’ Java [Link] language derives much of its
syntax from C and C++. Java is a general purpose, concurrent, class-based, object-oriented language. It is
intended to let application developers “write once, run anywhere”. Java is currently one of the most popular
programming languages in use, and is widely used from application software to web applications.

Java Platforms / Editions


There are 4 platforms or editions of Java:
1) Java SE (Java Standard Edition): It is a Java programming platform. It includes Java programming APIs
such as [Link], [Link], [Link], [Link], [Link], [Link] etc. It includes core topics like OOPs,
String, Regex, Exception, Inner classes, Multithreading, I/O Stream, Networking, AWT, Swing, Reflection,
Collection, etc.
2) Java EE (Java Enterprise Edition): It is an enterprise platform which is mainly used to develop web and
enterprise applications. It is built on the top of the Java SE platform. It includes topics like Servlet, JSP,
Web Services, EJB, JPA, etc.
3) Java ME (Java Micro Edition): It is a micro platform which is mainly used to develop mobile
applications.
4) JavaFX: It is used to develop rich internet applications. It uses a light-weight user interface API.

Versions
From the first version released in 1996 to the latest version 12 released in 2019, the Java platform has been
actively being developed for about nearly 24 years. Many changes and improvements have been made to the
technology over the years. The following table summarizes all versions of Java SE from its early days to the
latest.

Version Name Code Name Release Date

JDK 1.0 Oak January 1996

JDK 1.1 (none) February 1997

J2SE 1.2 Playground December 1998

J2SE 1.3 Kestrel May 2000

J2SE 1.4 Merlin February 2002

J2SE 5.0 Tiger September 2004

JDK 6 Mustang December 2006

JDK 7 Dolphin July 2011

JDK 8 March 2014


JDK 9 September, 21st 2017

JDK 10 March, 20th 2018

JDK 11 September, 25th 2018

JDK 12 March, 19th 2019

JDK 13 September, 10th 2019

From the table above we can see that the naming and the version number have been changing over times:
 Versions 1.0 and 1.0 are named as JDK (Java Development Kit).
 From versions 1.2 to 1.4, the platform is named as J2SE (Java 2 Standard Edition).
 From versions 1.5, Sun introduces internal and external versions. Internal version is continuous from
previous ones (1.5 after 1.4), but the external version has a big jump (5.0 for 1.5).
Application
According to Sun, 3 billion devices run Java. There are many devices where Java is currently used. Some of
them are as follows:
 Desktop Applications such as acrobat reader, media player, antivirus, etc.
 Web Applications such as [Link], [Link], etc.
 Enterprise Applications such as banking applications.
 Mobile
 Embedded System
 Smart Card
 Robotics
 Games, etc.
Types of Java Applications
There are mainly 4 types of applications that can be created using Java programming:
1) Standalone Application: Standalone applications are also known as desktop applications or window-based
applications. These are traditional software that we need to install on every machine. Examples of
standalone application are Media player, antivirus, etc. AWT and Swing are used in Java for creating
standalone applications.
2) Web Application: An application that runs on the server side and creates a dynamic page is called a web
application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc. technologies are used for creating
web applications in Java.
3) Enterprise Application: An application that is distributed in nature, such as banking applications, etc. is
called enterprise application. It has advantages of the high-level security, load balancing, and clustering. In
Java, EJB is used for creating enterprise applications.
4) Mobile Application: An application which is created for mobile devices is called a mobile application.
Currently, Android and Java ME are used for creating mobile applications.

Features of Java
The primary objective of Java programming language creation was to make it portable, simple and secure
programming language. Apart from this, there are also some excellent features which play an important role
in the popularity of this language. The features of Java are also known as java buzzwords.
A list of most important features of Java language is given below.
1. Simple
2. Object-Oriented
3. Portable
4. Platform independent
5. Secured
6. Robust
7. Architecture neutral
8. Interpreted
9. High Performance
10. Multithreaded
11. Distributed
12. Dynamic

Simple
Java is very easy to learn, and its syntax is simple, clean and easy to understand. According to Sun, Java
language is a simple programming language because:
 Java syntax is based on C++ (so easier for programmers to learn it after C++).
 Java has removed many complicated and rarely-used features, for example, explicit pointers,
operator overloading, etc.
 There is no need to remove unreferenced objects because there is an Automatic Garbage Collection
in Java.

Object-oriented
Java is an object-oriented programming language. Everything in Java is an object. Object-oriented means we
organize our software as a combination of different types of objects that incorporates both data and
behavior.
Object-oriented programming (OOPs) is a methodology that simplifies software development and
maintenance by providing some rules.
Basic concepts of OOPs are:
 Object
 Class
 Inheritance
 Polymorphism
 Abstraction
 Encapsulation
Platform Independent
Java is platform independent because it is different from other languages like C, C++, etc. which are
compiled into platform specific machines while Java is a write once, run anywhere language. A platform is
the hardware or software environment in which a program runs. There are two types of platforms software-
based and hardware-based. Java provides a software-based platform. The Java platform differs from most
other platforms in the sense that it is a software-based platform that runs on the top of other hardware-based
platforms
Java code can be run on multiple platforms, for example, Windows, Linux, Sun Solaris, Mac/OS, etc. Java
code is compiled by the compiler and converted into bytecode. This bytecode is a platform-independent
code because it can be run on multiple platforms, i.e., Write Once and Run Anywhere (WORA).

Secured
Java is best known for its security. With Java, we can develop virus-free systems. With Java's secure feature
it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key
encryption. Java program always runs in Java runtime environment with almost null interaction with system
OS, hence it is more secure. Some security can also be provided by an application developer explicitly
through SSL, JAAS, Cryptography, etc.
The fact that a Java program is executed by the JVM also helps to make it secure. Because the JVM is in
control, it can contain the program and prevent it from generating side effects outside of the system. As you
will see, safety is also enhanced by certain restrictions that exist in the Java language.

Robust
Robust simply means strong. Java has been designed for writing highly reliable or robust software. Java is
robust because:
 It uses strong memory management.
 It is a strongly typed language, which allows for extensive compile-time checking for potential type-
mismatch problems.
 There is a lack of pointers that avoids security problems.
 There is automatic garbage collection in java which runs on the Java Virtual Machine to get rid of
objects which are not being used by a Java application anymore.
 There are exception handling and the type checking mechanism in Java. All these points make Java
robust.
Architecture-neutral
Java is architecture neutral because there are no implementation dependent features, for example, the size of
primitive types is fixed. In C programming, int data type occupies 2 bytes of memory for 32-bit architecture
and 4 bytes of memory for 64-bit architecture. However, it occupies 4 bytes of memory for both 32 and 64-
bit architectures in Java.

Portable
Java is portable because it facilitates you to carry the Java bytecode to any platform. It doesn't require any
implementation.

High-performance
Java is faster than other traditional interpreted programming languages because Java bytecode is "close" to
native code. It is still a little bit slower than a compiled language (e.g., C++). Java is an interpreted language
that is why it is slower than compiled languages, e.g., C, C++, etc.

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.
Distributed
Java is distributed because it facilitates users to create distributed applications in Java. RMI and EJB are
used for creating distributed applications. This feature of Java makes us able to access files by calling the
methods from any machine on the internet.
Multi-threaded
A thread is like a separate program, executing concurrently. We can write Java programs that deal with
many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn't
occupy memory for each thread. It shares a common memory area. Threads are important for multi-media,
Web applications, etc.

Dynamic
Java is a dynamic language. It supports dynamic loading of classes. It means classes are loaded on demand.
It also supports functions from its native languages, i.e., C and C++. Java supports dynamic compilation and
automatic memory management (garbage collection).

Java Programming Environment


Java environment includes a large number of development tools and hundreds of classes and methods. The
development tools are part of the system known as Java Development Kit (JDK) and the classes and
methods are part of the Java Standard Library (JSL), also known as the Application Programming Interface
(API).

JDK
The Java Development Kit (JDK) is a software development environment which is used to develop Java
applications and applets. It physically exists. It contains JRE + compiler and development tools. To compile
java programs, you will need to download and install the JDK. The JDK consists of a set of tools necessary
to construct Java programs. They include:

Tool Description
javac Java compiler, which translates Java source code to bytecode files that the interpreter
can understand

java Java interpreter, which runs applets and applications by reading and interpreting
bytecode files
javadoc Creates HTML-format documentation from Java source code files
javah Produces header files for use with native methods
javap Java disassembler which enables us to convert bytecode files into a program description
jdb Java debugger, which helps us to find errors in our programs.
appletviewer Enables us to run Java applets

JRE
JRE is an acronym for Java Runtime Environment. It is also written as Java RTE. The Java Runtime
Environment is a set of software tools which are used for developing Java applications. It is used to provide
the runtime environment. It is the implementation of JVM. It physically exists. It contains a set of runtime
class libraries + other files that JVM uses at runtime.
JIT compiler: Since Java Runtime Environment (JRE) version 1.2, Sun’s JVM implementation has also
included a just-in-time (JIT) compiler. The compiler used to compile bytecode into machine-code at runtime
is called the JIT compiler. Instead of interpreting the bytecode one instruction at a time, this converts the
bytecode for a program into equivalent native machine code as the program is loaded into the virtual
machine, allowing it to execute much faster at the cost of a small delay whenever new bytecode is loaded.
Once the piece of code is compiled by the JVM to execution code, the code is used and reused again and
again, to speed up the execution.

JVM
The heart of the java platform is the concept of a common “virtual” processor that executes the intermediate
Java bytecode programs. This bytecode is the same no matter what hardware or operating system the
program is running under. The Java platform provides an interpreter called the Java Virtual Machine (JVM),
which translates the Java bytecode into native processor instructions at run-time. This permits the same
application to be run on any platform that has a virtual machine available.
JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine because it doesn't
physically exist. It is a specification that provides a runtime environment in which Java bytecode can be
executed. It can also run those programs which are written in other languages and compiled to Java
bytecode.
All language compilers translate source code into machine code for a specific computer. Java compiler also
does the same thing. The figure below illustrates the process of compiling a Java program into bytecode
which is also referred to as virtual machine code.

Java Java Virtual


Program Compiler Machine

Source code Byte code

Fig 1: Process of compilation

The virtual machine code is not machine specific. The machine specific code (known as machine code) is
generated by the Java interpreter by acting as an intermediary between the virtual machine and the real
machine as shown in figure below.

Java Machine
Bytecode Interpreter Code

Virtual Machine Real Machine

Fig 2: Process of converting byte code into machine code

JVMs are available for many hardware and software platforms. JVM, JRE, and JDK are platform dependent
because the configuration of each OS is different from each other. However, Java is platform independent.
The Bytecode
The output of a Java compiler is not executable code. Rather, it is bytecode. Bytecode is a highly optimized
set of instructions designed to be executed by the Java run-time system, which is called the Java Virtual
Machine (JVM). In essence, the original JVM was designed as an interpreter for bytecode. The fact that a
Java program is executed by the JVM helps solve the major problems associated with web-based programs.
Here is why. Translating a Java program into bytecode makes it much easier to run a program in a wide
variety of environments because only the JVM needs to be implemented for each platform. Once the run-
time package exists for a given system, any Java program can run on it. Remember, although the details of
the JVM will differ from platform to platform, all understand the same Java bytecode. If a Java program
were compiled to native code, then different versions of the same program would have to exist for each type
of CPU connected to the Internet. This is, of course, not a feasible solution. Thus, the execution of bytecode
by the JVM is the easiest way to create truly portable programs.
As already said, the Java compiler (javac) is used to compile Java source code files into executable Java
bytecode classes. In Java, source code files are text files with .java extension. You can create such files with
a text editor, like Notepad, or an IDE. The Java compiler then compiles these files into loadable and
executable class files, called java bytecode, using the .class extension. The compiler creates one class file for
each class defined in a source file and these files are packaged to an application_name.jar file to distribute
to run in any hardware.

First Java Program | Hello World Example


To create a simple java program, you need to create a class that contains the main method. Let's understand
the requirement first.
The requirement for Java Hello World Example:
For executing any java program, you need to
 Install the JDK if you don't have installed it, download the JDK and install it.
 Set path of the jdk/bin directory. [Link]
 Create the java program
 Compile and run the java program
Creating Hello World Example
Let's create the hello java program:
class Simple
{
public static void main(String args[])
{
[Link]("Hello Java");
}
}
Save this file as [Link]
To compile: javac [Link]
To execute: java Simple
Output: Hello Java

Compilation Flow:
When we compile Java program using javac tool, java compiler converts the source code into byte code.

Parameters used in First Java Program


Let's see what is the meaning of class, public, static, void, main, String[], [Link]().
 class keyword is used to declare a class in java.
 public keyword is an access modifier which represents visibility. It means it is visible to all.
 static is a keyword. If we declare any method as static, it is known as the static method. The core
advantage of the static method is that there is no need to create an object to invoke the static method.
The main method is executed by the JVM, so it doesn't require to create an object to invoke the main
method. So it saves memory.
 void is the return type of the method. It means it doesn't return any value.
 main represents the starting point of the program.
 String[] args is used for command line argument. We will learn it later.
 [Link]() is used to print statement. Here, System is a class, out is the object of
PrintStream class, println() is the method of PrintStream class. We will learn about the internal
working of [Link] statement later.

You might also like