

Java program code#
If it was called private, the method would only be visible to the code inside the class itself. The meaning of this will become clearer when we write several classes to work together.

If you start a line with //, the rest of the line will be ignored and considered to be a comment. Lines 6 and 7 are single line comments.It is used purely for readability, the compiler will ignore any empty lines The left curly brace after the classname, Main, indicates the beginning of the class while the right curly brace on line 12 closes it.Curly braces are used to indicate the beginning and ending of a structure.The name of the file in which the class is saved must be the same as the class name and it has to end in.By convention, classnames start with a capital letter.The * at the beginning of the second line is purely for readability.Everything in between these markers will be considered to be comments.You can start a comment block with /** and end it with **/.will create a file called Main.java for you with the following code already entered (without the comments):ģ **/ 4 class Main To the Java compiler it doesn’t matter what you call it but convention is to call it something meaningful so that someone else (or you when you come back to it tomorrow) can infer from the name what it will do.Ĭreate a repl called 01.HelloWorld. So we have to create a file called Main.java. Usually we would call this program HelloWorld, but because of the way works, we have to call it Main. The name of the file in which the class is saved HAS to be the same as the name of the class ending with the extention. This class will be used to build a program that is going to print “Hello World” on the screen. Let’s create a class called HelloWorld (the blue print).

If you are an architect and the computer is the builder, then the architect (the programmer) will provide the builder (the computer) with a blue print (the class) to build (instantiate) something (an object). You can think of a class as a “blue print”. We mentioned on our introductory page that Java is a class based and object oriented language. So the smallest possible program would be the smallest number of instructions that we need to perform a task. A program is a collection of instructions that can be executed by a computer to perform a task. We should probably start by defining what a computer program is. Identify the different parts of the program and explain their purpose. Write the most basic program that can run in Java.
