Basic Features
Basic Features
Basic Features
Java History
Year Progress
1990 Sun decided to developed software that could be used for
electronic devices. And the project called as Green Project head
by James Gosling.
1991 Announcement of a new language named ―Oak‖
1992 The team verified the application of their new language to
manage a list of home appliances using a hand held device.
1993 The World Wide Web appeared on the Internet and
transformed the text-based interface to a graphical rich
environment.
1994 The team developed a new Web browsed called ―Hot Java‖ to
locate and run Applets.
1995 Oak was renamed to Java, as it did not survive ―legal‖
registration. Many companies such as Netscape and Microsoft
announced their support for Java.
1996 Java language is now famous for Internet programming as well
as a general purpose OO language.
1997 Sun releases Java Development Kit(JDK 1.1)
1998 Sun releases Software Development Kit (SDK 1.2)
1999 Sun releases Java 2 platform Standard Edition (J2SE) and
Enterprise Edition(J2EE).
2000 J2SE with SDK 1.3 was released.
2002 J2SE with SDK 1.4 was released.
2004 J2SE with JDK 5.0 was released.
Features of java:
1. Compiled and Interpreted
• Basically a computer language is either compiled or interpreted. Java
comes together both these approach thus making Java a two-stage system.
• Java compiler translates Java code to Bytecode instructions and Java
Interpreter generate machine code that can be directly executed by
machine that is running the Java program.
2. Platform Independent
3. Object Oriented
• Java is truly object-oriented language.
• Objects have two sections.
• The first is Data (instance variables) and the second is methods.
4. Easy to Learn
• Java is very small and simple language. Java does not use pointer and
header files, goto statements,etc.
• It eliminates operator overloading , multiple inheritance and pointers.
• in Java is automatic memory allocation and de-allocation.
• The compiler can handle methods that are used before they’re declared. It
can also determine whether a source code has been changed since the last
time it was compiled.
8. High Performance
• Java is a fast-interpreted language.
• Java has designed for the run-time system can optimize their performance
by compiling bytecode to native machine code on the fly (execute
immediately after compilation). This is called “just in time” (JIT) compilation.
Java Environment:
• 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).
• Java Development kit (JDK) – The JDK comes with a set of tools that are used
for developing and running Java program. It includes:
1. Appletviewer( It is used for viewing the applet)
2. Javac(It is a Java Compiler)
3. Java(It is a java interpreter)
4. Javap(Java diassembler,which convert byte code into program
description)
5. Javah(It is for java C header files)
6. Javadoc(It is for creating HTML document)
7. Jdb(It is Java debugger)
For compiling and running the program we have to use following commands:
a) javac (Java compiler)
In java, we can use any text editor for writing program and then save that
program with ―.java extension.
Java compiler convert the source code or program in bytecode and interpreter
convert ―.java file in ―.class file.
Syntax: C:\javac filename.java
If my filename is ―abc.java‖ then the syntax will be
Eg. C:\javac abc.java
b) java(Java Interpreter)
Java interpreter convert bytecode into machine code and ―.java file in ―.class file.
Syntax: C:\java filename
If my filename is abc.java then the syntax will be
Eg. C:\java abc
A Simple Java Program
Java offers two flavors of programming, Java applets and Java application
Let us write your first program with the file name “Application”. This program,
after successful compilation and run, prints the words “This is My First Java
Program” on your display.
1. First of all using any text editor, type Java source file of your program as
given below.
2. Now compile the source file-using compiler named Javac that takes your
source file and translates its statements into a bytecode file.
3. Run the program using interpreter named Java that takes your bytecode file
and translates
them into machine code that your computer can understand.
/* This is my First Java Application Save the file as Application.Java: same as class
name */
class Application
{
public static void main (String args[ ] )
{
System.out.println(“This is My First Java Application”);
} // main ends here
} // Code ends here
Second line in the program defines a class named Application using a keyword
class.
This is the point from where the program will start the execution. This program
starts the execution by calling main () method. In this line public, static, and void
all are keywords. May be you are thinking of the meaning of ‘keyword’. Keywords
are nothing but some reserved words.
• The public keyword is used to control the access of various class members.
If member is public it can be accessed outside the class.
• So we have to declare main () as public because it has to be invoked by the
code outside the class when program is executed.
• Static key word allows the main () method to be executed without creating
an object of that class,
• and void means main () method does not return any value.
• Parentheses ( )
It encloses arguments in method definitions or calling and used to
define test expressions control statements.
• Braces { }
It defines blocks of code
• Square bracket [ ]
It declares array types.
• Semicolons;
are used to terminate statements.
To compile the Example program, execute the compiler, javac, specifying the
name of the source file on the command line, as shown here:
C:\>javac Application.java
The javac compiler creates a file called Example.class that contains the bytecode
version of the program.
The Java bytecode is the intermediate of program.the Java interpreter will
execute.
Thus, the output of javac is not code that can be directly executed.
To actually run the program, you must use the Java interpreter, called java. To do
so, pass the class name Example as a command-line argument, as shown here:
C:\>java Application
As you know the Java source code is compiled into bytecode by Java compiler. This
bytecode will be stored in class files. During runtime, this bytecode will be loaded,
verified and JVM interprets the bytecode into machine code which will be
executed in the machine in which the Java program runs.
These tasks are described in detail in the subsequent sessions.A detailed Java
architecture can be drawn as given below.
4. There are no illegal data conversions in the code such as float to object
references.
Once this code is verified and proven that there is no security issues with the code,
JVM will convert the byte code into machine code which will be directly executed
by the machine in which the Java program runs.
If the JIT Compiler library exists, when a particular bytecode is executed first time,
JIT complier compiles it into native machine code which can be directly executed
by the machine in which the Java program runs. Once the byte code is recompiled
by JIT compiler, the execution time needed will be much lesser. This compilation
happens when the byte code is about to be executed and hence the name “Just in
Time”.
Once the bytecode is compiled into that particular machine code, it is cached by
the JIT compiler and will be reused for the future needs. Hence the main
performance improvement by using JIT compiler can be seen when the same code
is executed again and again because JIT make use of the machine code which is
cached and stored.
Garbage Collection
Garbage collection is a process by which Java achieves better memory
management. As you know, in object oriented programming, objects communicate
to each other by passing messages. (If you are not clear about the concepts of
objects, please read the prior chapter before continuing in this session).
Whenever an object is created, there will be some memory allocated for this object.
This memory will remain as allocated until there are some references to this object.
When there is no reference to this object, Java will assume that this object is not
used anymore. When garbage collection process happens, these objects will be
destroyed and memory will be reclaimed.
Garbage collection happens automatically. There is no way that you can force
garbage collection to happen. There are two methods “System.gc()” and
“Runtime.gc()” through which you can make request for garbage collation. But
calling these methods also will not force garbage collection to happen and you
cannot make sure when this garbage collection will happen.
If you want to get the detailed knowledge of Java Virtual Machine, move to the next
page. Firstly, let's see the differences between the JDK, JRE, and JVM.
JVM
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. There are three notions of the
JVM: specification, implementation, and instance.
o Loads code
o Verifies code
o Executes code
o Provides runtime environment
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 libraries + other
files that JVM uses at runtime.
JDK
JDK is an acronym for Java Development Kit. 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 + development tools.
JDK is an implementation of any one of the below given Java Platforms released by
Oracle Corporation:
The JDK contains a private Java Virtual Machine (JVM) and a few other resources
such as an interpreter/loader (java), a compiler (javac), an archiver (jar), a
documentation generator (Javadoc), etc. to complete the development of a Java
Application.
Description
As you may know, in some other languages, including C/C++, strings are
implemented as arrays of characters. However, this is not the case in Java. Strings
are actually object types. As you will see later because Java implements strings as
objects, Java includes extensive string-handling capabilities that are both powerful
and easy to use.
Dynamic Initialization
Although the preceding examples have used only constants as initializers, Java
allows variables to be initialized dynamically, using any expression valid at the
time the variable is declared.
For example, here is a short program that computes the length of the hypotenuse
of a right triangle given the lengths of its two opposing sides:
So far, all of the variables used have been declared at the start of the main( )
method. However, Java allows variables to be declared within any block. A block
defines a scope. Thus, each time you start a new block, you are creating a new
scope. As you probably know from your previous programming experience, a
scope determines what objects are visible to other parts of your program. It also
determines the lifetime of those objects. Most other computer languages define
two general categories of scopes: global and local. However, these traditional
scopes do not fit well with Java’s strict, object oriented model. While it is possible
to create what amounts to being a global scope, it is by far the exception, not the
rule. In Java, the two major scopes are those defined by a class and those defined
by a method. Even this distinction is somewhat artificial. However, since the class
scope has several unique properties and attributes that do not apply to the scope
defined by a method, this distinction makes some sense.
As a general rule, variables declared inside a scope are not visible (that is,
accessible) to code that is defined outside that scope. Thus, when you declare a
variable within a scope, you are localizing that variable and protecting it from
unauthorized access and/or modification. Indeed, the scope rules provide the
foundation for encapsulation. Scopes can be nested. For example, each time you
create a block of code, you are creating a new, nested scope. When this occurs, the
outer scope encloses the inner scope. This means that objects declared in the outer
scope will be visible to code within the inner scope. However, the reverse is not
true. Objects declared within the inner scope will not be visible outside it.
C++ java
C