[go: up one dir, main page]

0% found this document useful (0 votes)
60 views2 pages

Hello World: Classes

The document provides an introduction to basic Java concepts including classes, the main method, printing to the console, comments, whitespace, compiling, and statements. A class represents a single concept and must contain a main method, which is the entry point for the program. The main method signature is public static void main and it can print output to the console using System.out.println. Comments are used to explain code and come in single-line and multi-line formats. Whitespace is ignored by the compiler. To run a Java program, it must be compiled into bytecode and then executed by the Java Virtual Machine. Statements execute tasks and end with a semicolon.

Uploaded by

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

Hello World: Classes

The document provides an introduction to basic Java concepts including classes, the main method, printing to the console, comments, whitespace, compiling, and statements. A class represents a single concept and must contain a main method, which is the entry point for the program. The main method signature is public static void main and it can print output to the console using System.out.println. Comments are used to explain code and come in single-line and multi-line formats. Whitespace is ignored by the compiler. To run a Java program, it must be compiled into bytecode and then executed by the Java Virtual Machine. Statements execute tasks and end with a semicolon.

Uploaded by

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

Cheatsheets / Learn Java

Hello World
Classes
A class represents a single concept.
A Java program must have one class whose name is the public class Person {
same as the program lename.
In the example, the Person class must be declared in public static void main(String[] args) {
a program le named Person.java.
System.out.println("I am a person, not
a computer.");

main() Method
In Java, every application must contain a main()
method, which is the entry point for the application. All public class Person {
other methods are invoked from the main() method.
The signature of the method is public static
public static void main(String[] args) {

void main(String[] args) { } . It accepts a


System.out.println("Hello, world!");
single argument: an array of elements of type String .

Print Line
System.out.println() can print to the console:
System.out.println("Hello, world!");

System is a class from the core library provided // Output: Hello, world!
by Java


out is an object that controls the output

println() is a method associated with that
object that receives a single argument

/
Comments
Comments are bits of text that are ignored by the
compiler. They are used to increase the readability of a // I am a single line comment!
program.
/*

Single line comments are created by using // .
And I am a
● Multi-line comments are created by starting with multi-line comment!
/* and ending with */ . */

Whitespace
Whitespace, including spaces and newlines, between
statements is ignored. System.out.println("Example of a
statement");

System.out.println("Another statement");

// Output:
// Example of a statement
// Another statement

Compiling Java
In Java, when we compile a program, each individual class
is converted into a .class le, which is known as byte # Compile the class file:
code. javac hello.java
The JVM (Java virtual machine) is used to run the byte
code.
# Execute the compiled file:
java hello

Statements
In Java, a statement is a line of code that executes a task
and is terminated with a ; . System.out.println("Java Programming
☕");

You might also like