Eclipse Authors: Pat Romanski, Elizabeth White, Liz McMillan, David H Deans, JP Morgenthal

Related Topics: Eclipse

Eclipse: Article

SYS-CON Webcast: Eclipse IDE for Students, Useful Eclipse Tips & Tricks

Lesson 10 In The Hugely Popular "Java Basics" SYS-CON.TV Education Series by Yakov Fain

In Lesson 10 of the Java Basics series Yakov Fain shows you how to start working with Eclipse IDE, which is a tool of choice for millions of professional Java programmers. After reading this article you may want to look at another of Yakov's articles for youngsters "Teaching Kids Programming: Even Younger Kids can Learn Java".

Moving to Eclipse

Programmers usually work in a so-called Integrated Development Environment (IDE). You can write, compile and run programs there. An IDE also has a Help thingy that describes all elements of the language, and makes it easier to find and fix errors in your programs. While some IDE programs are expensive, there is an excellent free IDE called Eclipse. You can download it from the Web site www.eclipse.org. In this chapter I'll help you to download and install Eclipse IDE on your computer, create a project there called Hello World, and after this we'll be creating all our programs there.

Make yourself comfortable in Eclipse - it's an excellent tool that many professional Java programmers use.

Installing Eclipse

Open the Web page www.eclipse.org and click on the Download menu on the left (http). Click on the link Main Eclipse Download Site and select the version of Eclipse you want to download. They usually have one latest release and several stable builds. The latest release is an officially released product. Even though stable builds may have more features, they still may have some minor problems. At the time of this writing the latest stable build is 3.0M8.

Select this build and you'll see the following window:


Click on the link (http) next to the word Windows, Mac, or Linux depending on your computer, and download the file with this long name that ends with .zip to any folder on your disk.



Installation of Eclipse is complete! For your convenience, create the shortcut for Eclipse on your desktop. Right-click on the Windows desktop, then press New, Shortcut, Browse, and select the file eclipse.exe in the folder c:\eclipse. To start the program, double-click on the blue icon Eclipse, and you'll see the first Welcome screen (this screen is changing slightly with each Eclipse build):


If your screen looks different, proceed to so-called Workbench, which is the working area for your Java projects.

Getting Started with Eclipse

In this section I'll show you how you can quickly create and run Java programs in Eclipse. You can also find a nice tutorial under the menus Help, Help Contents, and Java Development User Guide.

To start working on a program you'll need to create a new project. A simple project like our HelloWorld will have just one file - HelloWorld.java. Pretty soon we'll create more advanced projects that will consist of several files.

To create a brand new project in Eclipse just click on the menus File, New, Project, and then press the button Next on the New Project window. Now you'll need to enter the name of your new project, for example My First Project:


Look at the grayed out box Directory. It tells you where the files of this project will be located on the disk. Eclipse has a special folder workspace, where it keeps all files for your projects. Later on, you can create separate projects for a calculator program, a Tic-Tac-Toe game, and other programs.

Eclipse workbench has several smaller areas called perspectives which are different views of your projects.


If you click on the little plus sign by My First Project, it'll expand showing you an item Java Run-time Environment (JRE) System Library which is a part of the project. If for any reason you do not see JRE there, click on the menus Windows, Preferences, Java, Editor, Installed JREs, Add, and, using the button Browse find the folder where you have installed Java, for example c:\j2sdk1.5.0.

Creating Programs in Eclipse

Let's recreate the HelloWorld program from Chapter 1 of my e-book Java Programming for Kids, Parents and Grandparents in Eclipse. Java programs are classes that represent objects from real life. You'll learn more about classes in the next chapter.

To create a class in Eclipse select the menus File, New, Class and enter HelloWorld in the field Name. Also, in the section Which methods stubs you would like to create, check off the box

public static void main(String[] args)


Press the button Finish, and you'll see that Eclipse created for you the class HelloWorld. It placed program comments (the text between /* and */) on top - you should change them to describe your class. After the comments you'll find the code of the class HelloWorld with an empty method main(). The word method means action. To run a Java class as a program, this class must have a method called main().


To complete our program, place the cursor after the curly brace in the line with main, push the button Enter and type the following on the new line:

System.out.println("Hello World");

To save the program on disk and compile it, just press at the same time two buttons on your keyboard: Ctrl-S. If you did not make any syntax errors, you won't see any messages - the program is compiled. But let's make an error on purpose to see what's going to happen. Erase the last curly brace and hit Ctrl-S again. Eclipse will display the Unmatched Brace error in the tasks perspective, and also it will place a red mark by the line that has a problem.

As your projects become larger, they'll have several files and compiler may generate more than one error. You can quickly find (not fix though) the problematic lines by double-clicking on the error message in the tasks perspective. Let's put the curly brace back and hit Ctrl-S again - voila, the error message is gone!

Running HelloWorld in Eclipse

Our simple program is a one-class project. But pretty soon your projects will have several Java classes. That's why before running the project for the first time, you need to tell Eclipse which class in this project is the main one.

Select the menu Run, then Run...(make sure that Java Application is selected in the top left corner), and enter the names of the project and the main class:


