0% found this document useful (0 votes)
2 views3 pages

01. Programming Environment

This document provides a cheatsheet for learning Java, covering essential concepts such as printing to the console, comments, compiling Java programs, whitespace, statements, the main() method, and classes. It explains how to use System.out.println() for output, the purpose of comments for readability, and the compilation process to convert Java code into bytecode for execution. Additionally, it highlights the importance of the main() method as the entry point of a Java application and the requirement for class names to match the program filename.
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)
2 views3 pages

01. Programming Environment

This document provides a cheatsheet for learning Java, covering essential concepts such as printing to the console, comments, compiling Java programs, whitespace, statements, the main() method, and classes. It explains how to use System.out.println() for output, the purpose of comments for readability, and the compilation process to convert Java code into bytecode for execution. Additionally, it highlights the importance of the main() method as the entry point of a Java application and the requirement for class names to match the program filename.
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/ 3

Firefox about:srcdoc

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 // Output: Hello, world!
provided 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 And I am a
with /* and ending with */ . multi-line comment!
*/

Compiling Java

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

1 of 3 7/3/25, 16:49
Firefox about:srcdoc

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 System.out.println("Java Programming


task and is terminated with a ; .
");

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.
public static void main(String[] args)
The signature of the method is public static void
main(String[] args) { } . It accepts a single {
argument: an array of elements of type String .
System.out.println("Hello, world!");

2 of 3 7/3/25, 16:49
Firefox about:srcdoc

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 �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.");

Print Share

3 of 3 7/3/25, 16:49

You might also like