JTC
Updates
  • Starting New Weekday Batch for Java Full Stack Developer on 24th June 2024 @ 02:00 PM to 04:00 PM
  • Starting New Weekend Batch for Java Full Stack Developer on 06th July 2024 @ 11:00 AM to 02:00 PM
  • Starting New Weekday Batch for Java Full Stack Developer on 08th July 2024 @ 04:00 PM to 06:00 PM
  • Starting New Weekday Batch for Java Full Stack Developer on 29th July 2024 @ 10:00 AM to 12:00 PM
Join Course

Java compilation and running the Java program


Q:1 How do we write a Java program?

  1. Open an editor (Notepad).
  2. Write a program.

            
class FirstProgram{
    public static void main(String [] args) {
        System.out.println("Name :- JTC");
        System.out.println("email :- jtc@jtcindia.org"); 
        System.out.println("job :- software");
        System.out.println("Favourite subject :- Computer science");
    }
}      
            
        
    Name :- JTC
    email :- jtc@jtcindia.org"
    job :- software
    Favourite subject :- Computer science


Q:2 How do we save a Java program?

Save the program (File).

• Select the destination (location) [JTC Folder]
• Write the file name.
• Save with ".java" extension
• Click on save button.

Note:
We cannot save the Java source code with space.

Q:3 How do we compile our Java Program?

1. Open the command prompt.
2. Move to that directory where we have saved out .java file [JTC Folder]

Navigation 1: -

• cd OneDrive
• cd desktop
• cd JTC

Option 2 :-

• cd OneDrive/desktop/JTC

Option 3 :-

Move to JTC folder manually (on click) then
  • Select the directory path
  • Type cmd
  • Press Enter

javac FirstProgram.java

Note: FirstProgram.java is a file in class example

Note: If compiler gets any mistake in code, then we get err message on cmd along with the line no.
Note: If compiler id does not get any error, then we get a .class file on same location [JTC].

Q:4 How we can run our Java Program?

After successful program compilation, as you can see in the above image, we have a .class file which is FirstProgram.class and now we can proceed to run the Program.