How to Java: E1 (Hello World)

This my first tutorial within the HowToJava series, hope this is the correct way to write it...(helpful advice is encouraged)

In this tutorial, I'll be discussing how to install the Java Development Kit (JDK), and an IDE to run it.

Downloading the JDK

First go to this website JavaSE Downloads and click the option that the arrow indicates (in picture)

Scroll down to the box that says Java SE Development Kit 8u66

Next click Agree then select the JDK for your OS (Linux, OSX, Windows, etc.) and download it

Follow the steps for installing the JDK


Installing Eclipse IDE
The next step is to install an IDE for programming in Java.
For this tutorial, I'll be using Eclipse IDE

Click the one thats in the big banner
Select the right one for your OS (for Windows/Linux, check to see if your OS is 32 or 64bit)

You are free to use an IDE of your choice/preference (Atom, Netbeans, Eclipse, etc.)

Let it install, then follow the steps to set it up.

Now that its installed, run it.

(If you already know how to create new projects in EclipseIDE, you can skip this step)
But for those who don't know, please read below:

Some Java-related information

  • Java projects have a .java as their file extension, and depending on your OS, they may have a big red J as their file icon.
  • Java is a cross-platform programming language ("write anywhere, run anywhere"). Meaning you can build a java program on windows, and have it run on Linux, and vice versa.

Back to the tutorial:

Creating a new Java Project

Click that icon (circled in red) to create a new Java project

Find the folder named Java and select Java Project

Next, you'll find a screen like this (see image below)

Name it whatever you want to, but for the purpose of this tutorial, I'll name it NBExample (Null-byte example)

Make sure you have JavaSE 1.8 selected (if you didn't thats okay. This current tutorial won't require anything too fancy)

Java tends to be backwards compatible (most of the time)

Next, click Finish


Create a Package

The next thing to do is to open the NBExample Java folder from the side of the EclipseIDE panel. And right-click on Src then New then package

Next name the package whatever you want to (but for this, I'll name it nbexample), and click Finish

right-click Package, and select New then click Class

The Class file is where the code goes

Click Finish

Now, you have a file window with some basic stuff

You have keywords in highlighted purple coloring, and normal stuff in normal black text. (except that String is a variable type (its for sentences))

Just about every project has a main method (without one, the Java project cannot run)

Explanation of what the highlighted words mean:

package = basically says where the file is in which sub-folder. (I'm not sure if I make sense, or confused someone.) You can only have one package per file.

public = Says that this class (aka file) is public and can be accessed by other classes within the same Java project

class = states that code within the class' brackets are in the file.

Static = means that the variable or function is shared between all instances of that class as it belongs to the type, not the actual objects themselves

void = Means that the method does not return anything.

{ } = Java does not care about indentation of code (its purely for the viewing pleasure of the programmer/reader). However, to keep things together, Java requires that all classes, methods, loops, (and sometimes if/else statements) have them.

; = The semicolon tells Java "This is the end of this statement". Without it, Java will keep going to the next line(s) until it finds a Semicolon, then determine whether it is proper syntax or not.

On a side note, semicolons enable programmers to be trolls and one-line their Java code, making it near impossible for other people to read. (it doesn't slow the Java Virtual Machine's compile time, since the JVM reads code in a line anyways)

// = Put these before stuff to comment them (one line)

/** */ or /* */ = multiple line comments (adding two ** will tell Java that the comment is a Javadoc, and will appear as a textbox if you hover your mouse over it, it'll display what you wrote in that Javadoc comment)

Other things, I'll explain in later tutorials.

Lets start by getting the project to display Hello World

To do this,

write System.out.println("Hello World") within the main method of the java class. (the one that says public static main(String args){ })

Another way to write it (if you're like me, and don't like having to write System.out.println over and over), is to write import static java.lang.System.*

And yes, System has to be capitalized for it to work

import = allows Java to reference other classes without having to declare the full name every time.

static = though not all imported classes are static, Java.lang.System is. If you don't write it, Java will complain. (i.e. errors will show up)

* = tells the import to import everything within that class (meaning it imports System.out,, etc.); It also works as a multiplication sign.

Now click Run and hit Ok when the pop-up appears, asking which file you want to run

Your end result should look something like this

You've created and ran your first Java project!

Code written from this tutorial can be found on Github

(Next tutorial is being worked on)

I'll try to upload a new tutorial every week or so (but because I'm finishing up school work, the 1Tutorial per week thing may not prove true... So I'll try to upload one once every 2 weeks)

I would love to get some feedback on this first tutorial.
How was it? too short? too long? too much info all at once?


Join the Next Reality AR Community

Get the latest in AR — delivered straight to your inbox.

6 Responses

I have written a Java based backdoor. I am willing to give it to you if you are going to do a tutorial on it

If you want, we can work on it together via private messaging on this forum

I can understand the majority of what is written in the code, though there are some I can guess the meaning/function of. (I might need to look through the Java API to figure some of it out)

Yeah sure let's do that

I am taking a class in Java. This will be a great supplement to my learning! Thanks for the quality tutorial!

Share Your Thoughts

  • Hot
  • Active