AllInWorld99 provides a reference manual covering many aspects of web programming, including technologies such as HTML, XHTML, CSS, XML, JavaScript, PHP, ASP, SQL,FLASH, jQuery, java, for loop, switch case, if, if else, for...of, for...in, for...each,while loop, blogger tips, blogger meta tag generator, blogger tricks, blogger pagination, client side script, html code editor, javascript editor with instant output, css editor, online html editor, materialize css tutorial, materialize css dropdown list,break, continue statement, label,array, json, get day and month dropdown list using c# code, CSS button,protect cd or pendrive from virus, cordova, android example, html and css to make android app, html code play,telerik show hide column, Transparent image convertor, copy to clipboard using javascript without using any swf file, simple animation using css, SQL etc. AllInWorld99 presents thousands of code examples (accompanied with source code) which can be copied/downloaded independantly. By using the online editor provided,readers can edit the examples and execute the code experimentally.


Basic of Create and Execute the java Program

     First you need to choose a text editor like Notepad, Notepad++, Wordpad and etc, I recommended to use the Notepad++.

Write a Simple Java Program and Save
     After open your editor write a java program and save it same as class name (class simple) with .java extension, your file name should like classname.java.
File_name.java

where
File_name – it is a file name which used in main method.
Java – extension, it indicate the file type.

Simple Java Program

     The above one is a source file. If the program contains multiple classes, which class has main method, that class name is saves as the file name.

Java Saved Path


Set Path in Java

     Before execute the java program you should set the JDK installed path. All you need to find the JDK  bin folder and copy the path and paste by the following screenshot. In default  JDK Bin folder in C:\Program Files\Java\jdk1.6.0\bin.

set path for java program

     Paste the above copied path to Environment Variable. Right click on my computer => properties => Advanced => Environment Variables.

Set the path in java with Environment variable

     After click on the Environment Variables Find the path in system variable.

Java path


     Click Edit and move to end of the line put semicolon (;) - and 
paste previously copied path (C:\Program Files\Java\jdk1.6.0\bin) then click ok.

Move to program directory

     After create the program and set the path open command prompt (Run=>cmd=>Enter), you can see the window like below screenshot.

Command prompt home page


     Move to program saved directory through DOS command, like below.

DOS command to move the path

Compile the Java Program

      The source code should be compiled and generate the class file like below syntax.
Javac file_name.java

Where 
javac – name of the java complier.
Filename – name of the source file, which is already saved in your system.

Compile Java program

     When compile the java program, java compiler can generate the class file. This class file contain the byte code. Java compiler is automatically named for the class file.

java program class file

     The class file is look like the above marked image.

Execute the java program

     When we execute the java program the program will execute from the class file (sample.class), source code no need.
java File_name

Where
Java – name of the java interpreter.
Filename - name of the source file, which is already saved in your system.
Java interpreter can generate the machine code from the byte code.

Execute Java Program

0 comments:

Post a Comment

Total Pageviews