Fundamentals of Programming in Java
Fundamentals of Programming in Java
By
Ravi Kant Sahu
Asst. Professor, LPU
Naming Conventions
All the letters of an identifier in Java should be in lower case
Except:
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Identifiers
A name in a program is called an identifier.
The keywords const and goto are reserved but not used.
• class MyJavaProgram
• {
• public static void main(String args[])
{
System.out.println(“Have fun in Java…”);
}
• }
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Compiling and Executing Java Program
Step-1: Save your file with .java extension.
• Example: Program1.java
NOTE: If the class is public then the file name MUST BE same as
the name of the class.
Step-2: Compile your .Java file using javac compiler from the
location where the file is saved.
javac Program1.java
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Compiling and Executing Java Program
java MyJavaProgram
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Access Specifiers
Specifier Sub class Non-Sub class Sub class Non-Sub class
(Same (Same (Different (Different
Package) Package) Package) Package)
private No No No No
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Important Points
A user defined outer class can be either public or default. We can
not define a private or protected class.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)