A Learning Journey

–By Sharing Knowledge

Archive for the ‘Core Java’ Category

Contains the Basic Java Concepts

CHAPTER-IV: Introduction to Java Programming

Posted by krishnamm on February 10, 2009

Chapter-IV

In This Chapter we will learn about the basic java programming. And also compilation and running of a basic java program.

The Basic Structure of a java program is look like this.

class  Helloworld
{
    public static void main(String[] args)
   {
       System.out.println(“Hai Welcome to learning Java”);
  }
}

We will learn about step-by-step:

First check the line #1: class Helloworld.

     In java the program start with a block (which is having ‘{‘ and ‘}’) called class. Helloworld is the name of the class. you can give any name in this place. This is the name of the class.

line#2:

public static void main(String[] args)

we will learn about each and every word in next few chapters. This is the main method. this is as like main() in ‘C’ language.

Any java program contains only one main method. The Program Execution follows from the main. So main is the starting point of a java program execution.

line#3:

System ==> This is Java built in class used for get some system properties like input stream, outputstream, path etc…

out==> this is the output stream.

println() ==> this method will print the message in console.This will print the message with in it.

Ex: Here it will print as “Hai Welcome to learning Java

This is same as printf in ‘C’.

So how to compile this program and run this program.

Do follow the steps:

1. Set the path first (see previous chapter-III)

2. Create a folder name “JavaPrograms”  in C:\  in your Computer (you can create any wher. may be in D:\ or E:\ and the folder name will be any thing.Just for reference i put Java Programs).

3. Save your program in thsi folder with Helloworld.java

4. Go to Start–>run–>type ‘cmd’ (it will open the command prompt)

5. Type cd.. and then type as cd javaprograms

then it will look like C:\javaprograms> in command prompt.

6. javac Helloworld.java (This is called java compilation)

    it will create a Helloworld.class file i nyour C:\Javaprograms folder.

7. After that

    java Helloworld (run the java program)

8. it will print “Hai Welcome to learning Java“.

We wil learn How the Java Compilation and interpratation will be done.

 

 

 

 

 

Posted in Chapter-IV | Leave a Comment »