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.
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.
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’.
- Save your file in anywhere (Remember location; I saved in D drive/Java folder).
- Now open Command prompt. (Window key + ‘R’ and Type ‘cmd’).
- Click OK or Press Enter.
- 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.
- 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.
- 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”.
- Now type on cmd: path=” C:\Java\jdk\bin” with quotes. Enter.
Compiling a Java Program
- Now type: javac<space>your_programe_name.java. That is here type: ‘javac myfirst.java’ without quotes. Then Enter.
- 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 Run a Java Program
- Then type: ‘java myfirst’ without quotes to run this compiled java program.
- Now you will see your program output as “Hello”.
Like this, you can Build and Run any java program.
Be First to Comment