Software Development Basics Prepare for Launch

OK, I said that we will see again in a week, but I am too excited with the blog so I decided to write the next entry as soon as possible.

In this post I will show you the tools you need and how to get, install and run them to be able to program in Java.

You need two basic things: install Java on your computer and install an IDE.

 

Installing Java

 

Go to the Java Downloads site . There you need to accept the license agreement and select the correct download for you. In my case it is the Windows x64 option.

Java Download

Wait for it to download and install. It is the typical installation: double click and next until you get tired about it.

Once it is installed you can verify that everything was installed correctly by opening a terminal console (if you use Windows, press the Windows key + R and write cmd). Then you just need to type java and press enter and see something like this:

Java Verification

These steps worked for me in a Windows 8 PC. If you have problems write a comment and I’ll try to help you.

 

Installing Eclipse

 

You can write Java code in the old notepad and compile by hand and it will work, but honestly, I don’t think anyone does that anymore.

 

That is why you need an IDE. An IDE is a software that will help you write, compile, run and debug your code. There are many IDEs including Eclipse, NetBeans, IntelliJ. You can use anyone you like, but this posts will use Eclipse in the examples and the code that will be available in GitHub will be code written in Eclipse.

 

Go to the Eclipse website and download Eclipse IDE for Java Developers. Once again select your version Windows 32 bit, Windows 64 bit or the options available for Linux and Mac OS.

Eclipse Download

After selecting your version, you will get options to select the mirror where you want to download it. Select the one that you want.

Eclipse Download

You will be downloading a .zip file, which means you don’t need to install Eclipse! You just need to unzip it (in Windows right click over the downloaded file and select Extract All or something similar) and select the location where you want to put the files, it doesn’t matter where you put them.

Open the folder where you unzipped Eclipse and double click eclipse.exe.

Eclipse Location

You need to select a folder that will work as a workspace. I recommend having one workspace for each project that you work on. For example, you can have one workspace for this Software Basics series, and in this workspace you can create all the projects that we are going to make.

Once you select your workspace folder and Eclipse loads, you will see its main screen.

Eclipse Main Window

Hello World

Time to write your first program and learn the basics of Eclipse.

First you need to create a new project. You can do this by clicking File -> New -> Java Project. Give a name to your project, maybe “HelloWorld”. You can select Java version to use in this screen. Now the latest version is 1.8, but we will use 1.7. I’m a little skeptical to use the latest version. Click Finish and your project will be created. (If you have the Welcome Screen open you will like to close it because if not, you won’t be able to see your project).

New Project

At the left side of the workspace you will see all the projects in the workspace and all the files for each project. Obviously you need to create a file where you are going to write your code. You can do this by right-clicking on the src folder -> New -> Class. For now you only need to know that a Class is where you write code.

Create a Class

In the next screen write the class name (HelloWorld) and select the checkbox “public static void main(String[] args)” and click finish.

Create a Class

You will get a file with some code in it. You will write your code inside the main method, between the curly brackets.

Class Code

For this example, you are going to write this line:

System.out.println(“Hello World”);

Notice the double quotes and the semicolon at the end and that the code should be between the curly brackets {} of the main method.

 Hello World Code

At the bottom of the workspace make sure you see the Console tab. If you don’t see it open it clicking the Window menu -> Show View -> Console.

 Then you need to see your super code in action! Click the green circle with an arrow that you can find in the top tool bar. If you see an error that says something about not recent launches, you need to click the project name in the left side of the workspace. Then try again. It will ask you the way to run your code. You should select Java Application.

 Run Your Code

Once you run it you will see a special message for you in the Console tab at the bottom of the workspace.

  Hello World Result

This is a super basic program but it shows you three important things: how to create a project, how to create a class, and that Java is running correctly in your computer. If you have an error or problem let me know and I’ll try to help you.

 You can find the code in Github.

 (You can import this code to Eclipse. Select File -> Import -> Git -> Projects from Git -> Clone Directory and paste the link in the URI field. Click next until you finish. Be sure to not have a project with the same name already).

Eclipse brief tutorial

 Things you already know:

  • Create a project
  • Add files to your project
  • Write code in a class
  • Run your project.
  • Open the console window

 Things you need to know

  • Debugging
  • Perspectives
  • Breakpoints

 Some times (every time I should say) your code won’t work and you will have to look for the problem. Your code will have bugs and you will have to fix them. This is called debugging: finding and fixing bugs and errors in your code.

 In Eclipse you can debug your code. You only need to click on the debug button at the top. You will find it easily because it looks just like… a BUG.

 Debug

If you try it, Eclipse will ask you if you want to switch the perspective. What this means is that the Eclipse layout will change to make available to you windows that will help you achieve a certain task, in this case debugging. Click Yes and check to remember your decision. You will get something like this, where you can see the processes that are running, values for variables that you are watching and breakpoints.

 Debug Perspective

If you noticed, you were not able to do anything! This is because you need to add a breakpoint. A breakpoint is a place in the code where the execution will stop and from there you can continue executing by hand, line by line to see what is going on.

 To add a breakpoint double click at the left part of the code just where the code window is about to end. You will see a circle appear. That is the breakpoint and when you debug the code execution will stop there. You can add as many breakpoints as you want.

 Breakpoint

 Now if you debug again the execution will stop in the breakpoint. From there you can do one of these: Step Into (it will jump so you can see the execution of the method), Step Over (it will go to the next line of code without going into it), Resume (it will continue execution until it finds another breakpoint or until it ends). In Windows you can use F5 for Step Into, F6 for Step Over and F8 to resume.

 If you want to go back to the Java perspective (where you write code) click the Java icon at the top right corner.

 Change Perspective

 

 

That is all for today. Next post we will start with programming theory.

 

See you next post.

 

** Questions? Leave a comment or email me.

2 thoughts on “Software Development Basics Prepare for Launch

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s