Now press the button Run, to start the program. It will print the words Hello World in the console view the same way as it did in Chapter 1.

You can run this project by selecting the menus Run, Run Last Launched or by pressing the buttons Ctrl-F11 on the keyboard.

How HelloWorld Works?

Let's start learning what's actually happening in the program HelloWorld.

The class HelloWorld has only one method main(), which is an entry point of a Java application (program). You can tell that main is a method, because it has parentheses after the word main. Methods can call (use) other methods, for example our method main() calls the method println() to display the text Hello World on the screen.

Each method starts with a declaration line called a method signature:

public static void main(String[] args)

This method signature tells us the following:

  • Who can access the method - public. The keyword public means that the method main() could be accessed by any other Java class or JVM itself.
  • Instructions on how to use it - static. The keyword static means that you don't have to create an instance (a copy ) of HelloWorld object in memory to use this method. We'll talk about instances more in the next chapter.
  • Does the method return any data? The keyword void means that the method main() doesn't return any data to the calling program, which is Eclipse in this case. But if for example, a method had to perform some calculations, it could have returned a resulting number to its caller.
  • The name of the method is main.
  • The list of arguments - some data that could be given to the method - String[] args. In the method main() the String[] args means that this method can receive an array of Strings that represent text data. The values that are being passed to a method are called arguments.

As I said before, you can have a program that consists of several classes, but one of them has the method main(). Java class usually have several methods. For example, a class Game can have the methods startGame(), stopGame(), readScore(), and so on.

The body of our method main()has only one line :

System.out.println("Hello World");

Every command or a method call must end with a semicolon ;. The method println()knows how to print data on the system console (command window). Method names in Java are always followed by parentheses. If you see a method with empty parentheses, this means that this method does not have any arguments.

The System.out means that the variable out is defined inside the class System that comes with Java. How are you supposed to know that there's something called out in the class System? Eclipse will help you with this. After you type the word System and a dot, Eclipse will show you everything that is available in this class. At any time you can also put a cursor after the dot and press Ctrl-Space to bring up a help box similar to this one:


The out.println() tells us that there is an object represented by a variable out and this "something called out" has a method called println(). The dot between a class and a method name means that this method exists inside this class. Say you have a class PingPongGame that has a method saveScore(). This is how you can call this method for Dave who won three games:

PingPongGame.saveScore("Dave", 3);

Again, the data between parentheses are called arguments or parameters. These parameters are given to a method for some kind of processing, for example saving data on the disk. The method saveScore() has two arguments -a text string "Dave", and the number 3.

Eclipse will add fun to writing Java programs. The Appendix below has some useful tips and tricks that will speed up your Java programming in this excellent IDE.

Appendix: Eclipse Tips

Eclipse has many little convenient commands that make Java programming a little easier. I've included some useful Eclipse tips here, but I'm sure you'll find more when you start using this tool.

  • If you see a little asterisk in the tab with the class, this means that the class has unsaved code changes.
  • Highlight the name of the class or a method that is used in your code and press the button F3 on your keyboard. This will take you to the line where this class or method was declared.
  • If some of the lines are marked with red error circles, move the mouse over the circle to see the error text.
  • Press Ctrl-F11 to run the last-launched program again.
  • Place the cursor after a curly brace and Eclipse will mark the matching brace.
  • To change the superclass when creating a new class, click on the button Browse, delete the class java.lang.Object and enter the first letter of the class you'd like to use. You'll see a list of available classes to choose from.
  • To copy a class from one package to another, select the class and press Ctrl-C. Select the destination package and press Ctrl-V.
  • To rename a class, a variable or a method, right-click on it and select Refactor and Rename from the popup menu. This will rename every occurrence of this name.
  • If your project needs some external jars, right-click on the project name, select Properties, Java Build Path and press the button Add External Jars.

Eclipse Debugger

Rumor has it that about 40 years ago, when computers were large and would not even fit in your room, all of a sudden one of the programs started giving wrong results. All these troubles were caused by a small bug that was sitting inside the computer somewhere in the wires. When people removed the bug, the program started working properly again. Since then, to debug a program means to find out why it does not give the expected results.

Do not confuse bugs with the compilation errors. Say for example, instead of multiplying the variable by 2, you'll multiply it by 22. This typo will not generate any compilation errors, but the result will be incorrect. Debuggers allow you to step through a running program one line at a time, and you can see and change values of all variables at each point of the program execution.


I'll show you how to use Eclipse debugger using the FishMaster program from Chapter 4 of my e-book  Java Programming for Kids, Parents and Grandparents.

A breakpoint is a line in the code where you'd like program to pause so you can see/change current values of the variables, and some other run-time information. To set a breakpoint just double click on the gray area to the left of the line where you want a program to stop. Let's do it in the FishMaster class on the line myFish.dive(2). You'll see a round bullet on this line which is a breakpoint. Now, select the menus Run, Debug.... Select the application FishMaster and press the button Debug.

FishMaster will start running in the debug mode, and as soon as the program reaches the line myFish.dive(2), it will stop and will wait for your further instructions.

You will see a window similar to the next one.


