How to Make Build Compile Run Java Program files
  
        Java Platform, Standard Edition (Java SE) lets you develop and deploy Java applications on desktops and servers, as well as in today's demanding embedded environments. Java offers the rich user interface, performance, versatility, portability, and security that today’s applications require.
Java is a platform independent language. That is, your java files will run in any platform like windows, Linux, Mac etc. But you need JVM (Java Virtual Machine).

It is simple to build and Run a java program. We can make java files using any text editor like notepad in Windows. But you have to save your file with extension‘.java’. But after making a java file, you need JDK (Java Development Kit) for compiling and running your java file.
Download JDK for Windows 32bit(86x)
If above links are not working, or for latest version or for other Operating System like Linux, click here
After download, extract you file.. Remember extracted location.( I extracted on C:\Java)

Now let us write a java program to print "Hello".

  • Open any text editor, here I opened ‘notepad’ (Right click => New => Text Document)

Java is fully object oriented language, so you need to write all your program codes in classes even main of your program.
  • Write down like below on your notepad. 
class myfirst
 {
    public static void main(String s[ ])
{
 System.out.println("Hello");
}
 }

  In java, System.out.println is using to print a text in new line.

How to Make Build Compile Run Java Program files

Name of a java file must be same as name of class which contains program's ‘main’.
Here ‘main’ included in a class named ‘myfirst’. So you must save your file name with ‘myfirst.java’.

How to Make Build Compile Run Java Program files
  • Save your file in anywhere (Remember location; I saved in D drive/Java folder).
  • Now open Command prompt. (Window key + ‘R’ and Type ‘cmd’).
How to Make Build Compile Run Java Program files
  • Click OK or Press Enter.
How to Make Build Compile Run Java Program files
  • Now go to the location of your saved java program file through CMD (mine: D:/myjava).
Default drive is ‘C”. To go to another drive, Type drive letter and colon (Eg: For Drive type ‘D:’) and press enter key. 
How to Make Build Compile Run Java Program files
  • My file is in ‘myjava’ folder in D drive, so for going to folder 'myjava', type ‘cd myjava’ (cd stands for change directory). Like this, go to your java file location. 
How to Make Build Compile Run Java Program files
  • After above step, go to your Java SDK (extracted) folder. You can find a folder named as ‘bin’. Copy its location. I extracted SDK to C:/Java, so my location of folder ‘bin’ is “C:\Java\jdk\bin”. 
How to Make Build Compile Run Java Program files
  • Now type on cmd: path=” C:\Java\jdk\bin” with quotes. Enter. 
How to Make Build Compile Run Java Program files
  • Now type: javac<space>your_programe_name.java. That is here type: ‘javac myfirst.java’ without quotes. Then Enter. 
How to Make Build Compile Run Java Program files
  • Now your CMD screen should be like below. Now compilation completed. If any error occurred, you have to correct them to done compilation. 
How to Make Build Compile Run Java Program files
  • Then type: ‘java myfirst’ without quotes to run this compiled java program. 
How to Make Build Compile Run Java Program files
  • Now you will see your program output as “Hello”. 
How to Make Build Compile Run Java Program files
Like this, you can Build and Run any java program.





1 comment:
  1. I don't have a D drive in my computer can we do the same thing by saving the java file in C drive

    ReplyDelete