A Java program is a collection of objects, and these objects communicate through method calls to each other to work together. Here is a brief discussion on the Classes and Objects, Method, Instance variables, syntax, and semantics of Java.
Basic terminologies in Java
1. Object: The object is an instance of a class, have Behavior and state.
- Example: A car is an object whose states are: brand, color, number-plate.
- Behavior: Running on the road.
2. Class: The class is a blueprint(plan) of class objects and status.
- Example: Blueprint of the house is class.
3. Method: The behavior of an object is the method.
- Example: The fuel indicator indicates the amount of fuel left in the car.
4. Instance variables: Every object has its own unique set of instance variables. The state of an object is generally created by the values that are assigned to these instance variables.
Example: Steps to compile and run a java program in a console
javac GFG.java java GFG
Note: When the class is public, the name of the file should be the class name.
The Basic Syntax:
1. Comments in Java
There are three types of comments in Java.
i. Single line Comment
ii. Multi-line Comment
/* System.out.println("GFG!"); System.out.println("Alice!"); */
iii. Documentation Comment. Also called a doc comment.
/** documentation */
2. Program File Name
The name of a program file should exactly match the class name with an extension of .java. The name of the file can be other names if the program does not have any public class. Assume you have a public class GFG.
GFG.java // valid syntax gfg.java // invalid syntax
3. Case Sensitivity
Java is a case-sensitive language, which means that the identifiers AB, Ab, aB, and ab are different in Java.
System.out.println("Alice"); // valid syntax system.out.println("Alice"); // invalid syntax
4. Class Names
i. The first letter of the class should be in Uppercase
ii. If several words are used to form a name of the class, each inner word’s first letter should be in Upper Case, Underscore are allowed.
class MyJavaProgram // valid syntax class myJavaProgram // invalid syntax
5. public static void main(String  args)
Java program processing starts with the method main().
6. Method Names
i. All the method names should start with a Lower Case letter.
ii. If several words are used to form the name of the method, then each first letter of the inner word should be in Upper Case, Underscore are allowed.
public void employeeRecords() // valid syntax public void EmployeeRecords() // invalid syntax
7. Identifiers in java
i. All identifiers can begin with a letter (A to Z or a to z) or an underscore _.
ii. The first character of identifiers can have any combination of characters.
iii. Most importantly identifiers are case-sensitive.
iv. A keyword cannot be used as an identifier since it is a reserved word and has some special meaning.
Legal identifiers: MinNumber, total, ak74, hello_world, $amount, _under_value Illegal identifiers: 74ak, -amount
8. White-spaces in Java
A line containing only white-spaces, possibly with the comment, is known as a blank line, and the Java compiler totally ignores it.
9. Access Modifiers: These modifiers control the scope of class and methods.
- Access Modifiers: default, public, protected, private
- Non-access Modifiers: final, abstract, strictfp
10. Java Keywords
Keywords or Reserved words are the words in a language that are used for some internal process or represent some predefined actions. These words are therefore not allowed to use as variable names or objects.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Basic Operators in Java
- ProcessBuilder in Java to create a basic online Judge
- Basic Type Base64 Encoding and Decoding in Java
- Basic Calculator Program Using Java
- How to Create a Basic Color Picker Tool in Android?
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java.Lang.Float class in Java
- Java.io.BufferedInputStream class in Java
- Java.io.ObjectInputStream Class in Java | Set 1
- Java.util.BitSet class in Java with Examples | Set 1
- Java.io.File Class in Java
- Java.io.BufferedWriter class methods in Java
- Java.io.DataOutputStream in Java
- Java.io.StreamTokenizer Class in Java | Set 1
- Java.io.InputStream Class in Java
- Java.io.SequenceInputStream in Java
- Java.io.StreamTokenizer Class in Java | Set 2
- Java.io.Console class in Java
- Java.io.FilterOutputStream Class in Java
- Java.io.StringWriter class in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.