Sitemap
Ali Habibian

Ali Habibian

I'm a Java Back-End developer with a passion to learn and work with new technologies and learning better ways to write clean and efficient code.

Java Syntax

2 min readMar 6, 2023
Press enter or click to view image in full size
Java syntax

Syntax is the set of rules that define how to write a valid Java program. Some aspects of Java syntax are:

    Get Ali Habibian’s stories in your inbox

    Join Medium for free to get updates from this writer.

  • Every line of code that runs in Java must be inside a class1. A class should always start with an uppercase first letter1. The name of the java file must match the class name1.
  • A class can have fields (instance variables) and methods (behaviors) that define its state and functionality. Fields and methods should start with a lowercase first letter.
  • A method is a block of code that performs a specific task. Every Java program must have a main method, which is the entry point for execution. A method should have a return type, a name, and a list of parameters enclosed in parentheses.
  • Every statement in Java must end with a semicolon (;). Statements can be grouped together using curly braces ({}) to form blocks.
  • Comments are used to explain or document the code. Comments can be single-line (//) or multi-line (/* */) and are ignored by the compiler.
  • Java is case-sensitive, which means that MyClass and myclass have different meanings. Keywords, identifiers, literals, and operators are some of the elements that make up Java syntax.

You can learn more about Java syntax by following online tutorials such as W3Schools or GeeksforGeeks. I hope this helps you understand Java syntax better. 😊

--

--

Ali Habibian
Ali Habibian

Written by Ali Habibian

I'm a Java Back-End developer with a passion to learn and work with new technologies and learning better ways to write clean and efficient code.