• Home
  • Jobs
  • Courses
  • Certifications
  • Companies
  • Online IDE
  • Login
  • Signup
MYTAT
  • Home
  • Jobs
  • Courses
  • Certifications
  • Companies
  • Online IDE
  • Login
  • Signup
Java
  • Java Introduction
  • Java Getting Started
  • Java Syntax
  • Java Comments
  • Java Variables
  • Java Data Types
  • Java Type Casting
  • Java Operators
  • Java Strings
  • Java Math
  • Java Booleans
  • Java If ... Else
  • Java Switch
  • Java While Loop
  • Java For Loop
  • Java Break And Continue
  • Java Arrays
  • Java Methods
  • Java Method Parameters
  • Java Method Overloading
  • Java Scope
  • Java Recursion
  • Java OOP
  • Java Classes And Objects
  • Java Class Attributes
  • Java Class Methods
  • Java Constructors
  • Java Modifiers
  • Java Encapsulation
  • Java Packages
  • Java Inheritance
  • Java Polymorphism
  • Java Inner Classes
  • Java Abstraction
  • Java Interface
  • Java Enums
  • Java User Input (Scanner)
  • Java Date And Time
  • Java ArrayList
  • Java LinkedList
  • Java HashMap
  • Java HashSet
  • Java Iterator
  • Java Wrapper Classes
  • Java Exceptions - Try...Catch
  • Java Regular Expressions
  • Java Threads
  • Java Lambda Expressions
  • Java Files
  • Java Create And Write To Files
  • Java Read Files
  • Java Delete Files
  • Home
  • Courses
  • Java
  • Java Syntax

Java Syntax

Previous Next

Java Syntax

 

It seems like you want to continue discussing the previous chapter where we created a Java file named Main.java and used the code to print "Hello World" to the screen. Here's a recap of the code snippet we used:

Try it now

Main.java

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

Example explained

  1. Every line of code in Java must be inside a class:

    • In Java, code is organized into classes, which serve as blueprints for objects. All code must be contained within a class, even if it's just a simple program.
  2. Class names should start with an uppercase letter:

    • By convention, class names in Java start with an uppercase letter. This makes it easier to distinguish classes from other identifiers like variables and methods.
  3. Java is case-sensitive:

    • Java treats uppercase and lowercase letters as distinct. For example, "MyClass" and "myclass" would be considered different identifiers in Java.
  4. File name must match the class name:

    • When saving a Java file, the filename must match the name of the class declared in the file. Additionally, the file should have a ".java" extension to indicate that it contains Java source code.
Hello World



Practice Excercise Practice now

The Main Method

the main() method is indeed required in every Java program. Here are some key points about the main() method:

  1. Entry Point: The main() method serves as the entry point for Java applications. When you execute a Java program, the Java Virtual Machine (JVM) starts by invoking the main() method.

  2. Signature: The main() method must have a specific signature:

    • It must be declared as public, which means it can be accessed from outside the class.
    • It must be declared as static, which means it belongs to the class rather than to any instance of the class.
    • It must return void, indicating that it doesn't return any value.
    • It must be named main.
    • It must accept a single parameter of type String array (String[]), typically named args. This parameter allows command-line arguments to be passed to the program.
  3. Syntax:

    public static void main(String[] args) { // Main method body }
  4. Execution: When you run a Java program, the JVM looks for the main() method in the specified class and starts executing from there. It's where the actual logic of the program begins.

  5. Example Usage:

    • In our previous example, we used the main() method to print "Hello World" to the console. This is a common use case to demonstrate the basic structure of a Java program.

Overall, the main() method is a fundamental part of Java programming, and you'll find it in every Java application. It provides a starting point for program execution and allows you to define the initial behavior of your application. If you have any questions about the main() method or anything else related to Java, feel free to ask!



Practice Excercise Practice now

System.out.println()

nside the main() method, you can use the println() method to print a line of text to the screen. Here's a quick recap:

  1. System.out.println(): In Java, System.out is an object that represents the standard output stream. It provides methods for printing data to the console. The println() method is one such method, which is used to print a line of text to the console.

  2. Usage: You can use the println() method to display messages, variables, or any other information to the user. It automatically adds a newline character at the end of the output, so each call to println() starts a new line.


Try it now

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.

Note: Each code statement must end with a semicolon.



Practice Excercise Practice now

Previous Next
COMPANY
  • About us
  • Careers
  • Contact Us
  • In Press
  • People
  • Companies List
Products
  • Features
  • Coding Assessments
  • Psychometric Assessment
  • Aptitude Assessments
  • Tech/Functional Assessments
  • Video Assessment
  • Fluency Assessment
  • Campus
 
  • Learning
  • Campus Recruitment
  • Lateral Recruitment
  • Enterprise
  • Education
  • K 12
  • Government
OTHERS
  • Blog
  • Terms of Services
  • Privacy Policy
  • Refund Policy
  • Mart Category
Partner
  • Partner Login
  • Partner Signup

Copyright © RVR Innovations LLP 2025 | All rights reserved - Mytat.co is the venture of RVR Innovations LLP