Home | » | Java | » | Overview of Java |
---|
Contents
- Simple Java Program
- An Application with Two Classes
- Java Tokens
- Implements a Java Program
- Java Virtual Machine
- Command Line Arguments
Simple Java Program
A Simple Example of java Program
We know java is Purely OOP Language So that Every Program of Java Must be Written into the Classes For this Class is Keyword and abc is name of Class.
The first line is a single line comment which will be ignored during compilation. Comments make you understand what your program does. Use /*.............*/ for multiple line comments.
In Java, everything must be declared in a class, which is declared by the keyword Class. Public is a keyword which makes this class available and accessible to any one.(Simple) one is a Java identifier that specifies the name of the class to be defined.
In Java, every class definition begins with an opening brece "{" and ends with a closing brace "}". Pair of "{}" braces define the scope of any method or class.
The Main Line
The next line of code is shown here:
Public static void main(String arg[]
Public Here Public is a Keyword which declares main method is public or unprotected so that it will be Accessible to all classes. Static Static is used for Describing that this is the method which belongs to this class not to other means this is the main method of Class only Main Method Must be Declared as Static so that Interpreter Will Execute this Method First ,before Creating the Objects of the Class. Void Void means The Main Function will never Return a Value or it will Simply Prints the text on the Screen.
The Output Line
The next line of code is shown here:
System.out.print("A Simple Example of java Program");
This Line is Similar to printf in C and Cout in C++ For Displaying the Results on the Screen at the Time of Execution in this System is name of Package and Out i.e Output is name of class and print is the name of Method that belongs to the output class For Displaying the Results on the Screen.
An Application with Two Classes
The one example discussed above contain only one class that contains main() method. Multiple classes are required in a real-life application. Let's consider a program in Java with two classes.
The above program contains two classes Box and BoxDemo. The Box class declares three variables. The class BoxDemo contains the main method that initiates the execution.
The main method create a Box object by the statement.
Box mybox = new Box();
After this statement executes, mybox will be an instance of Box. Thus, it will have "physical" reality. Every Box object will contain its own copy of instance variables width, height and length. The dot (.) operator is used to access these variables.
Java Tokens
A java Program is made up of Classes and Methods and in the Methods are the Container of the various Statements And a Statement is made up of Variables, Constants, operators etc Tokens are the Smallest unit of Program There are Five Types of Tokens.
- Reserve Word or Keywords
- Identifier
- Literals
- Operators
- Separators
Keywords
A Keyword is that which have a special meaning those are already been explained to the java language like int, float, class, public etc these are the reserve keywords Always Remember that we can t give a name to a variable as the name of a keyword Java Provides us the 60 Keywords All the Keywords are to be written into the lower case because java is a Case Sensitive means Upper case and Lower case Letters are Different in java Some Keywords are inherit by the java language from c and C++ it adds only 27 keywords like System, Interface, abstract, final etc.
Identifiers
The Identifiers are those which are used for giving a name to a variable ,class and method ,packages ,interfaces etc There Are Some Rules against for using the Identifiers.
1) Name of Identifier not be a Keyword
2) Must be Start from Alphabet not from digit
3) Uppercase and Lowercase are Different
4) Can be any length
Literals
Literals are Sequence of Characters like Digits ,alphabets ,letters those are used for Representing the Value of the Variable Like Integer Literals, String Literals, Float Literals.
Operator
Operators are the Special Symbols those have specific functions associated with them for Performing the operations it needs some Operands
Operands are those on which operations are performed by the Operators
Like 2 +3
In this + is the Operator and 2 and 3 Operands.
Separators
These are Special Symbols used to Indicate the group of code that is either be divided or arrange into the Block The Separators includes Parentheses, Open Curly braces Comma, Semicolon, or either it will be period or dot Operator.
Implements a Java Program
The steps involved in the implementation of a java program are as follows:
- Creating the program
- Compling the program
- Running the program
Remember to install the Java Development Kit (JDK) properly before creating the program in Java.
Creating the program
A Program can be created using any text editor. Let us consider an example program.
First of all we will install JDK using any java version . for example now we will use jdk1.4 kit. after install java now you will open jdk1.4 using following commands:
The above program must be saved with the file name "First.java" under the "c:/jdk1.4/bin/ dir. This file is called the Source file. Note that file name must be the class name of the class containing the main method along with the file extension "java".
Compiling the Program
To compile the program, type the following instruction at the command prompt:
javac First.java
If the program is compiled successfully, the javac compiler creates a file called First.class contains the bytecode of the program.
Running the Program
Java Interpreter is used to run a stand-alone program. To run the program type the following instruction at the command prompt.
Download Complete Program
Very good and detailed article.
ReplyDeleteJava Training in Velachery
This comment has been removed by the author.
ReplyDeleteGreat overview of Java! It's impressive how tools like GodMode9 can complement Java development workflows.
ReplyDelete