In the left bottom part of the debug perspective, you see that the line with the breakpoint is highlighted. The blue arrow points at the line that is about to be executed. On the right side (in the Variables view) click on the little plus sign by the variable myFish. Since this variable points at the object Fish, you will see all member variables of this class and their current values, for example currentDepth=20.

The arrows in the top left area allow you to continue execution of the program in different modes. The first bended yellow arrow means step into the method. If you press this arrow (or F5), you'll find yourself inside the method dive(). The window changes and you see the values of the argument howDeep=2 as in the next screenshot. Click on the little plus by the word this to see what are the current values of member variables of this object.

To change the value of the variable, right-click on the variable and enter the new value. This can help when you are not sure why the program does not work correctly and would like to play what if game.


To continue execution one line at a time, keep pressing the next arrow step over (or the button F6).

If you want to continue program in the fast mode, press a small green triangle or the button F8.

To remove the breakpoint just double-click on the little round bullet and it'll disappear. I like using debugger even if my program does not have a bug - it helps me better understand what exactly happens inside the running program.

Where to put a breakpoint? If you have an idea which method gives you problems, put it right before the suspicious line of code. If you are not sure, just put it in the first line of the method main() and slowly walk through the program.


More Stories By Yakov Fain

Yakov Fain is a Java Champion and a co-founder of the IT consultancy Farata Systems and the product company SuranceBay. He wrote a thousand blogs (http://yakovfain.com) and several books about software development. Yakov authored and co-authored such books as "Angular 2 Development with TypeScript", "Java 24-Hour Trainer", and "Enterprise Web Development". His Twitter tag is @yfain

Comments (21)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

@ThingsExpo Stories
DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held November 11-13, 2018, in New York City. Digital Transformation (DX) is a major focus with the introduction of DXWorldEXPO within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of bus...
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, @CloudEXPO and DXWorldEXPO are two of the most important technology events of the year. Since its launch over eight years ago, @CloudEXPO and DXWorldEXPO have presented a rock star faculty as well as showcased hundreds of sponsors and exhibitors! In this blog post, we provide 7 tips on how, as part of our world-class faculty, you can deliver one of the most popular sessions at our events. But before reading...
DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City and will bring together Cloud Computing, FinTech and Blockchain, Digital Transformation, Big Data, Internet of Things, DevOps, AI, Machine Learning and WebRTC to one location.
DXWorldEXPO LLC announced today that ICOHOLDER named "Media Sponsor" of Miami Blockchain Event by FinTechEXPO. ICOHOLDER give you detailed information and help the community to invest in the trusty projects. Miami Blockchain Event by FinTechEXPO has opened its Call for Papers. The two-day event will present 20 top Blockchain experts. All speaking inquiries which covers the following information can be submitted by email to [email protected] Miami Blockchain Event by FinTechEXPO also offers s...
DXWorldEXPO | CloudEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Cloud-enabled transformation has evolved from cost saving measure to business innovation strategy -- one that combines the cloud with cognitive capabilities to drive market disruption. Learn how you can achieve the insight and agility you need to gain a competitive advantage. Industry-acclaimed CTO and cloud expert, Shankar Kalyana presents. Only the most exceptional IBMers are appointed with the rare distinction of IBM Fellow, the highest technical honor in the company. Shankar has also receive...
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities - ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups.
Poor data quality and analytics drive down business value. In fact, Gartner estimated that the average financial impact of poor data quality on organizations is $9.7 million per year. But bad data is much more than a cost center. By eroding trust in information, analytics and the business decisions based on these, it is a serious impediment to digital transformation.
The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
Predicting the future has never been more challenging - not because of the lack of data but because of the flood of ungoverned and risk laden information. Microsoft states that 2.5 exabytes of data are created every day. Expectations and reliance on data are being pushed to the limits, as demands around hybrid options continue to grow.
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
As IoT continues to increase momentum, so does the associated risk. Secure Device Lifecycle Management (DLM) is ranked as one of the most important technology areas of IoT. Driving this trend is the realization that secure support for IoT devices provides companies the ability to deliver high-quality, reliable, secure offerings faster, create new revenue streams, and reduce support costs, all while building a competitive advantage in their markets. In this session, we will use customer use cases...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
The best way to leverage your Cloud Expo presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering Cloud Expo and @ThingsExpo will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at Cloud Expo. Product announcements during our show provide your company with the most reach through our targeted audiences.
The IoT Will Grow: In what might be the most obvious prediction of the decade, the IoT will continue to expand next year, with more and more devices coming online every single day. What isn’t so obvious about this prediction: where that growth will occur. The retail, healthcare, and industrial/supply chain industries will likely see the greatest growth. Forrester Research has predicted the IoT will become “the backbone” of customer value as it continues to grow. It is no surprise that retail is ...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
DXWorldEXPO LLC announced today that "Miami Blockchain Event by FinTechEXPO" has announced that its Call for Papers is now open. The two-day event will present 20 top Blockchain experts. All speaking inquiries which covers the following information can be submitted by email to [email protected] Financial enterprises in New York City, London, Singapore, and other world financial capitals are embracing a new generation of smart, automated FinTech that eliminates many cumbersome, slow, and expe...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...