0% found this document useful (0 votes)
6 views20 pages

Week 4 Java Basic Syntax

The document outlines the basic syntax and structure of a Java program, emphasizing the importance of class definitions and the main method as the starting point for execution. It explains key concepts such as objects, classes, methods, and instance variables, along with naming conventions for classes and methods. Additionally, it highlights the case sensitivity of Java and the requirement for the program file name to match the class name.

Uploaded by

Jeric Mirandilla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views20 pages

Week 4 Java Basic Syntax

The document outlines the basic syntax and structure of a Java program, emphasizing the importance of class definitions and the main method as the starting point for execution. It explains key concepts such as objects, classes, methods, and instance variables, along with naming conventions for classes and methods. Additionally, it highlights the case sensitivity of Java and the requirement for the program file name to match the class name.

Uploaded by

Jeric Mirandilla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

JAVA BASIC SYNTAX

ENGR. JERIC M. MIRANDILLA


Special Science Teacher I
STRUCTURE OF A JAVA
PROGRAM

• Java programs are structured and


follow a strict syntax. The basic
structure always starts with a
class definition, and inside it,
there is a main method where
execution begins.
STRUCTURE OF A JAVA
PROGRAM

Components:
• Class declaration
• Main method
• Statements inside the main
method
• Use of braces {} to define code
blocks
Understanding Java
Basic Syntax

• When we consider a Java


program, it can be defined
as a collection of objects
that communicate via
invoking each other's
methods.
Understanding Java
Basic Syntax

• Object − Objects have states and behaviors.


Example: A dog has states - color, name, breed
as well as behavior such as wagging their tail,
barking, eating. An object is an instance of a
class.
Understanding Java
Basic Syntax

• Class − A class can be defined as a


template/blueprint that describes the
behavior/state that the object of its type
supports.
Understanding Java
Basic Syntax

• Methods − A method is basically a behavior. A


class can contain many methods. It is in
methods where the logics are written, data is
manipulated and all the actions are executed.
Understanding Java
Basic Syntax

• Instance Variables − Each object has its unique


set of instance variables. An object's state is
created by the values assigned to these
instance variables.
Understanding Java Basic Syntax
EXAMPLE
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

• Every line of code that runs in Java must be


inside a class. And the class name should
always start with an uppercase first letter.
Understanding Java Basic Syntax

It is very important to keep in mind


the following points:

• Case Sensitivity
• Java is case sensitive, which
means identifier Hello and hello
would have different meaning in
Java.
Understanding Java Basic Syntax

• Class Names
• For all class names the first letter
should be in Upper Case. If
several words are used to form a
name of the class, each inner
word's first letter should be in
Upper Case.
• Example − class
Understanding Java Basic Syntax

• Method Names
• All method names should start with a
Lower Case letter. If several words
are used to form the name of the
method, then each inner word's first
letter should be in Upper Case.
• Example − public void
myMethodName()
Understanding Java Basic Syntax

• Program File Name


• Name of the program file should exactly match the
class name. When saving the file, you should save
it using the class name and append '.java' to the
end of the name. Please note that in case you do
not have a public class present in the file, then the
file name can be different than the class name. It
is also not mandatory to have a public class in the
file.
• Example − Assume 'MyFirstJavaProgram' is the
class name. Then the file should be saved as
'MyFirstJavaProgram.java'
Understanding Java Basic Syntax

• public static void main(String


args[])
• Java program processing starts
from the main() method which is
a mandatory part of every Java
program.
CLASS DECLARATION

• A class is a container for methods and


variables. In Java, everything must be inside a
class.
CLASS DECLARATION

public class ClassName public class Student


{ {
// variables String name;
// method int age;
} }
• This declares a class named Student with two
attributes: name and age.
MAIN METHOD

• The main method is the entry point


of every Java application. It tells the
JVM where to start execution.
• The main() method is required and
you will see it in every Java program:
MAIN METHOD

Meaning of Keywords:
• public: Accessible from anywhere.
• static: Can be called without creating
an object.
• void: Doesn't return a value.
• String[] args: Used to receive
command-line arguments.
The Print() Method

There is also a print() method, which is


similar to println(). The only difference is
that it does not insert a new line at the
end of the output:
Thank you for
listening!

You might also like