Skip to main content

Java: Syntax

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


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;

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)


  • So java is a programming language with a class, and within that class, there should be the main method to run the code.
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.


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.