http://www.c4learn.com/javaprogramming/
This links learn JAVA Programming step by Step
INTRODUCTION TO JAVA....
Java was developed in the year 1991 and was formally announced in
1995. Basically, java is based on C and C++. The character of java is
inherited from both of these two languages. Syntax of java is related
to C and Object Oriented facial from C++.
Now java is used to create web sites including interactive content,
iphone applications, applications for devices like pagers and cell
phones etc.
Key Features of Java
- Portable
- Secure
- Object Oriented
- Multithreaded
- High Performance
- Dispersed
- Dynamic
What are Basics of Java program?
- Java programs consists of small pieces and are called classes
- These Classes contains methods, which are used to perform tasks
What are java class libraries?
- Class Libraries are also known as Java API that is an
abbreviation of Applications Programming Interface
- They include rich collection of predefined classes, which we can
use in our program
Approaches to Learn Java
- To learn java itself for creating our own classes
- Learn to use the existing classes in libraries
Environment of a java program
Program in
java consists of five phases
- Edit
- Compile
- Loading
- Verify
- Execute
Here is an explanation of each of the step:
Edit
It is an editor which is used to type a java program. Like
Notepad, J Builder, Net Beans
- Extension of a java program
.java is an extension of a java
program.
Like MyFirstProgram.java
Compile
It is the phase in which a program is translated into bytecodes,
which is understandable by Java interpreter.
Javac MyProgram.java
It Creates .class file containing
bytecodes like
(MyFirstProgram.class)
Loading
In this phase
.class file is loaded into main memory by class loader
Classes are loaded and are executed by an
interpreter with java program e.g.
Java
MyFirstProgram
Verify
Bytecode verifier ensures that bytecode is valid and they must
be secure from viruses.
Execute
In this phase, computer interprets a program, only one bytecode at a
particular time and also performs actions that are specified in a
program.
Now let us take an example of a simple java program:
Here it is:
class MyFirstProgram {
public static void main
(String args
[] )
{
System.
out.
println (&ldquo
;Welcome to our first java program
&rdquo
;);
}
}
Explanation of first program
1. class MyFirstProgram {
The line uses the keyword class which is an identifier used to
declare a new class. After the identifier we give the name of our
desired class, in the above example we use MyFirstProgram.
All of the class definition will be in two curly brackets {}.
2. public static void main (String args [] )
- This is the main method of the class which suggests that
program will begin executing. All of the java programs begin their
execution by calling main ().
- Public keyword is an access specifier which allows to control the
visibility of a java program, also it can be declared as private which
is opposite of public. By using private class cannot be accessed from
outside.
- Here the main () must be declared public.
- static allows main () to be called without declaring the objects
- There is only one parameter in main () i.e. String args[],
basically it is an array of instances of the string class
2. System.out.println (“Welcome to our first java program”);
The above line is used to display the string “Welcome to our first
java program” on the screen
The println() is a method which is used
to take the cursor on to a new line
- Hints
- Each java program has at least one class i.e. user defined.
- For better understanding make each word of class capitalize like in
the above example of class we use first letters of all class words
capital “MyFirstProgram”
- Name of class is an identifier.
- Name of class can be made from series of characters like, digits,
letters, dollar signs ($), underscores (_)
- Always assure that name of class must not begin from digit and it
must not contain spaces like 123java or 123 java but it can be
- Java123, WelcomeJava
- Java is a case sensitive language so capitalization will matter and
it gives error