Jump to content

  •  

Photo
- - - - -

Lesson 1.5: Compiling and running a .java file

Java for Beginners

  • Please log in to reply
No replies to this topic

#1 Wilson18

Wilson18

    Administrator

  • root
  • 112 posts
  • LocationUniversity of Birmingham

Posted 08 October 2014 - 09:45 PM

In this tutorial, I will be showing you how you can compile and run a .Java file on your system. This will be covering the process on Windows, OS X and Ubuntu.

Compiling and Running a .java file on Windows 7

 

The first thing you will need to do is to open CMD through the start menu. You can do this by following the images below.

Attached File  OpenCMD.png   51.79KB   0 downloads

Once you have this open, you can use the cd command to change to the directory where you have your java file stored. You can then use the dir command to make sure it is there. You can see an example of this using the image below.

Attached File  CD_DIR.png   104.22KB   0 downloads

 
The final thing is to compile and run our program. The command for this is as follows

javac Classname.java

to run the program, we type in

java Classname

You can see a full example in the image below

Attached File  Javac_java.png   42.46KB   0 downloads

 

Compiling and Running a .java file on OS X

The first thing you will need to do is to open the Terminal. You can do this by following the images below.

Attached File  OpenTerminal.png   56.01KB   0 downloads

Once you have opened terminal, you will need to navigate to the directory you have stored your .java file. You can use this by using the cd command showing in the screenshot below. You can then view everything in that directory by typing the ls command.
 

Attached File  CD_LS.png   64.9KB   0 downloads

The final thing is to compile and run our program. The command for this is as follows

javac Classname.java

to run the program, we type in

java Classname

You can see a full example in the image below.

Attached File  Javac_Java.png   72.76KB   0 downloads

Compiling and Running a .java file in Ubuntu

 

The first thing you will need to do is to open a Terminal Window. You can do this by following the images below.

Attached File  OpenTerminal.png   292.45KB   0 downloads

Once you have opened terminal, you will need to navigate to the directory you have stored your .java file. You can use this by using the cd command showing in the screenshot below. You can then view everything in that directory by typing the ls command.

Attached File  CD_LS.png   65.45KB   0 downloads

The final thing is to compile and run our program. The command for this is as follows

javac Classname.java

to run the program, we type in

java Classname

You can see a full example in the image below.

Attached File  Javac_Java.png   99.84KB   0 downloads


List what you read?

Check me out on: YouTube, Twitter, Facebook, Google+






Also tagged with one or more of these keywords: Java for Beginners