Hello World Flashcards

1
Q

Print Line

A

System.out.println() can print to the console:

  • 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

Ex.
System.out.println(“Hello, world!”);
// Output: Hello, world!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Comments

A

Comments are bits of text that are ignored by the 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 ending with */.

Ex.
// I am a single line comment!

/*
And I am a
multi-line comment!
*/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

main () Method

A

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.

The signature of the method is public static void main(String[] args {}. It accepts a single argument: an array of elements of type String.

Ex.
public class Person {

    public static void main(String[] args) {
       
        System.out.println(“Hello, world!”);
   } }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Classes

A

A class represents a single concept

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 program file named Person.java

Ex.
public class Person {

public static void main(String[] args) {

    System.out.println(“I am a person, not a computer.”);
   } }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Compiling Java

A

Execute the compiled file:

In Java, when we compile a program, each individual class is converted into a .class file., which is known as byte code.

The JVM (Java virtual machine) is used to run the byte code

Ex.
# Compile the class file:
java hello.java

java hello

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Whitespace

A

Whitespace, including spaces and new lines, between statements is ignored.

Ex.
System.out.println(“Example of a statement”);

System.out.println(“Another statement”);

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Statements

A

In Java, a statement is a line of code that executes a task and is terminated with a ; (semicolon).

Ex.
System.out.println(“Java Programming ☕️”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly