JAVA PROGRAMMING
BASIC STRUCTURE OF JAVA
BASIC STRUCTURE OF JAVA
public class Main {
public static void main(String[ ] args) {
[Link]("Hello and welcome!");
[Link]("This is Java Programming!");
}
}
public class Main {
This is where we define a
class.
A Class name is created by
the programmer following the
rules in naming identifiers
A class can be declared as
public or private to access
data within a class.
public static void main(String[ ] args) {
This is the main method (core of the
program) in Java.
This is the entry point for executing a
Java program
Main method does not return anything
(Keyword: Void)
It can be called without creating an
object. (Keyword: static)
It accepts String type of arguments
Java Output
• System is a class
• out is a public static field:
it accepts output data.
• println() method to display
the string
[Link]
Difference between println(), print() and printf()
print() - It prints string
inside the quotes.
println() - It prints string
inside the quotes similar
like print() method. Then the
cursor moves to the beginning
of the next line.
printf() - It provides string
formatting (similar to printf in C/
C++ programming).
[Link]
Types of Comments in Java
Comments are a portion
of the program that are
completely ignored by
Java compilers.
They are mainly used to
help programmers to
understand the code.
single-line comment
[Link]
Types of Comments in Java
This type of comment is
also known as
Traditional Comment.
In this type of comment,
the Java compiler
ignores everything
from /* to */.
multi-line comment [Link]