]
Java,  Tutorial

Java – Day 1 : Hello Universe!

Before you start:

You need to download Java Standard Edition from here. Also you need to download Eclipse for Java from here.

Java SE is a required to write any code, while you can choose different IDE(Integrated Development Environment), which is a software you can use as an editor and compiler for the code you write. Assuming you downloaded and install all the requirement we will start writing our first code.

Hello Universe!

Most instructors prefer to introduce you to the programming world by printing on the screen Hello World!. Probably the reason might be they like you to achieve something simple and see its outcome. I will follow the trend but make more alterations.

I created a project in Eclipse and created a class called Day1. we will go over all the details later but first you can try to create a project in Eclipse by going to new java project, name it as you please, then create a class by going to File> New > Class. Then name your file Day1, it is important to watch for UpperCase and lowercase when we write any code as it may result for errors later or styling convention which we will discuss later.

So you created your class and ready to write your code. You can copy/paste or write the following down and we will explain later what every word means but for now to test it just copy the following code to Eclipse and hit Run the green button in the toolbar, if you didn’t see run in the toolbar you can click on Run then Run or use the keyboard shortcut ctrl + F11.



public class Day1 {
	
	public static void main(String [] args){
		
		System.out.print("Hello Universe! My name is Zaki");
		
		
	}

}
Class Day1

When you run your program it should output the following:

Hello Universe! My name is Zaki.

You can replace my name with yours. but the important part of what we are trying to do that we have an output on the screen.

Lets explain what was this code was all about.. The 3rd line in the code is the one responsible for printing out something on the screen. System.out.print(“Something”); Whatever you input inside the parentheses can be printed on the console as you saw earlier.

We will explain everything later, for what is System and out and the dots also what is public and static, void and even main. But lets take it step by step.

The 2nd line public static void main(String [] args){ main() is called entry method for the program, so lets say you have a building its main entrance is the door, when you try to access any building you need to go through the door, similarly main is like a way to enter the written software to be executed. When the compiler starts to read the code it tries to fine what is the main entrance, Java wrote this method for you to write those simple codes to use.

You may noticed those curly brackets { }. We normally say that is a block, which define group of instructions. So main(){ } has its block of code, and class Day1{ } contains the main method block which includes the instructions within main.

You saw public class Day1 we will not explain public or the class yet now but for now, when you write the class name you should start with UpperCase and every word after the first word in uppercase too. While methods has a lowercase beginning like main() and they are followed by parentheses and every word after would have an upper case, we call that style camel case. because it goesUpAndDown like that.

Leave a Reply

Your email address will not be published. Required fields are marked *