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

Intro to Java_ Hello World Cheatsheet _ Codecademy

The document provides an introduction to Java programming, covering basic concepts such as printing to the console, comments, compiling Java code, and the structure of a Java program including the main() method. It also discusses the implications of using personal data in computing systems and the ethical and social impacts of programming, particularly in areas like machine learning and AI. Additionally, it explains the importance of classes in Java, emphasizing that each program must have a class matching the filename.

Uploaded by

brucelee565001
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)
4 views

Intro to Java_ Hello World Cheatsheet _ Codecademy

The document provides an introduction to Java programming, covering basic concepts such as printing to the console, comments, compiling Java code, and the structure of a Java program including the main() method. It also discusses the implications of using personal data in computing systems and the ethical and social impacts of programming, particularly in areas like machine learning and AI. Additionally, it explains the importance of classes in Java, emphasizing that each program must have a class matching the filename.

Uploaded by

brucelee565001
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

Cheatsheets / Intro to Java

Hello World

Print Line

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


console:
// Output: Hello, world!
System is a class from the core library
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 with And I am a
/* and ending with */ .
multi-line comment!
*/

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


and is terminated with a ; .
System.out.println("Java Programming ☕️");

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

Computing Systems & Personal Security

Using a user’s personal data can create unique and


personalized online experiences for use; however, there is
a risk to personal privacy when collecting and storing
personal data in a program.
Computing Systems & Ethical and Social Impacts

Programs have had both positive and negative ethical and


social impacts on society. Some examples of this include:
Machine learning: While there are positives to
pattern identification and automation, there is a
problem with data bias and its impact on
marginalized communities.
AI: For example, should a driverless car make
choices that protect the life of the passenger over
the life of another driver or a pedestrian?

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 public static void main(String[] args) {
a program file named Person.java.

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


a computer.");

Print Share

You might also like