Site icon TestingDocs.com

Java Program Structure

Overview

This article explains the basic java program structure in detail. These key components make up the Java program. Let’s get started!

Java Program Structure

The components of a Java automation program that defines its structure are as below:

 

 

Javadoc comment

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
*/

Package declaration

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

package com.testingdocs.javaautomation;

specifies that the class can be found in the directory com/testingdocs/javaautomation as shown below

 

Import statements

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

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

Multi-line comments

//This is a multi-line comment with
//two lines…..

Or

/*
This is a multi-line comment
explain about your code here……
*/

Automation code

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.

Read Input in Java Program

https://www.testingdocs.com/java-reading-from-standard-input/

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/java/

Exit mobile version