Language BasicsCreate your first Java programLet's start by compiling and running the following short sample program.
________________
/*
This is a simple Java program. Call this file "progname.java".
*/public class progname {
// Your program begins with a call to main(). public static void main(String args[]) {
System.out.println(
"Java.");
}
}
- Code:
-
/*
This is a simple Java program. Call this file "progname.java".
*/
public class progname {
// Your program begins with a call to main().
public static void main(String args[]) {
System.out.println("Java.");
}
}
In Java, a source file is called a compilation unit. It is a text file that contains one or more class definitions. The Java compiler requires that a source file use the .java filename extension.
In Java, all code must reside inside a class. By convention, the name of the public class should match the its file name. And Java is case-sensitive.
For further explanation...
Open a text editor software, don't worry notepad will do.
Select all of the code then Paste the it in notepad.
Save it with a file name of
progname.java (NOTE: progname.java is used as the file name because the class name must be the same with the file name)
Then compile the program. Follow it
[You must be registered and logged in to see this link.] - Code:
-
/*
This is a simple Java program. Call this file "progname.java".
*/
public class progname {
//the class name is progname, so save it as progname.java
// Your program begins with a call to main().
public static void main(String args[]) {
//The code here will be executed when you start the program, this will be the place in inserting syntax
System.out.println("Java.");
//Displays an output - Java
}
}