Anatomy of Java Program

You might be wondering how Java program works and the Anatomy of it. Here it is,


Java is an object-oriented programming language, it contains classes and objects. Every Java program contains at least one class and everything in Java is associated with classes. A class is like a blueprint for creating objects or a factory that produces objects.

anatomy of java
Anatomy of Java program

Functions/Methods –

A function in Java is a block of code that performs a particular task. Starting with specifying the return type of function, some function return value like number, character, boolean and so on. Function in Java have return type like void and many more based on what the return. A function is also as called method in Java.

The name of the function or method should be relevant to the action performed inside. e.g.sendEmail().This name clearly identifies the purpose of the function.

After we have parentheses ‘()’ and inside this parentheses we add parameters. For this function we use parameters to pass the value to our function. e.g. our function sendEmail() has parameters like receiver, subject of Email, What’s the content of Email. After the parentheses we add curly braces ‘{}’ and inside this curly braces we write our actual Java code.

The code is always enclosed between curly braces ‘{}’. In Java each code statement must end with a semicolon ‘;’.

Comments –

Comments in code have purpose that to explain that what the code is doing. Adding comments as you write the code is good practice, because they provide clarification and understanding when you need to refer back to it. As well as as others who read it.

Access Modifiers –

In Java all this classes and methods have access modifier. Access modifier is a keyword that determines if other classes and methods in this program can access the respective class or method. We have various access modifiers like public, private and so on. Most of the times we use public access modifier so we put that in front of method.

Naming convention –

In Java we have Pascal naming convention for naming classes, therefore every class in Java is named in capital, such as for methods and variables its Camel naming convention.

Note :

1. In Java we put the 1st curly braces where we define our function.

2. Every Java program should have at least one function[ main() function ].

For such information :- click here