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

Learn Java - Hello World Cheatsheet - Codecademy

Uploaded by

gadija ishah
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)
21 views

Learn Java - Hello World Cheatsheet - Codecademy

Uploaded by

gadija ishah
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
Print Line
System.out.println() can print to the console:
System.out.println("Hello, world!");
● System is a class from the core library provided by Java // Output: Hello, world!
● 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 program. // I am a single line comment!

● Single line comments are created by using // .


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

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

  }
  
}

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

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

# Execute the compiled file:


java hello
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

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