Key Concepts

Review core concepts you need to learn to master this subject

Java Classes

public class Person { public static void main(String[] args) { System.out.println("I am a person, not a computer."); } }

In Java, 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.

main() Method in Java

public class Person { public static void main(String[] args) { System.out.println("I am a person, not a computer."); } }

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.

Print Line in Java

public class Person { public static void main(String[] args) { System.out.println("I am a person, not a computer."); } }

In Java, 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 output
  • println() is a method associated with that object that receives a single argument

Comments in Java

public class Person { public static void main(String[] args) { System.out.println("I am a person, not a computer."); } }

In Java, 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 made by using // and multi-line comments are made by starting with /* and ending with */.

Whitespace in Java

public class Person { public static void main(String[] args) { System.out.println("I am a person, not a computer."); } }

Whitespace, including spaces and newlines, between statements is ignored.

Compiling in Java

public class Person { public static void main(String[] args) { System.out.println("I am a person, not a computer."); } }

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.

Statements

public class Person { public static void main(String[] args) { System.out.println("I am a person, not a computer."); } }

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

Hello World
Lesson 1 of 1
  1. 1
    Welcome to the world of Java programming! Programming languages enable humans to write instructions that a computer can perform. With precise instructions, computers coordinate applications and sy…
  2. 2
    Java runs on different platforms, but programmers write it the same way. Let’s explore some rules for writing Java. In the last exercise, we saw the file HelloWorld.java. Java files have a **….
  3. 3
    Writing code is an exciting process of instructing the computer to complete fantastic tasks. Code is also read by people, and we want our intentions to be clear to humans just like we want our in…
  4. 4
    As we saw with comments, reading code is just as important as writing code. We should write code that is easy for other people to read. Those people can be co-workers, friends, or even yourself! …
  5. 5
    Java is a compiled programming language, meaning the code we write in a .java file is transformed into byte code by a compiler before it is executed by the Java Virtual Machine on your comp…
  6. 6
    Compilation helped us catch an error. Now that we’ve corrected the file, let’s walk through a successful compilation. As a reminder, we can compile a .java file from the terminal with the comm…
  7. 7
    In this lesson, we’ve started writing our first programs in Java. We’ve also learned rules and guidelines for how to write Java programs: * Java programs have at least one class and one main() me…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo