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 command 

Javac MyProgram.java
It Creates .class file containing bytecodes like
(MyFirstProgram.class)

Loading

       In this phase

  • Class Loader

.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

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:

  1. class MyFirstProgram {
  2. public static void main (String args [] )
  3. {
  4. System.out.println (“Welcome to our first java program”);
  5. }
  6. }

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

Tags

Comments

public class shibi{ public static void main(string args[]){ for(int j=5;j>0;j--){ for(int i=j;i>0;i--) { System.out.print(i);} System.out.println(); } } }

package javaapplication8; import java.io.*; public class pattern { public static void main(String[] args) throws IOException { int i,j; InputStreamReader buffer=new InputStreamReader(System.in); BufferedReader buff=new BufferedReader(buffer); for (i=1;i=i;j--) { System.out.print(j+" \t"); } System.out.println(""); } } }
Submitted byhaxxanion Fri, 10/02/2009 - 05:15

Do you have any programs created using Java Applets. I have a project where i need to create a Java Applet (Swing) application on (Bank loan system). If you can help or provide a program or source code of a program or application close to this, i will be glad. And thanks a lot for the excellent tutorials you had made on VB.NET. It was a great help to me. Thank you
Submitted byAnonymous (not verified)on Sat, 01/23/2010 - 17:43

int[] num = { 1, 2, 3, 4, 5 }; for (int x = num.Length; x > 0 ; x--) { for (int y = 0; y
Submitted byAnonymous (not verified)on Mon, 10/11/2010 - 14:52

Hello can u please help me about bubble sort using java

Add new comment