CodeGym /Java Course /Java Syntax /Ready for the first program

Ready for the first program

Java Syntax
Level 0 , Lesson 3
Available

(an hour later)

"Terrific! Where did we stop?"

"The code inside a method or something like that."

"Right. Exactly. The body of a method consists of commands. We could even say that a method is a group of commands that has been given a name (method name). Both statements would be true."

"There are all sorts of commands. Are there dogs on your planet?"

"Only domesticated robotic wolves."

"Do they execute commands?"

"Yep. 'Bite', 'Eat', 'Tear', and 'Good! Heel!'"

Ready for the first program - 1

"Hmm. Nice commands! But there aren't very many of them."

"How many do we need?"

"The Java language has commands for every occasion. Each command describes some action. At the end of each command, we use a semicolon."

"Here are some examples of commands:"

Command Description (what it does)
System.out.println(1);
Displays the number 1 on the screen
System.out.println("Amigo");
Displays "Amigo" on the screen
System.out.println("Rishi & Amigo");
Displays "Rishi & Amigo" on the screen

"Actually, this is just one command System.out.println. We use parentheses to pass arguments to the command. Depending on the value of the arguments, the same command can execute different actions."

"That's very convenient."

"Yes. If you want to display some text on the screen, you put double quotes on each side of it.

A single quotation mark looks like this: '. A double quotation mark looks like this: ". A double quotation mark is not the same thing as two single quotation marks. Please don't confuse them."

"The key for the double quotation mark is next to the Enter button on the keyboard, right?"

"Right."

Amigo’s pulse accelerated from 3 to 5 GHz. He still couldn’t believe it. He had just learned how to print strings on the screen, and it turned out to be much easier that he had expected.
Amigo looked out the window to distract himself from his thoughts and calm down. The leaves were turning yellow. The Rusty Season is very close, he noted automatically. An illuminator let him see much further than usual. The newcomers’ technology was very advanced indeed. But did he care about the leaves now? He would multiply his knowledge again by evening!

Ready for the first program - 2

But his thoughts wouldn’t calm down. One day, he’d write a program to make all robots take refuge in their homes during the Rusty Season. That program alone would save thousands of robo-lives…

"This command has two versions: System.out.println() and System.out.print()"

"If you use the System.out.println() command a few times, you’ll see that each time the text you pass to the command is displayed on a separate line. If you use the System.out.print() command, the text is displayed on the same line. For example:"

Commands What will be displayed on the screen
1
System.out.println("Amigo");
System.out.println("Is The");
System.out.println("Best");
Amigo
Is The
Best
2
System.out.print("Amigo");
System.out.println("Is The");
System.out.print("Best");
AmigoIs The
Best
3
System.out.print("Amigo");
System.out.print("Is The");
System.out.print("Best");
AmigoIs TheBest

"Keep this in mind: println doesn't start printing text from a new line. It prints text on the current line, but makes it so the next text will be printed on a new line."

"The println() command prints the text on the screen and adds a special unseen 'newline character'. This is what makes the next text start on a new line."

"What does the entire program look like?"

"Look at the screen:"

public class Home
{
    public static void main(String[] args)
    {
        System.out.print("Amigo ");
        System.out.print("Is The ");
        System.out.print("Best");
    }
}

"Oh! It's all clear. We added spaces to the ends of the words so they wouldn’t all run together, right?"

"Exactly. You’re a smart little guy."

The comment made Amigo radiate with pride.

"Great. Here’s a task for you.."

Comments (308)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
geofrey machoka Level 1, Germany
1 December 2024
1 system.out.print("I think" ); 2 system.out.print("being a programmer" ); 3 system.out.print("Is cool");
Anonymous #11599292 Level 2, Bangalore, India
30 November 2024
Such a great way to learn java in this kind of way....thank you devolper for this masterpiece.
Bhupender Level 2, Mumbai, India
28 November 2024
Be you for yourself and try something new always.
Joseph Pushpa Raj Level 2, Bengaluru, India
27 November 2024
This is the fantastic way to learn java. Thank you Team
Ruchika Jadhav Level 2, CodeGym University in India, India
11 November 2024
public class Solution { public static void main(String[] args) { System.out.println("I think being a programmer is cool"); } }
Anonymous #11597250 Level 1, Nashik, India
24 November 2024
Hwy radhika I am also trying to learn java
Anonymous #11591470 Level 1, Mumbai, India
9 November 2024
public class Home { public static void main(String[] args) { System.out.printIn("I think being a programmer is cool") } }
Anonymous #11586443 Level 1, Mumbai, India
28 October 2024
public class Home { public static void main(String[] args) { System.out.println("I think being a programmer is cool"); } }
akhila enugu Level 1, India
18 October 2024
public class Home { public static void main(String[] args) { System.out.println("I think being a programmer is cool"); } }
akhila enugu Level 1, India
18 October 2024
public class Home { public static void main(String[] args) { System.out.println("I think being a programmer is cool"); } }
Kpravt Level 1, India
7 October 2024
public class Test{ public static void main(String[]args){ System.out.println("I think being a programmer is cool"); } }