Java Syntax Quick

When referencing a programming language, the syntax is a set of grammar and spelling rules. In other words, it means using character structures that a computer can interpret. For example, if a user tries to execute a command without the proper syntax, it generates a syntax error, which usually causes the program to fail.

In a text editor or IDE (integrated development environment) that supports syntax highlighting, the programming language's syntax elements (keywords, variable names, operators, etc.) are coloured, making the code easier to read.

Java Syntax

Hello world program in java

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello World");

Each line of code running in Java must be inside a class. In our example, we gave the class the main name. A class should always start with a uppercase first letter.
Java is case-sensitive: "MyAndroid" and "myandroid" have different meanings.
The curly brace { } marks the beginning and end of a block of code.
Each code statement must end with a semicolon. ;

public static means in Java

The modifier public and static can be written in either order (public static or static public), but the convention is to use public static as shown above. You can name any argument, but most programmers choose "args" or "argv".

main Method in Java

The main method is similar to the main function in C and C ++; This is the entry point for your application and will later implement all other methods required for your program.

String[] args in Java

The main method accepts a single argument: an array of elements of type string. An array is the mechanism through which a runtime system provides information for your application.


Java myapp arg1 arg2

System in Java

System class from the core library to print the "Hello World!" message to standard output. Parts of this library (also known as the "Application Programming Interface", or "API")

Post a Comment

Previous Post Next Post