Eclipse Java For Mac Os
2021年2月3日Download here: http://gg.gg/o6m5o
*Eclipse Packages | The Eclipse Foundation - Home To A Global ...
*Eclipse Installer 2020-09 R | Eclipse Packages
*Download Eclipse On Mac
*Reference
*Eclipse Mac Os
Installing Java 8 and Eclipse on Mac OS X. This page tells you how to download and install Java 8 and Eclipse on Mac OS X, and how to configure Eclipse. Installing Java 8. Go to the Oracle website. You’ll see something like this.
Eclipse (@ www.eclipse.org) is an open-source Integrated Development Environment (IDE) supported by IBM. Eclipse is popular for Java application development (Java SE and Java EE) and Android apps. It also supports C/C++, PHP, Python, Perl, and other web project developments via extensible plug-ins. Eclipse is cross-platform and runs under Windows, Linux and macOS.
Accept the License Agreement and download the file mapped to Mac OS X x64. In my case it is jdk-7u79-macosx-x64.dmg, you may find it different based on the java version you are trying to install. I was a strong and rigid supporter of Mac as a development environment but ever since Apple’s decision to not port java on later versions of os x my confidence has shaken a little. And please do not even think about doing any j2EE deployment on Mac as it will bring about a tsunami of woes. So long Java but I like my mac book pro too much.Eclipse Versions
The various versions are:
*Eclipse 1.0 (November 7, 2001): based on an earlier Java IDE called VisualAge from IBM.
*Eclipse 2.0 (June 28, 2002)
*Eclipse 2.1 (March 28, 2003)
*Eclipse 3.0 (June 25, 2004)
*Eclipse 3.1 (June 28, 2005)
*Eclipse 3.2 (June 30, 2006) (Callisto - named after one of the Jupiter’s Galilean moons): started annual simultaneous release of all the related Eclipse projects.
*Eclipse 3.3 (June 25, 2007) (Europa - named after another Jupiter’s Galilean moons)
*Eclipse 3.4 (June 19, 2008) (Ganymede - named after yet another Jupiter’s Galilean moons)
*Eclipse 3.5 (June 12, 2009) (Galileo - named after the great 17th century scientist and astronomer Galileo Galilei)
*Eclipse 3.6 (June 23, 2010) (Helios - named after god of the sun in Greek Mythology)
*Eclipse 3.7 (June 23, 2011) (Indigo)
*Eclipse 4.2 (June 27, 2012) (Juno)
*Eclipse 4.3 (June 2013) (Kepler)
*Eclipse 4.4 (June 2014) (Luna)
*Eclipse 4.5 (June 2015) (Mars)
*Eclipse 4.6 (June 2016) (Neon)
*Eclipse 4.7 (June 2017) (Oxygen)
*Eclipse 4.8 (June 2018) (Photon)
*Eclipse 2018-09 (4.9)
*Eclipse 2018-12 (4.10)
*Eclipse 2019-03 (4.11)
*Eclipse 2019-06 (4.12)
*Eclipse 2019-09 (4.13)
*Eclipse 2019-12 (4.14)How to Install Eclipse IDE 2019-12 for Java DevelopersHow to Install Eclipse on WindowsStep 0: Install JDK
To use Eclipse for Java programming, you need to first install Java Development Kit (JDK). Read ’How to Install JDK for Windows’.Step 1: Download
Download Eclipse from https://www.eclipse.org/downloads. Under ’Get Eclipse IDE 2019-12’ ⇒ Click ’Download Packages’. For beginners, choose the ’Eclipse IDE for Java Developers’ and ’Windows 64-bit’ (e.g., ’eclipse-java-2019-12-R-win32-x86_64.zip’ - about 201MB) ⇒ Download.Step 2: Unzip
To install Eclipse, simply unzip the downloaded file into a directory of your choice (e.g., ’c:myProject’).
I prefer the zip version, because there is no need to run any installer. Moreover, you can simply delete the entire Eclipse directory when it is no longer needed (without running any un-installer). You are free to move or rename the directory. You can install (unzip) multiple copies of Eclipse in the same machine.Eclipse Packages | The Eclipse Foundation - Home To A Global ...How to Install Eclipse on macOS
To use Eclipse for Java programming, you need to first install JDK. Read ’How to install JDK for macOS’.
To install Eclipse:
*Goto http://www.eclipse.org/downloads/. Under ’Get Eclipse IDE 2019-12’ ⇒ Click ’Download Packages’. For beginners, select ’Eclipse IDE for Java Developers’ and ’Mac Cocoa 64-bit’. You will receive a DMG file (e.g., ’eclipse-java-2019-12-R-macosx-cocoa-x86_64.dmg’).
*Double-click the downloaded Disk Image (DMG) file. Follow the screen instructions to install Eclipse. Eclipse will be installed under ’/Applications/eclipse’. (To confirm!)How to Install Eclipse on Ubuntu Linux
Eclipse comes with many flavors (See ’Eclipse Packages’ @ https://www.eclipse.org/downloads/compare.php):
*To use Eclipse for Java programming, choose ’Eclipse IDE for Java Developers’ (JavaSE) or ’Eclipse IDE for Java EE Developers’ (JavaEE). You need to first install JDK. Read ’How to install JDK on Ubuntu’.
*To use Eclipse for PHP programming, choose ’Eclipse IDE for PHP Developers’.
*To use Eclipse for C/C++ programming, choose ’Eclipse IDE for C/C++ Developers’.
Nonetheless, you can install any package, and then add more features when needed.
To install Eclipse (e.g, for Java Programming):
*Download Eclipse from http://www.eclipse.org/downloads/. Under ’Get Eclipse IDE 2019-12’ ⇒ Click ’Download Packages’. Choose ’Eclipse IDE for Java Developers’ for Java SE program development; or ’Eclipse IDE for Java EE Developers’ for developing webapps ⇒ Linux 64-bit. You will receive a tarball (e.g., ’eclipse-java-2019-12-R-linux-gtk-x86_64.tar.gz’) in the ’~/Downloads’ folder.
*We shall install Eclipse under /usr/local.
To run Eclipse, open the ’/usr/local/eclipse’ folder and click on the ’Eclipse’ icon; or start a ’Terminal’, enter ’eclipse’.Lock Eclipse on Launcher
Simply start Eclipse. Right-click the Eclipse icon ⇒ Lock to Launcher.
(For older version - If the above don’t work) Create a /usr/share/applications/eclipse.desktop file with the following contents:
Start Eclipse, right-click on the Eclipse icon on launcher ⇒ lock to launcher.Writing your First Java Program in EclipseStep 0: Launch Eclipse
*Launch Eclipse by running ’eclipse.exe’ from the Eclipse installed directory.
*Choose an appropriate directory for your workspace, i.e., where you would like to save your files (e.g., c:myProjecteclipse for Windows) ⇒ Launch.
*If the ’Welcome’ screen shows up, close it by clicking the ’close’ button next to the ’Welcome’ title.Step 1: Create a new Java Project For each Java application, you need to create a project to keep all the source files, classes and relevant resources.
To create a new Java project:
*Choose ’File’ menu ⇒ ’New’ ⇒ ’Java project’ (or ’File’ ⇒ ’New’ ⇒ ’Project’ ⇒ ’Java project’).
*The ’New Java Project’ dialog pops up.
*In ’Project name’, enter ’FirstProject’.
*Check ’Use default location’.
*In ’JRE’, select ’Use default JRE (currently ’JDK11.0.x’)’. But make sure that your JDK is 1.8 and above.
*In ’Project Layout’, check ’Use project folder as root for sources and class files’. Push ’Finish’ button.
*In ’Create module-info.java’ dialog, Click ’Don’t Create’. (Note: For easier version of Eclipse, you need to use the ’Next’ Button in the previous step, and uncheck ’Create module-info.java file’).Step 2: Write a Hello-world Java Program
*In the ’Package Explorer’ (left pane) ⇒ Right-click on ’FirstProject’ (or use the ’File’ menu) ⇒ New ⇒ Class.
*The ’New Java Class’ dialog pops up.
*In ’Source folder’, keep the ’FirstProject’.
*In ’Package’, delete the content if it is not empty.
*In ’Name’, enter ’Hello’.
*Check ’public static void main(String[] args)’.
*Don’t change the rest. Push ’Finish’ button.
*The source file ’Hello.java’ opens on the editor panel (the center pane). Enter the following codes: Step 3: Compile & Execute the Java Program
*There is no need to compile the Java source file in Eclipse explicitly. It is because Eclipse performs the so-called incremental compilation, i.e., the Java statement is compiled as and when it is entered.
*To run the program, right-click anywhere on the source file ’Hello.java’ (or choose ’Run’ menu) ⇒ Run As ⇒ Java Application.
*The output ’Hello, world!’ appears on the Console panel (the bottom pane).NOTES:
*You should create a NEW Java project for EACH of your Java application.
*Nonetheless, Eclipse allows you to keep more than one programs in a project, which is handy for writing toy programs (such as your tutorial exercises). To run a particular program, open and right-click on the source file ⇒ Run As ⇒ Java Application.
*Clicking the ’Run’ button (with a ’Play’ icon) runs the recently-run program (based on the previous configuration). Try clicking on the ’down-arrow’ besides the ’Run’ button.Correcting Syntax Errors
Eclipse performs incremented compilation, as and when a source ’line’ is entered. It marked a source line having syntax error with a RED CROSS. Place your cursor at the RED CROSS to view the error message.
You CANNOT RUN the program if there is any syntax error (marked by a RED CROSS before the filename). Correct all the syntax errors; and RUN the program.
HINTS: In some cases, Eclipse shows a ORANGE LIGHT-BULB (for HINTS) next to the ERROR RED-CROSS (Line 5 in the above diagram). You can click on the LIGHT-BULB to get a list of HINTS to resolve this particular error, which may or may not work!
SYNTAX WARNING: marked by a orange triangular exclaimation sign. Unlike errors, warnings may or may not cause problems. Try to fix these warnings as well. But you can RUN your program with warnings.Read the Eclipse Documentation
At a minimum, you SHOULD browse through Eclipse’s ’Workbench User Guide’ and ’Java Development User Guide’ - accessible via the Eclipse’s ’Welcome’ page or ’Help’ menu. This will save you many agonizing hours trying to figure out how to do somethings later.Debugging Programs in Eclipse
Able to use a graphics debugger to debug program is crucial in programming. It could save you countless hours guessing on what went wrong.Step 0: Write a Java Program
The following program computes and prints the factorial of n (=1*2*3*...*n). The program, however, has a logical error and produce a wrong answer for n=20 (’The Factorial of 20 is -2102132736’ - a negative number?!).
Let’s use the graphic debugger to debug the program.Step 1: Set an Initial Breakpoint
A breakpoint suspends program execution for you to examine the internal states (e.g., value of variables) of the program. Before starting the debugger, you need to set at least one breakpoint to suspend the execution inside the program. Set a breakpoint at main() method by double-clicking on the left-margin of the line containing main(). A blue circle appears in the left-margin indicating a breakpoint is set at that line. Step 2: Start Debugger
Right click anywhere on the source code (or from the ’Run’ menu) ⇒ ’Debug As’ ⇒ ’Java Application’ ⇒ choose ’Yes’ to switch into ’Debug’ perspective (A perspective is a particular arrangement of panels to suits a certain development task such as editing or debugging). The program begins execution but suspends its operation at the breakpoint, i.e., the main() method.
As illustrated in the following diagram, the highlighted line (also pointed to by a blue arrow) indicates the statement to be executed in the next step.Step 3: Step-Over and Watch the Variables and Outputs
Click the ’Step Over’ button (or select ’Step Over’ from ’Run’ menu) to single-step thru your program. At each of the step, examine the value of the variables (in the ’Variable’ panel) and the outputs produced by your program (in the ’Console’ Panel), if any. You can also place your cursor at any variable to inspect the content of the variable.
Single-stepping thru the program and watching the values of internal variables and the outputs produced is the ultimate mean in debugging programs - because it is exactly how the computer runs your program!Step 4: Breakpoint, Run-To-Line, Resume and Terminate
As mentioned, a breakpoint suspends program execution and let you examine the internal states of the program. To set a breakpoint on a particular statement, double-click the left-margin of that line (or select ’Toggle Breakpoint’ from ’Run’ menu).
’Resume’ continues the program execution, up to the next breakpoint, or till the end of the program.
’Single-step’ thru a loop with a large count is time-consuming. You could set a breakpoint at the statement immediately outside the loop (e.g., Line 11 of the above program), and issue ’Resume’ to complete the loop.
Alternatively, you can place the cursor on a particular statement, and issue ’Run-To-Line’ from the ’Run’ menu to continue execution up to the line.
’Terminate’ ends the debugging session. Always terminate your current debugging session using ’Terminate’ or ’Resume’ till the end of the program.Step 5: Switching Back to Java perspective
Click the ’Java’ perspective icon on the upper-right corner to switch back to the ’Java’ perspective for further programming (or ’Window’ menu ⇒ Open Perspective ⇒ Java).
Important: I can’s stress more that mastering the use of debugger is crucial in programming. Explore the features provided by the debuggers.Other Debugger’s Features
Step-Into and Step-Return: To debug a method, you need to use ’Step-Into’ to step into the first statement of the method. (’Step-Over’ runs the function in a single step without stepping through the statements within the function.) You could use ’Step-Return’ to return back to the caller, anywhere within the method. Alternatively, you could set a breakpoint inside a method.
Modify the Value of a Variable: You can modify the value of a variable by entering a new value in the ’Variable’ panel. This is handy for temporarily modifying the behavior of a program, without changing the source code.Tips & TricksGeneral Usages (for all Programming Tasks)
These are the features that I find to be most useful in Eclipse:
*Maximizing Window (Double-Clicking): You can double-click on the ’header’ of any panel to maximize that particular panel, and double-click again to restore it back. This feature is particularly useful for writing source code in full panel.
*Shorthand Templates (sysout, for,...): You can type ’sysout’ followed by a ctrl+space (or alt-/) as a shorthand for typing ’System.out.println()’. The default shortcut key (ctrl-space or alt-/) depends on the system. Check your system’s shortcut key setting in ’Edit’ ⇒ ’Content Assist’ ⇒ ’Default’. Take note that many of you use ctrl+space to switch between input languages. You need to reconfigure either your language switching hot-key or Eclipse. Similarly, you can type ’for’ followed by ctrl-space (or alt-/) to get a for-loop. You can create your own shorthand in ’Window’ menu ⇒ ’Preferences’ ⇒ ’Java’ ⇒ ’Editor’ ⇒ ’Templates’. (Alternatively, in ’Window’ ⇒ ’Preferences’ ⇒ type ’template’ as filter text and choose ’Java’ ⇒ ’Editor’ ⇒ ’Templates’.) You can change your key settings in ’Window’ menu ⇒ ’Preferences’ ⇒ ’General’ ⇒ ’Key’ ⇒ choose ’Command’, ’Content Assist’. (Alternatively, in ’Window’ ⇒ ’Preferences’ ⇒ type ’key’ as filter text and choose ’General’ ⇒ ’Key’.)
*Intelli-Sense (ctrl-space): You can use ctrl-space to activate the ’intelli-sense’ (or content assist). That is, Eclipse will offer you the choices, while you are typing.
*Source Formatting (ctrl-shift-f): Right-click on the source. Choose ’Source’ ⇒ ’Format’ to let Eclipse to layout your source codes with the proper indentation.
*Source Toggle Comment (ctrl-/): To comment/uncomment a block of codes, choose ’Source’ ⇒ ’Toggle Comment’.
*Hints for Correcting Syntax Error: If there is a syntax error on a statement, a red mark will show up on the left-margin on that statement. You could click on the ’light bulb’ to display the error message, and also select from the available hints for correcting that syntax error.
*Refactor (or Rename) (alt-shift-r): You can rename a variable, method, class, package or even the project easily in Eclipse. Select and right-click on the entity to be renamed ⇒ ’Refactor’ ⇒ ’Rename’. Eclipse can rename all the occurrences of the entity.
*Line Numbers: To show the line numbers, choose ’Window’ menu ⇒ ’Preferences’ ⇒ ’General’ ⇒ ’Editors’ ⇒ ’Text Editors’ ⇒ Check the ’Show Line Numbers’ Box. You can also configure many editor options, such as the number of spaces for tab. Alternatively, you can right-click on the left-margin, and check ’Show Line Numbers’.
*Error Message Hyperlink: Click on an error message will hyperlink to the corresponding source statement.
*Changing Font Type and Size: From ’Window’ menu ⇒ ’Preferences’ ⇒ ’General’ ⇒ ’Appearance’ ⇒ ’Colors and Fonts’ ⇒ expand ’Java’ ⇒ ’Java Editor Text Font’ ⇒ ’Edit’. (Alternatively, in ’Window’ ⇒ ’Preferences’ ⇒ type ’font’ as filter text and choose the appropriate entry.)
*Unicode Support: To enable Unicode support, select ’Window’ menu ⇒ Preferences ⇒ General ⇒ Workspace ⇒ Text file encoding ⇒ UTF-8. This sets the default character set used for file encoding, similar to VM’s command-line option -Dfile.encoding=UTF-8. Commonly used charsets for Unicode are UTF-8, UTF-16 (with BOM), UTF-16BE, UTF-16LE. Other charsets are US-ASCII, ISO-8859-1.
*Mouse Hover-over: In debug mode, you could configure to show the variable’s value when the mouse hovers over the variable. Select ’Window’ menu ⇒ ’Preferences’ ⇒ ’Java’ ⇒ ’Editor’ ⇒ ’Hover’.
*Comparing Two Files: In ’Package Explorer’, select two files (hold the control key) ⇒ Right-click ⇒ Compare with.
*Useful Eclipse Shortcut Keys:
*F3: Goto the declaration of the highlighted variable/method.
*Ctrl-Shift-G: Search for ALL references of the highlighted variable/method in workspace.
*Ctrl-G: Search for the Declaration of a variable/method in workspace. Don’t use Find (Ctrl-F), but use the above context-sensitive search.
*Ctrl-Shift-F: Format the source code.
*Ctrl-Shift-O: Organize imports.
*Alt-Shift-R: Rename. (Don’t use Find/Replace.)
*Ctrl-Space: auto-complete.
*Package Explorer vs. Navigator: We usually use ’Package Explorer’ in programming, but it will not show you all the folders and files under the project. On the other hand, ’Navigator’ is a file manager that shows the exact file structure of the project (similar to Windows Explorer). You can enable the Navigator by ’Window’ ⇒ Show view ⇒ Navigator.
*Spell Check: To enable spell check, select Window ⇒ Preferences ⇒ type ’spell’ in the filter ⇒ General ⇒ Editors ⇒ Text Editors ⇒ Spelling ⇒ Check ’Enable spell checking’. Also provide a ’User defined dictionary’ (with an initially empty text file). To correct mis-spell words, right-click and press ctrl-1 (or Edit menu ⇒ Quick Fix).
*Eclipse’s Log File: Goto Help ⇒ about Eclipse ⇒ Installation details ⇒ Configuration ⇒ View Error Log.
*Viewing two files in split screen: Simply click and hold on the title of one file and drag it to the lower side of the screen. [To view the same file on split screen, create a new editor window by selecting Window ⇒ New Editor; and drag one window to the lower side of the screen.]
*Block Select (Column Select): Push Alt-Shift-A to toggle between block-select mode and normal mode.
*Snippets:
*To view the snippet window: choose ’Window’ ⇒ Show View ⇒ Snippets.
*To create a new snippet category: Right-click ⇒ Customize ⇒ New.
*To create a new snippet item: Copy t
https://diarynote.indered.space
*Eclipse Packages | The Eclipse Foundation - Home To A Global ...
*Eclipse Installer 2020-09 R | Eclipse Packages
*Download Eclipse On Mac
*Reference
*Eclipse Mac Os
Installing Java 8 and Eclipse on Mac OS X. This page tells you how to download and install Java 8 and Eclipse on Mac OS X, and how to configure Eclipse. Installing Java 8. Go to the Oracle website. You’ll see something like this.
Eclipse (@ www.eclipse.org) is an open-source Integrated Development Environment (IDE) supported by IBM. Eclipse is popular for Java application development (Java SE and Java EE) and Android apps. It also supports C/C++, PHP, Python, Perl, and other web project developments via extensible plug-ins. Eclipse is cross-platform and runs under Windows, Linux and macOS.
Accept the License Agreement and download the file mapped to Mac OS X x64. In my case it is jdk-7u79-macosx-x64.dmg, you may find it different based on the java version you are trying to install. I was a strong and rigid supporter of Mac as a development environment but ever since Apple’s decision to not port java on later versions of os x my confidence has shaken a little. And please do not even think about doing any j2EE deployment on Mac as it will bring about a tsunami of woes. So long Java but I like my mac book pro too much.Eclipse Versions
The various versions are:
*Eclipse 1.0 (November 7, 2001): based on an earlier Java IDE called VisualAge from IBM.
*Eclipse 2.0 (June 28, 2002)
*Eclipse 2.1 (March 28, 2003)
*Eclipse 3.0 (June 25, 2004)
*Eclipse 3.1 (June 28, 2005)
*Eclipse 3.2 (June 30, 2006) (Callisto - named after one of the Jupiter’s Galilean moons): started annual simultaneous release of all the related Eclipse projects.
*Eclipse 3.3 (June 25, 2007) (Europa - named after another Jupiter’s Galilean moons)
*Eclipse 3.4 (June 19, 2008) (Ganymede - named after yet another Jupiter’s Galilean moons)
*Eclipse 3.5 (June 12, 2009) (Galileo - named after the great 17th century scientist and astronomer Galileo Galilei)
*Eclipse 3.6 (June 23, 2010) (Helios - named after god of the sun in Greek Mythology)
*Eclipse 3.7 (June 23, 2011) (Indigo)
*Eclipse 4.2 (June 27, 2012) (Juno)
*Eclipse 4.3 (June 2013) (Kepler)
*Eclipse 4.4 (June 2014) (Luna)
*Eclipse 4.5 (June 2015) (Mars)
*Eclipse 4.6 (June 2016) (Neon)
*Eclipse 4.7 (June 2017) (Oxygen)
*Eclipse 4.8 (June 2018) (Photon)
*Eclipse 2018-09 (4.9)
*Eclipse 2018-12 (4.10)
*Eclipse 2019-03 (4.11)
*Eclipse 2019-06 (4.12)
*Eclipse 2019-09 (4.13)
*Eclipse 2019-12 (4.14)How to Install Eclipse IDE 2019-12 for Java DevelopersHow to Install Eclipse on WindowsStep 0: Install JDK
To use Eclipse for Java programming, you need to first install Java Development Kit (JDK). Read ’How to Install JDK for Windows’.Step 1: Download
Download Eclipse from https://www.eclipse.org/downloads. Under ’Get Eclipse IDE 2019-12’ ⇒ Click ’Download Packages’. For beginners, choose the ’Eclipse IDE for Java Developers’ and ’Windows 64-bit’ (e.g., ’eclipse-java-2019-12-R-win32-x86_64.zip’ - about 201MB) ⇒ Download.Step 2: Unzip
To install Eclipse, simply unzip the downloaded file into a directory of your choice (e.g., ’c:myProject’).
I prefer the zip version, because there is no need to run any installer. Moreover, you can simply delete the entire Eclipse directory when it is no longer needed (without running any un-installer). You are free to move or rename the directory. You can install (unzip) multiple copies of Eclipse in the same machine.Eclipse Packages | The Eclipse Foundation - Home To A Global ...How to Install Eclipse on macOS
To use Eclipse for Java programming, you need to first install JDK. Read ’How to install JDK for macOS’.
To install Eclipse:
*Goto http://www.eclipse.org/downloads/. Under ’Get Eclipse IDE 2019-12’ ⇒ Click ’Download Packages’. For beginners, select ’Eclipse IDE for Java Developers’ and ’Mac Cocoa 64-bit’. You will receive a DMG file (e.g., ’eclipse-java-2019-12-R-macosx-cocoa-x86_64.dmg’).
*Double-click the downloaded Disk Image (DMG) file. Follow the screen instructions to install Eclipse. Eclipse will be installed under ’/Applications/eclipse’. (To confirm!)How to Install Eclipse on Ubuntu Linux
Eclipse comes with many flavors (See ’Eclipse Packages’ @ https://www.eclipse.org/downloads/compare.php):
*To use Eclipse for Java programming, choose ’Eclipse IDE for Java Developers’ (JavaSE) or ’Eclipse IDE for Java EE Developers’ (JavaEE). You need to first install JDK. Read ’How to install JDK on Ubuntu’.
*To use Eclipse for PHP programming, choose ’Eclipse IDE for PHP Developers’.
*To use Eclipse for C/C++ programming, choose ’Eclipse IDE for C/C++ Developers’.
Nonetheless, you can install any package, and then add more features when needed.
To install Eclipse (e.g, for Java Programming):
*Download Eclipse from http://www.eclipse.org/downloads/. Under ’Get Eclipse IDE 2019-12’ ⇒ Click ’Download Packages’. Choose ’Eclipse IDE for Java Developers’ for Java SE program development; or ’Eclipse IDE for Java EE Developers’ for developing webapps ⇒ Linux 64-bit. You will receive a tarball (e.g., ’eclipse-java-2019-12-R-linux-gtk-x86_64.tar.gz’) in the ’~/Downloads’ folder.
*We shall install Eclipse under /usr/local.
To run Eclipse, open the ’/usr/local/eclipse’ folder and click on the ’Eclipse’ icon; or start a ’Terminal’, enter ’eclipse’.Lock Eclipse on Launcher
Simply start Eclipse. Right-click the Eclipse icon ⇒ Lock to Launcher.
(For older version - If the above don’t work) Create a /usr/share/applications/eclipse.desktop file with the following contents:
Start Eclipse, right-click on the Eclipse icon on launcher ⇒ lock to launcher.Writing your First Java Program in EclipseStep 0: Launch Eclipse
*Launch Eclipse by running ’eclipse.exe’ from the Eclipse installed directory.
*Choose an appropriate directory for your workspace, i.e., where you would like to save your files (e.g., c:myProjecteclipse for Windows) ⇒ Launch.
*If the ’Welcome’ screen shows up, close it by clicking the ’close’ button next to the ’Welcome’ title.Step 1: Create a new Java Project For each Java application, you need to create a project to keep all the source files, classes and relevant resources.
To create a new Java project:
*Choose ’File’ menu ⇒ ’New’ ⇒ ’Java project’ (or ’File’ ⇒ ’New’ ⇒ ’Project’ ⇒ ’Java project’).
*The ’New Java Project’ dialog pops up.
*In ’Project name’, enter ’FirstProject’.
*Check ’Use default location’.
*In ’JRE’, select ’Use default JRE (currently ’JDK11.0.x’)’. But make sure that your JDK is 1.8 and above.
*In ’Project Layout’, check ’Use project folder as root for sources and class files’. Push ’Finish’ button.
*In ’Create module-info.java’ dialog, Click ’Don’t Create’. (Note: For easier version of Eclipse, you need to use the ’Next’ Button in the previous step, and uncheck ’Create module-info.java file’).Step 2: Write a Hello-world Java Program
*In the ’Package Explorer’ (left pane) ⇒ Right-click on ’FirstProject’ (or use the ’File’ menu) ⇒ New ⇒ Class.
*The ’New Java Class’ dialog pops up.
*In ’Source folder’, keep the ’FirstProject’.
*In ’Package’, delete the content if it is not empty.
*In ’Name’, enter ’Hello’.
*Check ’public static void main(String[] args)’.
*Don’t change the rest. Push ’Finish’ button.
*The source file ’Hello.java’ opens on the editor panel (the center pane). Enter the following codes: Step 3: Compile & Execute the Java Program
*There is no need to compile the Java source file in Eclipse explicitly. It is because Eclipse performs the so-called incremental compilation, i.e., the Java statement is compiled as and when it is entered.
*To run the program, right-click anywhere on the source file ’Hello.java’ (or choose ’Run’ menu) ⇒ Run As ⇒ Java Application.
*The output ’Hello, world!’ appears on the Console panel (the bottom pane).NOTES:
*You should create a NEW Java project for EACH of your Java application.
*Nonetheless, Eclipse allows you to keep more than one programs in a project, which is handy for writing toy programs (such as your tutorial exercises). To run a particular program, open and right-click on the source file ⇒ Run As ⇒ Java Application.
*Clicking the ’Run’ button (with a ’Play’ icon) runs the recently-run program (based on the previous configuration). Try clicking on the ’down-arrow’ besides the ’Run’ button.Correcting Syntax Errors
Eclipse performs incremented compilation, as and when a source ’line’ is entered. It marked a source line having syntax error with a RED CROSS. Place your cursor at the RED CROSS to view the error message.
You CANNOT RUN the program if there is any syntax error (marked by a RED CROSS before the filename). Correct all the syntax errors; and RUN the program.
HINTS: In some cases, Eclipse shows a ORANGE LIGHT-BULB (for HINTS) next to the ERROR RED-CROSS (Line 5 in the above diagram). You can click on the LIGHT-BULB to get a list of HINTS to resolve this particular error, which may or may not work!
SYNTAX WARNING: marked by a orange triangular exclaimation sign. Unlike errors, warnings may or may not cause problems. Try to fix these warnings as well. But you can RUN your program with warnings.Read the Eclipse Documentation
At a minimum, you SHOULD browse through Eclipse’s ’Workbench User Guide’ and ’Java Development User Guide’ - accessible via the Eclipse’s ’Welcome’ page or ’Help’ menu. This will save you many agonizing hours trying to figure out how to do somethings later.Debugging Programs in Eclipse
Able to use a graphics debugger to debug program is crucial in programming. It could save you countless hours guessing on what went wrong.Step 0: Write a Java Program
The following program computes and prints the factorial of n (=1*2*3*...*n). The program, however, has a logical error and produce a wrong answer for n=20 (’The Factorial of 20 is -2102132736’ - a negative number?!).
Let’s use the graphic debugger to debug the program.Step 1: Set an Initial Breakpoint
A breakpoint suspends program execution for you to examine the internal states (e.g., value of variables) of the program. Before starting the debugger, you need to set at least one breakpoint to suspend the execution inside the program. Set a breakpoint at main() method by double-clicking on the left-margin of the line containing main(). A blue circle appears in the left-margin indicating a breakpoint is set at that line. Step 2: Start Debugger
Right click anywhere on the source code (or from the ’Run’ menu) ⇒ ’Debug As’ ⇒ ’Java Application’ ⇒ choose ’Yes’ to switch into ’Debug’ perspective (A perspective is a particular arrangement of panels to suits a certain development task such as editing or debugging). The program begins execution but suspends its operation at the breakpoint, i.e., the main() method.
As illustrated in the following diagram, the highlighted line (also pointed to by a blue arrow) indicates the statement to be executed in the next step.Step 3: Step-Over and Watch the Variables and Outputs
Click the ’Step Over’ button (or select ’Step Over’ from ’Run’ menu) to single-step thru your program. At each of the step, examine the value of the variables (in the ’Variable’ panel) and the outputs produced by your program (in the ’Console’ Panel), if any. You can also place your cursor at any variable to inspect the content of the variable.
Single-stepping thru the program and watching the values of internal variables and the outputs produced is the ultimate mean in debugging programs - because it is exactly how the computer runs your program!Step 4: Breakpoint, Run-To-Line, Resume and Terminate
As mentioned, a breakpoint suspends program execution and let you examine the internal states of the program. To set a breakpoint on a particular statement, double-click the left-margin of that line (or select ’Toggle Breakpoint’ from ’Run’ menu).
’Resume’ continues the program execution, up to the next breakpoint, or till the end of the program.
’Single-step’ thru a loop with a large count is time-consuming. You could set a breakpoint at the statement immediately outside the loop (e.g., Line 11 of the above program), and issue ’Resume’ to complete the loop.
Alternatively, you can place the cursor on a particular statement, and issue ’Run-To-Line’ from the ’Run’ menu to continue execution up to the line.
’Terminate’ ends the debugging session. Always terminate your current debugging session using ’Terminate’ or ’Resume’ till the end of the program.Step 5: Switching Back to Java perspective
Click the ’Java’ perspective icon on the upper-right corner to switch back to the ’Java’ perspective for further programming (or ’Window’ menu ⇒ Open Perspective ⇒ Java).
Important: I can’s stress more that mastering the use of debugger is crucial in programming. Explore the features provided by the debuggers.Other Debugger’s Features
Step-Into and Step-Return: To debug a method, you need to use ’Step-Into’ to step into the first statement of the method. (’Step-Over’ runs the function in a single step without stepping through the statements within the function.) You could use ’Step-Return’ to return back to the caller, anywhere within the method. Alternatively, you could set a breakpoint inside a method.
Modify the Value of a Variable: You can modify the value of a variable by entering a new value in the ’Variable’ panel. This is handy for temporarily modifying the behavior of a program, without changing the source code.Tips & TricksGeneral Usages (for all Programming Tasks)
These are the features that I find to be most useful in Eclipse:
*Maximizing Window (Double-Clicking): You can double-click on the ’header’ of any panel to maximize that particular panel, and double-click again to restore it back. This feature is particularly useful for writing source code in full panel.
*Shorthand Templates (sysout, for,...): You can type ’sysout’ followed by a ctrl+space (or alt-/) as a shorthand for typing ’System.out.println()’. The default shortcut key (ctrl-space or alt-/) depends on the system. Check your system’s shortcut key setting in ’Edit’ ⇒ ’Content Assist’ ⇒ ’Default’. Take note that many of you use ctrl+space to switch between input languages. You need to reconfigure either your language switching hot-key or Eclipse. Similarly, you can type ’for’ followed by ctrl-space (or alt-/) to get a for-loop. You can create your own shorthand in ’Window’ menu ⇒ ’Preferences’ ⇒ ’Java’ ⇒ ’Editor’ ⇒ ’Templates’. (Alternatively, in ’Window’ ⇒ ’Preferences’ ⇒ type ’template’ as filter text and choose ’Java’ ⇒ ’Editor’ ⇒ ’Templates’.) You can change your key settings in ’Window’ menu ⇒ ’Preferences’ ⇒ ’General’ ⇒ ’Key’ ⇒ choose ’Command’, ’Content Assist’. (Alternatively, in ’Window’ ⇒ ’Preferences’ ⇒ type ’key’ as filter text and choose ’General’ ⇒ ’Key’.)
*Intelli-Sense (ctrl-space): You can use ctrl-space to activate the ’intelli-sense’ (or content assist). That is, Eclipse will offer you the choices, while you are typing.
*Source Formatting (ctrl-shift-f): Right-click on the source. Choose ’Source’ ⇒ ’Format’ to let Eclipse to layout your source codes with the proper indentation.
*Source Toggle Comment (ctrl-/): To comment/uncomment a block of codes, choose ’Source’ ⇒ ’Toggle Comment’.
*Hints for Correcting Syntax Error: If there is a syntax error on a statement, a red mark will show up on the left-margin on that statement. You could click on the ’light bulb’ to display the error message, and also select from the available hints for correcting that syntax error.
*Refactor (or Rename) (alt-shift-r): You can rename a variable, method, class, package or even the project easily in Eclipse. Select and right-click on the entity to be renamed ⇒ ’Refactor’ ⇒ ’Rename’. Eclipse can rename all the occurrences of the entity.
*Line Numbers: To show the line numbers, choose ’Window’ menu ⇒ ’Preferences’ ⇒ ’General’ ⇒ ’Editors’ ⇒ ’Text Editors’ ⇒ Check the ’Show Line Numbers’ Box. You can also configure many editor options, such as the number of spaces for tab. Alternatively, you can right-click on the left-margin, and check ’Show Line Numbers’.
*Error Message Hyperlink: Click on an error message will hyperlink to the corresponding source statement.
*Changing Font Type and Size: From ’Window’ menu ⇒ ’Preferences’ ⇒ ’General’ ⇒ ’Appearance’ ⇒ ’Colors and Fonts’ ⇒ expand ’Java’ ⇒ ’Java Editor Text Font’ ⇒ ’Edit’. (Alternatively, in ’Window’ ⇒ ’Preferences’ ⇒ type ’font’ as filter text and choose the appropriate entry.)
*Unicode Support: To enable Unicode support, select ’Window’ menu ⇒ Preferences ⇒ General ⇒ Workspace ⇒ Text file encoding ⇒ UTF-8. This sets the default character set used for file encoding, similar to VM’s command-line option -Dfile.encoding=UTF-8. Commonly used charsets for Unicode are UTF-8, UTF-16 (with BOM), UTF-16BE, UTF-16LE. Other charsets are US-ASCII, ISO-8859-1.
*Mouse Hover-over: In debug mode, you could configure to show the variable’s value when the mouse hovers over the variable. Select ’Window’ menu ⇒ ’Preferences’ ⇒ ’Java’ ⇒ ’Editor’ ⇒ ’Hover’.
*Comparing Two Files: In ’Package Explorer’, select two files (hold the control key) ⇒ Right-click ⇒ Compare with.
*Useful Eclipse Shortcut Keys:
*F3: Goto the declaration of the highlighted variable/method.
*Ctrl-Shift-G: Search for ALL references of the highlighted variable/method in workspace.
*Ctrl-G: Search for the Declaration of a variable/method in workspace. Don’t use Find (Ctrl-F), but use the above context-sensitive search.
*Ctrl-Shift-F: Format the source code.
*Ctrl-Shift-O: Organize imports.
*Alt-Shift-R: Rename. (Don’t use Find/Replace.)
*Ctrl-Space: auto-complete.
*Package Explorer vs. Navigator: We usually use ’Package Explorer’ in programming, but it will not show you all the folders and files under the project. On the other hand, ’Navigator’ is a file manager that shows the exact file structure of the project (similar to Windows Explorer). You can enable the Navigator by ’Window’ ⇒ Show view ⇒ Navigator.
*Spell Check: To enable spell check, select Window ⇒ Preferences ⇒ type ’spell’ in the filter ⇒ General ⇒ Editors ⇒ Text Editors ⇒ Spelling ⇒ Check ’Enable spell checking’. Also provide a ’User defined dictionary’ (with an initially empty text file). To correct mis-spell words, right-click and press ctrl-1 (or Edit menu ⇒ Quick Fix).
*Eclipse’s Log File: Goto Help ⇒ about Eclipse ⇒ Installation details ⇒ Configuration ⇒ View Error Log.
*Viewing two files in split screen: Simply click and hold on the title of one file and drag it to the lower side of the screen. [To view the same file on split screen, create a new editor window by selecting Window ⇒ New Editor; and drag one window to the lower side of the screen.]
*Block Select (Column Select): Push Alt-Shift-A to toggle between block-select mode and normal mode.
*Snippets:
*To view the snippet window: choose ’Window’ ⇒ Show View ⇒ Snippets.
*To create a new snippet category: Right-click ⇒ Customize ⇒ New.
*To create a new snippet item: Copy t
https://diarynote.indered.space
コメント