ULOG : Java Programming Basics 4 - First coding solution

in #ulog6 years ago (edited)

Lecture 4 - First Coding Solution


First Coding Exercise
Write a statement to print the text, ‘Hi there’ in Java.

First solution code
System.out.println("Hi there");

First solution output
Hi there

L04_0.png

Hi there, This is Marius from AlefTav Coding. In today's lecture you will learn the solution to the first coding exercise.

public class Lecture4 {
    public static void main(String[] args) {
        // TODO: Write a statement to print the text, ‘Hi there’
   }
}

The homework from the previous tutorial was, Write a statement to print the text, ‘Hi there’ in Java. I gave you starting code with the class as Lecture4, the main() method, and a TODO comment. You were asked to write your solution code at the line where the TODO comment appears.

Solution code

System.out.println("Hi there");

In Java you use the statement println() to check if your code works correctly. You read this as print line or print lin. What you do here is to tell Java to display the specified text and then move the cursor to the beginning of the next line. The format of this statement is, System.out.println(). The word, System is a Java class. Therefore it starts with a capital letter, S. The words, out and println() are all small letters.

The word, println() is a Java method. So, it must be followed by two round brackets, (). Inside these brackets is where you type the text that must be displayed. Also, the text to be displayed must appear between a set of quotation marks " ". Finally, to end a Java statement you add a semi-colon (;).

L04_2.png

When this code is executed, the words, Hi, there are displayed on your computer screen. Please note that your code needs to be EXACTLY like my solution below for it to work.

L04_3.png


In this lecture you learnt the solution to the first coding exercise. Next time I will look at Primitive data types in Java.

I am Marius from AlefTav Coding. Until then, KEEP CODING.


Earn extra steem by joining steemengine and steemfollower at the URL's below:

https://steemengine.net/join?r=4539
https://old.steemfollower.com/?r=18345

This post was made from https://ulogs.org

Sort:  

This user is on the @buildawhale blacklist for one or more of the following reasons:

  • Spam
  • Plagiarism
  • Scam or Fraud

Thank you for your contribution.

  • The tutorial is very basic and easy to find on the internet something more elaborate.

Please read the guidelines here


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

This user is on the @buildawhale blacklist for one or more of the following reasons:

  • Spam
  • Plagiarism
  • Scam or Fraud

Coin Marketplace

STEEM 0.26
TRX 0.11
JST 0.033
BTC 62796.11
ETH 3045.55
USDT 1.00
SBD 3.85