Tokens: Smallest individual units in a program are known as tokens. The compiler recognizes them for building up expressions and statements. Java program is a collection of tokens, comments and white spaces. Java language include five types of tokens. They are:
Java Character Set : The smallest units of Java Language are the characters used to write Java Tokens. These characters are defined by the Unicode character set. The Unicode is a 16 bit character coding system and currently supports more than 34000 defined characters derived from 24 languages.
Keywords : are an essential part of a language definition.These are the some word which java uses for its syntax definition. Java language has reserved about 50 words or keywords.
Here is a list of keywords in the Java programming
language. You cannot use any of the following as identifiers in your
programs. The keywords
Identifiers:Identifiers are programmer designed tokens. They are used for naming classes methods, variables,object, labels, packages, and interface in a program. Java identifiers follow the following rules:
1) They can have alphabets, digits, and the underscore and dollar sign characters.
2) They must not begin with a digit.
3) Uppercase and lowercase letters are distinct.
4) They can be of any length.
Illustration with simple program for compiling and running the java program.
Step 1: Creating the Program
Open the notepad and write the program, save the program "Test.java" ensuring that the file name contains the class name properly. This file is called source file.
If a program contains multiple classes, the file name must be the classname of the class containing the main method
public static void main ( String args)
System.out.println("Welcome to the world of Java. ");
Step 2: To compile the type in command prompt
javac is java compiler. If everything is OK, then javac compiler creates a file called Test.class containing the bytecode of the program.
Step 3: After compiling to run the program, we need to use the java interpreter to run the program, At the command prompt, type
Now, the interpreter looks for the main method in the program and begins execution from there.
Welcome to the world of Java.
Java The Machine Neutral or Platform Independent programming language.
1 ) What does Machine Neutral or Platform Independent means ?
Machine Neutral Platform Independent means that while writing the program in java, we don't need to care about on which Machine or platform the program will going to be executed. Like in C language if we want to run the program in Windows XP the we need to write the program in windows compatible C compiler and in windows platform to c program in UNIX or Linux we need to edit and compile the same program in Linux and UNIX compatible compiler and environment . Same in visual basic program can only run in Windows platform.
Java breaks all these restriction, Java gives the freedom to write and compile the program in any platform or machine and the same program can run on different platform and machine. Example Java program written for Linux system can also run on windows and UNIX etc.
2) How Java do this?
The secret behind platform independent of java is JAVA VIRTUAL MACHINE.
All language compilers translate source code into machine code for a specific computer. Java compiler also does the same thing. Then, how does java achieve architecture neutrality? The answer is that the Java compiler produces an itermedia code known as bytecode for a machine that does not exits. This machine is called the Java Virtual Machine and it exits only inside the computer memory. It is a simulated computer within the computer and does all major functions of a real computer.
See supported System Configurations for information about supported platforms, operating systems, desktop managers, and browsers.
The minimum physical RAM is required to run graphically based applications. More RAM is recommended for applets running within a browser using the Java Plugin. Running with less memory may cause disk swapping which has a severe effect on performance. Very large programs may require more RAM for adequate performance.
This installation requires Windows Installer 2.0 to be on your machine. For more details, see the Troubleshooting the Installation section .
For the amount of disk space required, see Windows Disk Space Requirements.
In this procedure, you will run the self-installing executable to unpack and install the JDK software bundle. As part of the JDK, this installation includes an option to include the public Java Runtime Environment. (The JDK also contains a private JRE for use only by its tools.)
3. If you want to run Netscape 7.x, Mozilla 1.x, or Firefox 1.x with Java Plugin, do this:
If you should ever want to uninstall the JDK, use the "Add/Remove Programs" utility in the Microsoft Windows Control Panel.
If you use the Invocation API to launch an application directly rather than using the Java application launcher, be sure to use the correct paths to invoke the Java HotSpot Client Virtual Machine (VM) or Java HotSpot Server VM, as desired. The path within the JDK to the Java HotSpot Client VM is:
The path to the Java HotSpot Server VM is:
The corresponding locations in the Java SE Runtime Environment begin with jre1.6.0 instead of jre. The Exact VM and Classic VM are no longer part of the JDK, and existing code that uses the Invocation API to launch an application based on old paths to the Exact or Classic VMs will not work.
Below are some tips for working around problems that are sometimes seen during or following an installation. For more troubleshooting information, see the Java FAQ.
Java is general purpose, object oriented programming language. We can develop two types of java programs:
1) Stand-alone applications.
2) Web applets.
Stand-alone applications are programs written in java to carry out certain tasks on a stand-alone local computer.
Executing a stand-alone java program involves two steps:
1) Compiling source code into bytecode using javac compiler.
2) Executing the bytecode program using java interpreter.
Applets are small java programs developed for Internet applications. An applet located on a distant computer(server) can be downloaded via internet and executed on a local computer using a Java-capable browser.
Stand-alone programs can read write files and perform certain operations that applets cannot do. An applet can only run within a Web browser.
Java Program Structure
Documentation Section <----------------- optional
Package Statement <----------------- optional
Import Statements <----------------- optional
Interface Statements <----------------- optional
Class definitions <------------------ optional
Main Method Class
Main Method definition <--------------------Essential
This section a set of comment lines giving the name of the program, the author and other details, which the programmer would like to refer to refer to at a later stage.
Package Statement :-
The statement declares a package name and informs the compiler that the classes defined here belong to this package.To continue java program package will be discussed more later on.
Import Statements :-
This statement is similar to the #include statement in C. Ex:- " import student.test;" This statement instruct the interpreter to load the test class contained in the package student. Using import statement , We can have access to classes that are part of other named packages.
Interface Statement :-
An interface is like a class but includes a group of method declarations. This is optional section and is used only when we wish to implement the multiple inheritance features in program.To continue java program interface will be discussed more later on.
Class Definitions :-
A java program may contains multiple class definitions. Class are the primary essential elements of a java program. The number of classes used depends on the complexity of the problem.
Main Method Class :-
Since java program may contains multiple classes, So Main class is one among them which has a main method that act as a starting point for the program or simple the main method drive the whole program.
The main method creates objects of various classes and establishes communications between them. On reaching the end of main, the program terminates and the control passes back to the operating system.
A simple Java Program may contain only main class and main method. It necessary to have a main method class in java program to run.
Java is one of the most job seeking programming language in the recent I.T industry. Object-Oriented Programming(OOP) is an approach to program organization and development, which attempts to eliminate some of the pitfalls of conventional programming methods by incorporating the best of structured programming features with several new concepts. It is a new way of organizing and developing programs and has nothing to do with any particular language.
Compiled and Interpredted: Mostly a computer programming language is either compiled or interpreted. Java combines both these approaches thus making Java a two-stage system. First, Java compiler translates source code into what is known as bytecode instructions. Bytecodes are not machine instruction and therefore in the second stage, Java interpreter generates machine code that can be directly executed by the machine that is running the java program.
Platform-Independent and Portable:Java programs can be easily moved from one computer system to another, anywhere and anytime.changes and upgrades in operating systems, processors and system resources will not force any changes in java programs.
Java ensures portability in two ways. First, Java compiler generates bytecode instruction that can be implemented on any machine. Secondly, the size of the primitive data types are machine independent.
Object-Oriented: Java is a true object-oriented language. Almost everything in java is an object. All program code and data reside within objects and classes. Java comes with an extensive set of classes, arranged in packages.
Robust and secure: Java is a robust language. It provides many safeguards to ensure reliable code. It has strict compile time and run time checking for data types. It is designed as a garbage-collected language relieving the programmers virtually all memory management problems. Java also incorporates the concepts of exception handling which captures series errors and eliminates any risk of crashing the system.
Java systems not only verify all memory access but also ensure that no viruses are communicated with an applet. The absence of pointers in java ensures that programs cannot gain access to memory locations without proper authorization.
Distributed: java is designed as a distributed language for creating applications on networks. It has the ability to share both data and programs. Java applications can open and access remote objects on Internet as easily as they can do in local system.
This enables multiple programmers at multiple remote locations to collaborate and work together on a single project.
Multithreaded : Multithreaded means handling multiple tasks simultaneously. Java supports multithreaded programming. This means that we not wait for the application to finish one task before beginning another.