Hello World!
Part of the Fundamentals section of Coddy's Java journey — lesson 2 of 73.
The "Hello World!" is a simple program that outputs Hello World! to the screen.
In Java, we use System.out.println() to print output to the console. The text to be printed is placed within double quotes and enclosed in parentheses.
Note that System is capitalized — Java is case-sensitive, so system.out.println() will not work.
Let's take a look at the "Hello World!" program in Java:
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}Here is what each part does:
public class Main— defines a class named Main. Every Java program must have at least one class.public static void main(String[] args)— this is the main method, the entry point of every Java program. When you run a Java program, execution always starts here.System.out.println("Hello World!")— prints the text inside the quotes to the console, followed by a new line.
Challenge
BeginnerUse the code view to write a program that outputs Hello World!
Note that anything inside quotation marks is case sensitive. For example:
System.out.println("Hello World!");System.out.println("hello world!");are different things (notice the capital letters in the first line).
Try it yourself
public class Main {
public static void main(String[] args) {
// Write your code below
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 43Variables Part 2
ConstantsNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementTernary OperatorRecap - If ElseNested If - Else