Introduction to Eclipse
We use application Eclipse to edit, test, and run Java programs. It is called an IDE (Integrated Development Environment. In this little module, we introduce you to the basics of Eclipse. You will not completely understand the Java code we write; just concentrate on how we are using Eclipse. Besides showing you how to use the IDE in a basic fashion, we give instructions on how to set various preferences, e.g. ensuring that line numbers appear in the editing pane.
The Eclipse workspace
A project is a program that you are writing in Eclipse. Eclipse keeps projects in a workspace. The workspace is just a folder/directory somewhere on your harddrive where Eclipse keeps information about your projects. When you install Eclipse, you can tell Eclipse where to put the workspace. Put it where you can get at it if you have to. On a MAC, you might put it in your user directory in a folder called Eclipse or Workspace. On a Windows machine, you could put it in C:\workspace. Eclipse keeps a file or two in the workspace that contains not only the projects but information about them (called metadata). Don't mess with that file.
For each assignment in this course, create a new project within the workspace. Keep things well organized. When you insert a .java file into a project within the workspace, you either copy the file or link to it. For this course, we suggest that you always copy the file into the workspace.
Basic terminology.
1. A Java class is a description of objects, which can contain methods (functions, procedures) to be called. You will learn about Java classes beginning in lecture 2 of CS2110.
2. A package is a collection of classes. If you are writing them, they will be in a directory or folder on your hard drive.
3. An Eclipse project is a program that you are writing using Eclipse. It consists of a bunch of classes. Every time you want to start a new program, say for a new assignment, you create a new project for it. We can also say that the project contains a Java program.
4. A Java application is a Java program (collection of classes) that has a certain method, main, that can be called to run the program.
0. Creating a project and a class and running it.
This video introduces you to the Eclipse window.
It shows you how to (1) create a project, (2) create a class within the project that is an "application", and
(3) run that application. (~6 minutes).
Click the left head for Java version 8 or
the right head for the newer Java 11. The second one is the first one with a slight modification
due to some changes in Java 11.
Read it here: eclipseIntro.pdf (Java 8) eclipseIntro.pdf (Java 11)
About "hello" in 5 languages
The previous video printed "hello" in the 5 most popular languages, in order of popularity. They are given below, with their meanings. One reason for showing you this is to show that characters from just about all languages can be used in Java, not just the roman letters and numerals to which we are accustomed.
Chinese: 你好 ni hao a respectful hello
Spanish: hola
English: hello
Hindi: नमस्ते namaste I bow to you; the divine within me bows to the divine within you
Arabic: السلام علي
as-salam alaykom peace be upon you
See this webpage: en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers
1. Line numbers and other formatting preferences
Read this page to see how to change settings so that line numbers appear in the editing pane. It shows a few other things too.
2. Importing preferences for automatic formatting
It takes time and effort to keep a program well formatted, so that it is easy to read and understandable. Eclipse can perform some automatic formatting whenever a file is saved, to help with keeping it well formatted. Read this page for instructions on importing and using a file of preferences.
3. Reset the Eclipse window layout
Read this page to see how to reset the Eclipse layout when it gets messed up.
4. Syntax help
The Eclipse editor can help with typing, e.g. adding a semicolon where necessary, and inserting a closing parentheses ")" when you type an opening one "(". Read this page to see how to set your preferences to enable this help.
5. See two Java files open at the same time
This video, in under 1 minute, shows you how to have two files open in the editing pane at the same time. This is useful when one has calls to methods in the other. Here's an example. One class is being developed and tested; the other is a testing class that is being developed to test the first class. (52 seconds). Read it here: twoEditingPanes.pdf
6. TODO comments
Multiline comments that start with TODO play a special role in Eclipse. Read this page to learn more.
7. JUnit testing
Read this page to learn about JUnit testing in Eclipse. It shows you the basics of JUnit testing. You can also learn how to ensure that all your expected tests were actually carried out. Some students think they ran certain tests but didn't, and their programs contain errors because of this, so this is important.
8. Assert statement. Ensuring that it is executed
Read this page to learn about the assert statement, which we use to check various things, like Preconditions of methods. In Java, the default is that the assert statement is not exeuted. This page shows you how to change that setting.
9. Generating javadoc
Read this page to learn about documenting Java programs using javadoc comments and why such documentation is useful as you program.
Read this page to learn how to generate java documentation for your project, using a javadoc command.
This page also shows you how to fix it if the javadoc command is not available.
10. Red square: terminating programs
Read this page to see how to determine that a Java program is running and how to terminate it.
11. Remove unused imports and add missing ones
Read this page to see how to remove unused import statements or add missing import statements.
12. UTF-8 as the character encoding
UTF-8 is a variable-width encoding of all Unicode characters. It includes just about all characters of all languages, musical symbols, and much more. It's the preferred encoding for email and web browsers, and it should also be used in Eclipse. But some versions of Eclipse in Windows 10 may use a different encoding by default, and this should be changed to UTF-8! In Eclipse, use menu item Preferences -> General -> Workspace and select UTF-8 as the Text File Encoding. See en.wikipedia.org/wiki/UTF-8 for more information.