Java: Very simple (part1)

Java is a programming language that is mostly used in many new scientific and engineering areas. There are several reasons for the popularity of java language:

1. It is very like C++ programming language, therefore many C++ programmers can start writing JAVA codes very fast.

2. The “Java Virtual Machine” or JVM is a wonderful tool which gives you an environment to do you programming without being worried about the OS you are working with.

3. Java is very explicit, just like C++, but at the same time it is easier to work with it as you don’t need to be worried about the memory management things.

4. Java can handle many applications, which are very hard to be handled in C++.

5. There thousands of Java samples available on the internet that you can simply find what you are looking for and solve most of your problem by the advantage of the available codes.

Hello world project: Traditionally we start the frit step with a hello world application. Before writing the “hello world” program, we give a few tips for compiling you program.

Tips:

1. You need a text editor program, notepad can do the job for the beginning

2. You need java compiler which you can download it from the internet for free (just google “java sun download”)

3. The name of the java compiler is “javac.exe

4. The name of the java environment is “java”

5. Save you java files with the extension “.java”

6. The compiled files will have the extension “.class”

7. To compile you file you have to type: “javac.exe yourfile.java”

8. To run it: “Java yourfile.class”

If you install jdk you can find the necessary file in

C:\Program Files\Java\jdk1.6.0_11\bin

My JDK version might be different from yours!

Let’s put bin files in the path:

1. Click start menu

2. Right-click on “My Computer” to select Properties.

3. Click the “Advanced” tab.

4. Click the “Environment Variable” button.

5. Scroll down the “System variables” list to the “Path” variable.

6. Double click on “Path”

7. Press the “End” key

8. Type (beginning with a semicolon separator); C:\Program Files\Java\jdk1.6.0_11\bin

9. Click “OK”

10. Click “OK” to close the System Properties window.

Now you java development kit is ready to be used.

The coding:

Open notepad and type as below and save the file as “test.java”:

class test

{

public static void main(String args[])

{

System.out.println(“hello”);

}

}

The description of the coding:

class test: in fact you have made a class which can contain some functions

public static void main(String args[]): this is your main function, the java compiler looks for it at when you start compiling a file.

System.out.println: outputs your test inside the parenthesis.

Facebook
Twitter
Pinterest