HomeJava

Java for Testers – Understanding Java Programs

Java for Testers – Understanding Java Programs

<<Previous Post                    << Complete Tutorial>>                        Next Post>>

In the previous article, I have explained – Creating a Java program in Eclipse IDE

In this article, I will make you understand the Java Program in detail.

Let’s get started.

Java for Testers – Understanding Java Programs

Follow the below steps for understanding the Java Programs:

1)  Below is the Java program we have created in Eclipse IDE, as part of the previous article.

2) class term in the above program is used as a syntax to create/define a Class in Java as shown below:


public class Demo {

}


In the above code, Demo is the Class Name created using the class Java syntax term.

3) In Java programs, we have to enclose everything inside a Class (i.e. starting and ending curly braces of the Class as shown below)


public class Demo {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println(“Hello World!”);

}

}


Observe that all the Java content (displayed in blue color above) is inside the starting and ending braces of the Class (i.e. starting and ending braces in the above code are in red color)

4) On executing any Java programs, the execution stats from the main method (i.e. main method is the beginning point or starting point of execution in Java programs)


public class Demo {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println(“Hello World!”);

}

}


The red marked text is the main method in the above Java program. methods in Java start and end with circular braces as shown above.

5) All the statements inside the Java end with a semicolon symbol  (i.e. ;) as shown in the below example:


public class Demo {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println(“Hello World!”);

}

}


print statement is ending with ; as shown above.

6) All the Java statements should be written inside the methods only.


public class Demo {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println(“Hello World!”);

}

}


In the above program, there is only one statement i.e. print statement and is inside the main() method only.

And the line before the above print statement, which is starting with // is nothing but a comment.

Anything in java which when marked with // will be considered as a comment.

On executing the Java programs, the comments won’t be executed.

7) Apart from the above-mentioned things, there are Java keywords like public, static, void and String args[] in the given Java program and all these keywords will be too early to explain now and will be explained at the proper time later.


public class Demo {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println(“Hello World!”);

}

}


Having this basic understanding of Java programs will help you in understanding the programs in the upcoming articles.

Here concludes this article.

In the next article, I will explain about the compiler errors in Java in a practical way.

Next Steps:

  • > To learn more about Java, continue to the next post (Click on Next Post link below)
  • > Check complete Java Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below:

Happy Learning 🙂

Arun Motoori (www.QAFox.com)

On a mission to help the Testing Community in all possible ways.

<<Previous Post                    << Complete Tutorial>>                        Next Post>>

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *