Learn more about Java Syntax

As we discuss Syntax in our previous post, blog of C#, Pythonand C++. If you not familiar with the word Syntax, don’t worry. Syntax means a structure or the way of writing particular code for any specific programming language in the context of programming. So today, we shall discuss Java syntax. You can ask or comment in the comment section if you face any issues.

java syntax

Java Syntax

In the previous post, or you can say blog, we created a Java file called Main.java, and we used the following code to print “Hello World!!!” to the screen, or you can say to our console, okay, you can see code of that file below:

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

Output

Hello World!!!

Now Understand the Java Syntax

The line of code that runs or executes in Java must be inside a class. In our code, i.e. above code, we named the class Main. A class should always start with an uppercase first letter, or you can say a Capital letter.

Note: Java is case-sensitive: “MyClass” and “class” have different meanings, which means we must carefully write letters of our choice.

The name of the Java file must match the class name. When saving the file, If it does not match, it can cause a problem for us; save it using the class name and add “.java” to the end of the filename. To run the example above on your computer, ensure Java is correctly installed: Go to the Java Getting Started for how to install Java. The output of the source code or our file code should be:

Output

Hello World!!!

What is The main Method()

The main() method is required, and you will see it in every Java program because it is the entry point of our program; why we call it an entry point because that code run of any file is the code which is in our main method okay now say how can we declare it here is the code below :

public static void main(String[] args)

Note: The curly braces {} mark the beginning and the end of a block of code or our method; now, what is a method? We will discuss it later. The System is a pre-built, or you can say built-in, Java class that contains useful members, such as out, which is short for “output”. The println() method, which is for printing purposes either, can be a text or message, or it can be a number. Okay, later, we will discuss this in the next post, or you can say blog, okay? Don’t need to worry too much about System, out and println(). Just know that you need them together to print stuff to the screen to get our desired output, okay?

You should also note that each code statement must end with a semicolon (;), which is called a terminator.

Now in next blog or post we will discuss how to get output or we can print our text on to console. What could requiredd to do this and what type of code is it okay.

Link: https://Codelikechamp.com

Medium Link: Follow me on Medium

Linkedin Link: Follow me on Linkedin

🤞 Don’t miss any latest posts!

Please subscribe by joining our community for free and stay updated!!!

IF YOU HAVE ALREADY SUBSCRIBED JUST CLOSE THIS FORM !

Leave a Comment

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

Scroll to Top