>>> Preliminaries :

1 First of all if you don’t have java install it here : https://java.com/en/download/

2 Download a good text editor. Sublime text is quite good. Download it here : https://www.sublimetext.com/3

>>> Writing the test program :

1 Set the language to JAVA. see bottom right corner.

2 Write the few lines below

public class MyClass {

public static void main(String[] args) {
System.out.print(“first lines”);
}

}

3 MyClass is the name of your program. you can change it

>>> Saving

1 Save the file, go to top left :

File -> save

2 set the name to MyClass or what you wrote instead of that as the file name must be equal to the program name.

The file will be saved as MyClass.java

>>> Checking if java exists

1 Go to command line

2 write java -version

see the – sign don’t forget it.

if you’ve installed java, you must get it !

>>> Changing directory

Go to where you saved the java file

if in C:\JAVA\program folder write

cd C:\JAVA\program

which will change directory of commandline to file location

or you can also start command line where desired by altering the start in: field

>>> Compiling the file

on the command line type :

javac MyClass.java

>>> Optional if error : adding path

if you see java not recognised as internal command etc go to

1 start -> computer -> system properties -> advanced system settings -> environment variables -> path

select then click edit

2 now go to where java is installed normally in C:\program files\java

now open until you get the bin folder

right click on the top and select copy address as text

… now go to 1 again in values paste the address and add a ; at the end

if it is too long just copy and paste in text editor add, then recopy,paste.

Now apply / ok

>>> Running the file

now type :

java MyClass

the program shoud run . . .

notice that MyClass does not have the .java extention here

>>>

Advertisements