HISTORY AND DEVELOPMENT OFJAVA
In 1991, the Sun Micro Systems (Broomfield, Colorado, USA) developed a complete language as a part of research work to develop software for consumer electronics. It was developed as a full-fledged programming language It can accomplish all arts of tasks and solve the problems like another programming Languages viz BASIC C++. It was platform independent and hence, the task can be made portable from one system to another.
The language was named ‘Oak while staring at an oak tree outside the office window! The name ‘Oak was later dismissed due to a patent search, which determined that the name was made copyright and used for another programming language. According to Gosling, The lava development team discovered that Oak was the name of a programming language that predated Sun’s language, so another name had to be chosen.
It’s surprisingly difficult to find a good name for a programming language for the team. Finally, inspiration struck one day during a trip to the local coffee shop in the presence of Gosling. The name Java came from several individuals involved in the project James Gosling, Arthur Van Hoff, and Andy Bechtolsheim headed by James Gosling. Thus, the language JAVA came into existence as an object oriented programming language.
JAVA, being an object oriented programming language, encapsulates many features of C++. Initially, JAVA was designed to execute applets, which can be downloaded by using web browsers. But gradually, the language has been gaining wide acceptance as a programming language, very often replacing C or C++.
DIFFERENT TYPES OF JAVA PROGRAMMING
Stand Alone System (Java Application)
Java programming language was primarily developed to deal with embedded applications. But with the introduction of other user interface utilities to Java, it made its mark in desktop applications too. Now, the trend is to use Java technology in developing large web and enterprise applications. Java is more focused on the web than desktop applications. In the present scenario, Java language is widely accepted as a development technology for stand alone (desktop application) development.
Internet Applets (Java Applets)
A Java applet is an applet delivered to the users in the form of Java byte code Java applets can run in a web browser using a Java Virtual Machine (JVM). The applet is a program written in the Java programming language that can be included in an HTML page, much, in the same way, an image is included in a page. When you use a Java technology-enabled browser to view a page that contains an applet, the applet’s code is transferred to your system and executed by the browser’s Java Virtual Machine (JVM). Java applets were introduced in the first version of the Java language in 1995.
BASIC FEATURES OF JAVA
Java possesses the following features:
- Java is an object oriented programming language.
- Java programs are both compiled and interpreted.
- Java programs are platform independent.
- Java is a robust programming language.
- It is a multi-threaded language.
- It can access data from a local system as well as from the net.
- Java programming is written within a class. The variables and functions are declared and defined with the class.
- Java programs can create Applets (the programs which run on web browsers) and Applications (that are general programs like any other programming language).
- Java does not require any preprocessor or inclusion of header files for creating a Java application.
- Java is case sensitive. As a programming language, the language distinguishes the upper case and lower case letters.
COMPILER AND INTERPRETER
Compilation and interpretation are the terms related to language translation. Suppose, the Russian President has to address a gathering in New Delhi. He may not know any language other than Russian. In such a situation, he is accompanied by a language translator (a person) who can translate the speech made by him in the Russian language to Hindi or English for the people of New Delhi to understand. The translation may take place in the following two ways:
- After the completion of the President’s speech, the translator will communicate the whole speech made by him in Hindi or English so that the people can understand. This type of language conversion is termed a compilation and the person who does it is called a compiler.
- As President finishes a sentence, it is immediately converted and spoken by the translator in Hindi or English. In this system, the translation is sentence-wise. This process of conversion of language is called interpretation and the translator is termed an interpreter.
How do Compiler & Interpreter Work?
All high level languages need to be converted to machine code (binary code) so that the computer understands the program after taking the required inputs. It processes the program and then shows the desired results if it is error-free, otherwise, the errors are to be corrected to execute the program successfully.
The conversion of a high level language (source code) to machine level language (binary code) can be done in two possible ways. It can be done either by using a compiler or an interpreter.
The software, by which the conversion of the high level instructions is performed line by line to machine level language, is known as an interpreter. If an error is found on any line, the further execution stops till it is corrected. This process of error correction is much easier but the program takes longer time to execute successfully.
However, if all the instructions can be converted to machine level language at once and all the errors are listed together, then the software is known as a compiler. This process is much faster but sometimes it becomes difficult to debug (correct) all the errors together in a program.
BYTE CODE AND JAVA VIRTUAL MACHINE
Java is a high level language (HLL) and the program written in HLL is compiled and then converted to an intermediate language called byte code. This code is irrespective of the machine on which the program is run (Le machine independent). This makes a Java program highly portable as its bytes code can easily be transferred from one system to another. When this byte code is to be run on any system, an interpreter is needed, known as Java Virtual Machine (JVM), which translates the byte code to machine code.
Java machine code varies for different platforms like Windows, UNIX, OS-2, etc. Hence, Java Interpreter converts byte code to machine code pertaining to a specific platform.
JVM acts as a virtual processor, which processes the byte code to machine code instructions for various platforms. That is why it is called Java Virtual Machine. Thus, the Java program uses both the compiler as well as an interpreter.
JAVA LIBRARIES
The Java Development Kit (JDK) contains a Java Class Library for different purposes. Some useful packages in the Java Class Library are mentioned below:
- java. lang: to support classes containing String/character, Math, Integer, Thread, etc.
- java.io: to support classes to deal with input and output statements.
- java. applet: to support classes to generate an applet-specific environment.
- java.net: to support classes for network related operations and dealing with URL (Uniform Resource Locator).
- java. awt: to support abstract window tool kit and also to manage GUI
- (Graphic User Interface).
- java.txt: to locate text elements such as dates, times and currency, etc.
- java. math: to support mathematical functions such as square roots (Integer and decimal both).
JAVA RESERVED WORDS
Reserve words or keywords are those words, which are preserved with the system. These words cannot be applied as a variable name in any program. Java also has reserved words. Some of the reserved/keywords are given below for your reference:
case | switch | else | break | static |
char | float | throws | const | do |
goto | void | double | int | try |
import | new | boolean | while | for |
private | if | long | catch | package |
byte | public | short | class | default |
COMMENT SYMBOLS IN JAVA PROGRAMMING
Sometimes it becomes difficult for a user to understand the logic applied in a program particularly when any other person develops it. In such cases, the programmer keeps mentioning the purpose and action being taken in different steps. This can be made possible only by applying comment statements in the program.
There are three ways to give a comment in Java programming. However, users are expected to give comments wherever necessary while writing Java programming.
Single Line Comment
Single Line Comments are written in (//). This comment symbol is applied to explain the purpose of a logical step in short Le within a line. An example is given below:
class main
{
public static void main(String args[]
{
//This is my first program
int a=15, b=8, c;
c=a+b;// Find the sum of two numbers
System.out.println("Product of two numbers");
}
}
Multi Line Comment
Multi Line Comments are written in (/* Comment */). This comment statement can be used when the programmer wants to explain the logical steps in detail i.e. by including multiple lines as shown below.
class main
{
public static void main(String args[]
{
/*This is my first program
To find the sum of two numbers */
int a=15, b=8, c;
c=a+b;
System.out.println("Product of two numbers");
}
}
Documenting Comment
Documenting Comments are written in (/** Full Details about program*/). This type of comment statement can be applied if the programmer needs to apply a sort of document along with his program.
class main
{
public static void main(String args[]
{
/**Welcome to beeown.com
This is my first program
To find the sum of two numbers
*/
int a=15, b=8, c;
c=a+b;
System.out.println("Product of two numbers");
}
}
OUTPUT STATEMENT IN JAVA PROGRAMMING
When you use System.out.println() statement, the cursor skips the line and passes to the next line after displaying the required result.
However, the cursor remains on the same line after displaying the result if we use System. out.print().
These statements are used to get the output of the program or to display messages on the screen which are shown below:
Syntax: System.out.println(“Welcome to Java Programming”);
Note: The message is to be written within double quotes (” “) enclosed within braces.
In case of a message along with a variable:
Syntax: System.out.println(“The sum of two numbers is” + a );
Note: When a message is to be displayed along with a variable, then they are to be separated with+ a (plus) sign.
Conclision
There are various types of Java programming such as GUI programming, remote method invocation, network distributed processing, and so on.