1. Introduction to commands
If you once imagined a programmer’s work as something incomprehensible and mysterious, it’s time to debunk that myth! Programming isn’t a secret art, but a fantastic and very interesting job. And you’re about to see for yourself.
Computer programs are written using programming languages—special rules and words that a computer understands. Today you’ll get acquainted with Java: you’ll write your first program, figure out what commands are, and make the computer obey you (as much as it wants to, of course). 😅
A program is a set (list) of commands. First, the first command runs, then the second, third, and so on. When all the commands have been executed, the program finishes.
flowchart LR
A([🚀 Program Starts]) --> B
B[📋 Command 1]
B --> C[📋 Command 2]
C --> D[📋 ...]
D --> E([✅ Program Ends])
style A fill:#4CAF50,color:#fff,stroke:#388E3C
style E fill:#2196F3,color:#fff,stroke:#1565C0
style B fill:#FFF9C4,stroke:#F9A825
style C fill:#FFF9C4,stroke:#F9A825
style D fill:#FFF9C4,stroke:#F9A825
Which commands can be in the list depends on who executes them, or more precisely, on which commands the executor knows (and understands). You can give a dog the command “Sit”, “Speak”, a cat — “Shoo”, a person — “Stop!”, and a robot — “Work!”. 👨💻
A command is a simple instruction to the computer: do this! The key point is — the computer does exactly what you tell it, not what you mean. 😆 At least until artificial intelligence grows up, of course.
The set of commands in Java is quite extensive. For example, this command can print a message to the screen:
System.out.println("A robot is a human's friend");
This command tells the computer: “Print the text "A robot is a human's friend" to the screen.”
If you want the computer to print your phrase three times, give it the command several times.
System.out.println("A robot is a human's friend");
System.out.println("A robot is a human's friend");
System.out.println("A robot is a human's friend");
As a result, the computer will print the phrase 3 times. It’s that simple. 😎
2. The main() method
Your program, depending on its size, can consist of one or several files. Each file contains commands grouped into functions (in Java they are also called methods). A minimal Java program must have at least one method where its execution begins. This method is called main().
The main() method is the entry point to your program. Code execution always starts there. In Java 21 and above, a minimal program can consist of a single main() method, which may even contain no commands.
A minimal program in Java 25 looks like this:
void main()
{
}
As you can see, the main() method in this example doesn’t contain a single command. But it’s still a complete—albeit minimal—program. Its skeleton always looks the same:
void main()
{
// method commands
}
This simplified approach makes Java more approachable for beginners, allowing you to focus on the program’s logic rather than the syntax.
3. Program execution order
Your program simply executes all commands from top to bottom, line by line. When the commands are over, the program ends.
Let’s look at a simple example:
void main()
{
System.out.println("Hello, everyone!");
System.out.println("Today we are learning to write in Java!");
}
The result of running this code will be:
Hello, everyone!
Today we are learning to write in Java!
Add a couple more lines, and the computer will obediently print them to the screen. It’s very hardworking but modest—it won’t write anything extra.
4. Writing and running your first program
Why put off a good thing? Time to move from theory to practice! Let’s write your first program in Java.
Step 1: open WebIDE
Open WebIDE and write a program that prints the message "It’s cool to be a programmer! 😎" to the screen.
You should have a file named Solution.java open.
Step 2: write the following code
You can include emojis—Java supports them perfectly! 🥰
System.out.println("It’s cool to be a programmer!😎");
Step 3: submit the program for checking
At the top of the WebIDE panel you’ll find a "Check" button. Click it.
If you did everything correctly, the server will accept your solution and congratulate you. 😎
You just wrote and successfully submitted your first program in Java. Feels good, right? Now you’re a real programmer (well, at least one step closer to that title). 😇
GO TO FULL VERSION