Laurand Osmeni

Let's build a faster web.

e-mail

How do I compile Java programming on Mac.

First I must create an empty file name called Payroll.java.

The file name also will be the class name of the program.

I shall keep in mind that in Java the file name must be the same as the class name, otherwise it will bring error.

For example, public class Payroll.

Which also is the file name Payroll.java.

Opening the Terminal app on my Mac.

Inserting in Terminal the directory of the project. For example, I have placed my project on desktop, cd desktop.

Terminal will let me know once it verifies the correct location of my Java project.

Then I will begin compiling by typing in: javac Payroll.java and by pressing enter.

Compiler will automatically let know me to know, if I am calling the correct class and file name, if the class and file name differ it will bring error.

Then I type again in Terminal java Payroll, at this time it differs because I am not including the "c" or ".java".

If there is an error in the code, compiler will let me to know where the error is located by including project's line number.

Once the program runs successfully, it will automatically create another file name as Payroll.class. This file is not necessary to be saved, because each time I compile the programm, automatically a new one will be created.

Watch live in action creating the program, or scroll below to copy the entire code.

Java Programming
How to compile java programming on Mac.
// Class name to test the project. public class Payroll { public static void main(String[] args) { // Storing hours integer as 45 hours worked. int hours = 45; // Using double for zeros, storing gross pay and the pay rate which is 30.0. double grossPay, payRate = 30.0; // Multiply both hours and the pay rate. grossPay = hours * payRate; // After multiplication, print on the screen the gross pay. System.out.println("Your gross pay is: $" + grossPay); } }

Feel free to use the code.

Last update .

Navigate between pages.
Top