Category: Java

Added: 19th of October 2021

Updated On: 7th of January 2022

Viewed: 2,862 times

Related Tips & Tutorials

How to compile your Java code using the terminal in Linux, Learning Java

Install Bluej on Ubuntu, Java Development Environment for beginners

Reading user input and outputting the results to console in Java using Scanner class

Simple for loop in Java. Print the numbers 1 to 10 in the console


This article was updated and rechecked on 7th of January 2022

Printing to console in Java using the System.out.println command

What does the code do?
The java code below prints Welcome to My Computer Tips in the console

To print to console in Java we use the System.out.println command.
The following java code prints Welcome to My Computer Tips

public class ConsoleMessage {

public static void main(String[] args) {

System.out.println("Welcome to My Computer Tips");
}

}


Create a new file then copy and paste the code above
Save the file as ConsoleMessage.java

Next open the terminal, and enter the following command to compile the file
javac ConsoleMessage.java


A new file named ConsoleMessage.class will be created

To execute the code enter the following command
java ConsoleMessage