Java Basics 3 - Hello World

Words
850
Reading
4 min
Listen
Play
8y

Lecture 3: Hello world

Example problem statement
// Implement ‘Hello world’ in Java

Example solution
// System.out.print("Hello world");

// Hello world

L03.png

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

'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, which is one of Java's forerunners.

A java program contains what are called 'classes'. Let's say I have created one '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 this letter, 'L' in 'Lecture3'. If the name of the class is made up of more than one word, there must be no spaces between the words that make up the class name. In the example, 'Lecture3', there is no space between the letter, 'e' and the number, '2'.
Next, let's say that my class is 'public'. This means it can be accessed from anywhere, with certain limitations. The code of this 'class' must appear between two curly braces, '{ }'.

For a Java 'class' to be useful, you must have at least one 'method'. A 'method' is java code which indicates an action to be performed. Let's say further that I have a 'main' method. The 'main' method is where a Java program starts. In the following heading the word, 'public', again, means accessible from anywhere.

public static void main(String[] args) { }

For those of you who continue your Java studies after this course, you will learn that, while a 'class' is a general idea of something. For example, 'Person'. An 'object' is a specific instance of a person such as someone with the name, 'david'. So that you can then 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'. 'void' means this method does not produce a value that can be passed to another method.

These 4 words are special 'keywords' in Java therefore they start with a small letter, public static void main. But the word 'String' starts with a capital letter, because it is a built-in Java 'class'. It must be followed by 2 square brackets and the word 'args', short for 'arguments'. 'String[] args' is placed between 2 round brackets. And the code for my 'main' method must appear between 2 curly braces.

To print something in Java you need to type the statement, 'System.out.print'. 'System' capital letter starting 'S', but 'out' and 'print' all small letters. 'print()' is a method that needs to be followed by 2 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 2 words, 'hello world' are printed on your screen. These 2 forward slashes are one-line 'comments'. Extra information on one line only. Everything that appears after them is there to explain particular details to human readers of a program. Java ignores anything that appears after these slashes.

This has been a detailed explanation of this 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. And because they persisted and continued their Java studies they now earn very good money as developers. So, if everything did not make sense to you, watch this video again until you understand everything. And then you can call yourself a Java developer.

In programming you will find that that when you have learnt a new skill, it is essential for you to practice that skill by writing out the code. So, with that in mind, here is your homework coding exercise. This 'TODO' comment shows you where you need to write your Java code. Here, the 'TODO' comment is removed and this is the line in your program where you should do your homework. Preferably written 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.

Now for the homework, as follows.

FIRST CODING EXERCISE:
// Write a statement to print the text, ‘Hi there’ in Java.

Today you learnt to print the, 'hello, world' greeting. In the next lecture I will show you the solution to the first coding exercise.

My name is Marius from AlefTav Coding. Till next time, KEEP CODING.

Finally, please upvote, subscribe, like and share. And you can find me at the links below this video.

Find me at these sites:

https://www.youtube.com/channel/UCUr-H9hVVa0ulnQcqQKYmIw?disable_polymer=true
https://plus.google.com/101690479974829208565
https://www.slideshare.net/MariusClaassen1/java-the-basics?qid=4ff400a3-6e42-4e61-9d23-e48029081df6&v=&b=&from_search=5
https://www.udemy.com/course/1435298/manage/basics/
https://d.tube/#!/c/mariusclaassen
https://steemit.com/@mariusclaassen

Java Basics 3 - Hello World | Ecency