Skip to main content

Java: Syntax

In Java, we must follow a set of rules that are very helpful in executing the code.

Class

In java, every code should be written within the class, and the class should always start with an uppercase letter. Java is case-sensitive, meaning there is a difference between ClassJava and class java.

public class Testing
{
    public static void main(String[] args)
    {
        int x = 50, y = 50 , total;
        total = x + y;
        System.out.println(total);
    }
}

Output: 100

Every java file must be saved with a .java extension to run the code without any hassle.

Main Method

To execute your code, java needs to have a primary method (main()) to get the code up and run. Within this block of the main method, the code gets invoked and executed when we hit run.

public static void main(String[] args)

Verdict:

  • So java is a programming language with a class, and within that class, there should be the main method to run the code.
Tags
Submitted by arilio666 on October 5, 2021

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.