0% found this document useful (0 votes)
38 views

1 - Learn Java - Hello World Cheatsheet - Codecademy

This document provides an overview of basic Java concepts including printing to the console using System.out.println(), comments, the main method signature, classes, compiling Java code, whitespace, and statements. It explains things like how to create single and multi-line comments, the required structure of a main method, what classes represent, how to compile individual class files, that whitespace is ignored, and that statements are terminated with a semicolon.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

1 - Learn Java - Hello World Cheatsheet - Codecademy

This document provides an overview of basic Java concepts including printing to the console using System.out.println(), comments, the main method signature, classes, compiling Java code, whitespace, and statements. It explains things like how to create single and multi-line comments, the required structure of a main method, what classes represent, how to compile individual class files, that whitespace is ignored, and that statements are terminated with a semicolon.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Cheatsheets / Learn Java

Hello World

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 // I am a single line comment!
compiler. They are used to increase the readability of a
program.
Single line comments are created by using // . /*
Multi-line comments are created by starting with And I am a
/* and ending with */ .
multi-line comment!
*/

main() Method
In Java, every application must contain a main() public class Person {
method, which is the entry point for the application. All
other methods are invoked from the main() method.
The signature of the method is public static void public static void main(String[] args) {
main(String[] args) { } . It accepts a single argument: an
array of elements of type String . System.out.println("Hello, world!");

}
Classes
A class represents a single concept. public class Person {
A Java program must have one class whose name is the
same as the program filename.
In the example, the Person class must be declared in a public static void main(String[] args) {
program file named Person.java.

System.out.println("I am a person, not


a computer.");

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

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

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

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

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

Print Share

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy