Structure of Java Program
This article explains the basic java program structure in detail. The key components of a Java automation program that defines its structure are as below:
- Javadoc comment.
- Package declaration.
- Import statements.
- Class declaration.
- Program code.
A Javadoc comment starts with a single forward slash and two asterisks (/**) and ends with an asterisk and one slash ( */ ). Each line of the comment starts with one asterisk:
*This is a Javadoc comment
Javadoc comments are used to document code. The documented code can then be turned into a set of HTML pages. The documentation pages will be helpful to others who try to understand the code.
A package is a directory or folder containing the class or interface.
A package declaration describes the folder in which it occurs. For example, the declaration
specifies that the class can be found in the directory com/testingdocs/javaautomation as shown below
The import declaration can be used to make an entire package, or individual classes within a package, access to your Java program. Import statements, allow you to reference data and methods in other packages in your class.
Comments allow you to explain to others what you’re trying to do in your program code. You can have a single line comment or multi-line comment in Java. Note that when the program runs, comments are ignored.
//This is a single line comment
//This is a multi-line comment with
This is a multi-line comment
explain about your code here……
Class is where you write your automation code logic. You can think of a class as a description of an object. It is a bundle of variables and methods that operate on them.
Java requires that each public class be in a separate file and that the file name is the class name with a .java extension. For example, AutomationHandler class must be in a file named AutomationHandler.java. As a convention, and good programming practice it is recommended to put every class in a separate file.
Java Tutorial on this website: https://www.testingdocs.com/java-tutorial/
For more information on Java, visit the official website :