Java Programming Basics 3 - Hello world

Lecture 3 - Hello world


'Hello world' problem statement
Implement ‘Hello world’ in Java

'Hello World' solution code
System.out.println("Hello world");

'Hello World' output
Hello world


L03_2.png

Hi there, My name is Marius from AlefTav Coding. This is Lecture 3 of my course, Java Basics. In this lecture you will learn how to print out the two words, Hello world.

First, some background information. Hello, world is, traditionally, the first complete program you write when learning a programming language. This convention started in the 1970s with the C programming language, one of Java's forerunners.

public class Lecture3 { 

}

A Java program contains what are called classes. For this tutorial I have created a class with the name Lecture3. When giving your Java classes a name the first letter of every word in the name of the class should be a capital letter, as with the letter L. Then, if the name of the class is made of more than one word, there must be no spaces between the words that make up the class name. In my class name there is no space between the letter, e and the number, 3.

This class is public, which means it can be accessed from anywhere, with certain limitations. Next, the code of class Lecture3 must appear between two curly brackets, { }.

public static void main(String[] args) {

}

For a Java class to be useful, there must be at least one method. A method is java code which indicates an action to be performed. The method created here is a main method, which is where a Java program starts. In this heading there is another occurrence of the word, public, which means accessible from anywhere.

For those of you who continue your Java studies after this course, you will learn that a class is a general idea of something. For example, Person. On the other hand, an object is a specific 'person', for example someone with the name, David. Then you can write code where you say that David is a Person. However, if you add the word, static in the method header you will only work with the general class, Person and not the specific object, David. Next, the word, void means this method does not produce a value that can be passed to another method.

These four words, public static void main() are keywords in Java. Keywords have special meanings and can only be used in certain situations. Also, they start with a small letter.

The word, String starts with a capital letter, because it is a built-in Java class. This word is followed by two square brackets, [ ] and the word args, which is short for arguments.

The words, String[] args is placed between two round brackets, ( ). The code for my main method must appear between two curly brackets, { }.

System.out.println(" ");

To print something in Java you type the statement, System.out.println(" "). The word, System must have the starting capital letter, S, but the words, out and println() must be all small letters. println() is a method that needs to be followed by two round brackets ( ). Between these brackets are the words, Hello world which in turn must appear in quotation marks, " ". Java will print out as text everything between quotation marks. To tell Java that you have reached the end of a statement you add a semi-colon, ;.

Finally, when you run this program, the two words, Hello world are displayed on your computer screen.

In Java two forward slashes, // are one-line comments. Everything that appears after them, on one line, is extra information for human readers of a program. Java ignores anything that appears after these slashes.

This has been a detailed explanation of the most basic Java program. If you are a complete beginner you will find all this information a little overwhelming. However, be comforted by the fact that more than 12 million Java professionals have been where you are now. Furthermore, because they persisted and continued their Java studies they now earn very good money as professional developers. So, if everything did not make sense to you, read this tutorial again until you understand everything. At this point you can call yourself a Java developer.


Coding Exercise

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

In programming you will find that that when you have learnt a new skill, it is essential for you to practise that skill by writing out code. So, with that in mind, here is a coding exercise to complete. The TODO comment shows you where you need to write your Java code. Replace the TODO comment with your solution. Preferably do this homework by hand, in a notebook. I suggest you get a small notebook to write down the coding exercises to get the most out of this course.


In this tutorial you learnt to print the Hello, world greeting. In the next lecture I will show you the solution to this coding exercise.

I am Marius from AlefTav Coding. See you in the next lecture. 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

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now