Java Syntax For Programming And Coding

Back To Page


  Category:  JAVA | 15th August 2024, Thursday

techk.org, kaustub technologies

Java Syntax

In The Previous Chapter, We Created A Java File Named Main.java, Where We Wrote The Following Code To Display "Hello, World!" On The Screen:

Main.java

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

Example Explained

Every Line Of Code That Runs In Java Must Be Inside A class. In Our Example, We Named The Class Main. A Class Should Always Start With An Uppercase First Letter.

Note: Java Is Case-sensitive: "MyClass" And "myclass" Has Different Meaning.

The Name Of The Java File must Match the Class Name. When Saving The File, Save It Using The Class Name And Add ".java" To The End Of The Filename. To Run The Example Above On Your Computer, Make Sure That Java Is Properly Installed: Go To The Get Started Chapter for How To Install Java. The Output Should Be:

Hello World

The Main Method

The main() Method Is Required And You Will See It In Every Java Program:

public static void main(String[] Args)

Any Code Inside The main() method Will Be Executed. Don't Worry About The Keywords Before And After Main. You Will Get To Know Them Bit By Bit While Reading This Tutorial.

For Now, Just Remember That Every Java Program Has A class name Which Must Match The Filename, And That Every Program Must Contain The main() method.

System.out.println()

Inside The main() method, We Can Use The println() method To Print A Line Of Text To The Screen:

public static void main(String[] Args) {
  System.out.println("Hello World");
}

Note: The Curly Braces {} marks The Beginning And The End Of A Block Of Code.

System is A Built-in Java Class That Contains Useful Members, Such As out, Which Is Short For "output". The println() method, Short For "print Line", Is Used To Print A Value To The Screen (or A File).

Don't Worry Too Much About Systemout and println(). Just Know That You Need Them Together To Print Stuff To The Screen.

You Should Also Note That Each Code Statement Must End With A Semicolon (;).

Tags:
Java Syntax, Syntax For Java Programming

Languages Computer Science Web Programming
Java Computer Science HTML
C Programming Quantum Computing
PHP Operating System
Python AI
Links 1 Links 2 Products Pages Follow Us
Home Founder Gallery Payment
About Us MSME Kriti Homeopathy Clinic Contact Us
Blog Privacy Policy CouponPat Sitemap
Cookies Terms of Services Kaustub Study Institute
Disclaimer Partner Java Programming