Eclipse is a multi-language software development environment comprising an integrated development environment (IDE) and an extensible plug-in system.
A classpath variable can be added to a project’s class path. It can be used to define location of a JAR file that is not the part of workspace. Non modifiable class path variables are set internally like JRE_LIB, JRE_SRC, JRE_JRCROOT.
To define a class path variable in Eclipse, open preferences by clicking Window > Preferences from the menu bar. You will find class variables under Java > Build Path. There you can define new class variables.
Following are Eclipse debugging features: Breakpoints, Step into, Step over, Step return, Step Filters, Watches, Run to line, Suspend/Resume/Terminate. You should know each of these for debugging your Java programs. I will try to introduce these in the next few posts.
We use breakpoints in our Java source to cause the thread of execution to suspend and return to the debugger. To set breakpoints in Eclipse, simply double-click the left margin.
Use ‘Step Into’, to execute
In this post, I will talk about how to view all the breakpoints in a project/workspace.
You set breakpoints for debugging. If you have too many of them, then it becomes difficult to manage those. At some point, you would like to see all the breakpoints in a view so you can remove the unwanted ones. Eclipse has a breakpoints view. You can find it under:
Windows > Show View > Other > Debug > Breakpoints
You are working in a Eclispe workspace that involves many projects. If you want to refresh all the projects or just simply if want to see all project names without their sub folders and files, you have to collapse all projects.
In the package explorer, you will be viewing all the projects. To collapse each project, you can click the minus symbol for each project. But this is painful as too many clicks are required in case of too many projects.
Eclipse provides ‘collapse
I will introduce folding option provided by Eclipse which is very helpful if you wish to fold (collapse) elements of a class.
You might have experienced a situation where you have a class with lot of methods and comments. You may wish to collapse all the comments, or the methods or both to have a bird’s eye view of what the class is offering.
Right click on the left most line (border) of the class. A window will open in which
Maven can be integrated in to Eclipse my using M2Eclipse (Tycho). Is is true to say that it is the most mature of the Eclipse integration projects.
Worth mentioning features of M2Eclipse include:
- Launching Maven builds from within Eclipse
- Dependency management for Eclipse build path based on Maven's pom.xml
- Resolving Maven dependencies from the Eclipse workspace without installing to local Maven repository
- Automatic downloading of the required
Eclipse provides ‘Convert to J2ME Midlet Suite’ from the project pop-up menu to convert an existing Java project to EclipseME project. Let me show how to do that.
When you select ‘Convert to J2ME Midlet Suite’’, you will be prompted for the appropriate device definition by the EclipseME plug-in. This plugin will then make the required changes to your project.
When you convert a J2SE project to an EclipseME project, the J2SE libraries have to to be removed from the build
Many guys who are new to mobile application development often question: “Does Eclipse support MIDlet development?”. Yes it does. In the next few posts, I will explain how you can create a J2ME project in Eclipse.
To cleate a EclipseME project, we should use the New Project Wizard and select J2ME Midlet Suite from within the J2ME item.
You will then see a wizard pane which is actually the standard for almost all Eclipse projects.
Eclipse has a view that shows all the warnings and errors of the projects in your workspace. I will write about that in this post.
While working on Java projects involving lot of packages and classes, you want a view to show you all the warnings and errors in your work. This will present all wrong stuff in a single view and you don’t need to search for the errors manually. Eclipse provides a view called ‘Problems’ that serves the purpose.
Updated 11-03-2011 at 12:42 PM by Java Tip
Sometimes you might feel that your Eclipse is sluggish and performance tuning is required. I will address this issue in this post.
Implement the following for better performance:
- Increase your min/max memory settings from 40/256 to 256/512 or higher. You might have to experiment with the min/max setting but increasing the initial memory heap to 128 when Eclipse starts should help.
- Disabling the code folding feature also helps. To disable this, go
You might have encountered OutOfMemoryException using Eclipse. This post is about solving this issue.
OutOfMemoryException is caused by too little heap space for virtual machine. Adjusting the maximum heap space with something like -vmargs -Xmx256m works. This gives your Java apps more space to run and this always helps performance. There are situations where even with an enormous heap size you can still end up with OutOfMemoryException. This means that your VM is not running out
Jumping to a specific line is very useful feature. Ecplise provides line nos along the lines of code and you may just to the required line using 'Go to Line' feature.
Ctrl + L, enter line number and you are taken to the required line. Of course if the stack trace is in the Eclipse console, you can just click the hyperlink. But if it’s in a log file or something, just use this shortcut to go to the line in a sec.
You can have a lot of files open your Eclipse IDE and may want to switch the file while working. Eclipse provides a fast way of dong that.
You can cycle through the editors using Ctrl + F6 but its not that useful since the keys are requires you to keep the Ctrl key down. Better way is to use Ctrl + E and then either use the arrow buttons, or type the name of the file you’re editing.
I hope you will find this useful.
Opening a type for example: a class, an interface) without clicking through interminable list of packages really is a handy feature. The shortcut key combination is: Ctrl + Shift + T.
If what you want is a Java type, this shortcut will do the trick. Unlike the previous shortcut, this even works when you don’t have the Java source file in your workspace for instance: when you’re opening a type from the JDK).
Updated 11-01-2011 at 07:29 PM by Java Tip
Eclipse provides content assist that really can save lot of development time. For instance putting try catch blocks where needed, for loop to iterate over an array/list etc.
Key stokes required: Ctrl-Space
Here is a list of useful things that can be done using content assistant:
- Code completion, name completion, etc.
- Does lots of useful completions in different contexts. Try it!
- When the cursor is among the methods of a class declaration,
Using keyboard shortcuts while working in Eclipse saves a lot of effort. But some shortcuts are not easy to remember and some comprise of multiple keys like: Alt+Shift+Q Y" ("Open Synchronize View").
Eclipse provides a little pop-up showing you the possible completions for the keys you have pressed already. In the preferences, under General > Keys, there is an "Advanced" tab. Go to this tab, and check "Help Me With Multi-Stroke Keyboard Shortcuts".
This post is about setting class path variables.
When creating a linked folder or file, you can specify the target location relative to a path variable. By using path variables, you can share projects containing linked resources without requiring team members to have exactly the same path in the file system. You can define a path variable at the time you create a linked resource, or via the General > Workspace > Linked Resources preference page.
Updated 10-28-2011 at 07:04 PM by Java Tip
Eclipse communication Framework is a collection of communication and collaboration tools. One of exciting tool is support for talking to any Jabber server. This means that we can easily configure Google Talk to run inside an Eclipse view.
You should have Eclipse Europa and ECF installed. To install ECF, go to Help -> Software Updates -> Find and Install > 'Search for new features to install'. The Europa Discovery Site (http://download.eclipse.org/releases/europa) should be
Eclipse Europa introduces a noteworthy feature called Quick Access . Using it where needed can save time and money.
The Quick Access is your window to; perspectives, views, open editors, commands, menus. After pressing Ctrl + 3, start typing, and it will show you the possible matches. It filters the most likely ones first, but if you press it again, will show all the possible matches that it knows about.
Those of you who have used Ctrl+E to open up the list
You must have seen stack traces in console window of your Eclipse. Good this is that Java stack traces in the console appear with hyperlinks. This means you can click these to go to the referred place in the code. This helps in problem identification.
Here is how is works: place the mouse over a line in a stack trace and the pointer changes to the hand. Pres the mouse button and associated Java source file will be opened and the cursor will be placed at the corresponding line. Pressing
While coding in Java using Eclipse, you might have experienced situations where your Java class has some compile errors but stilly you want to run it. The reason might be that the problematic area might be invoked in your execution. What ever is the reason, Ill briefly explain how to execute code with compile errors.
In Eclipse, you can run and debug code that did not compile cleanly. You cannot do this using command prompt. If line of code with compile error is executed, following
You might have used code assistant while coding in Eclipse. Its really useful and saves time for trivial stuff. Most of us think that code assistant is only available in code writing context. That’s not right.
Code assistant is available in debug mode at following: When entering a breakpoint condition,In the Details pane of the Variables & Expressions view,When entering a Detail Formatter code snippet,When entering a Logical Structure code snippet,When
Consider the following scenario: you are working on a project with client specific APIs .You need to test some API methods before you put them in your real code. For that, you might consider a separate test workspace or defining a new test class in your running workspace. What about scrapbook page? Ever heard of it?
Eclipse provide scrapbook pages to test write test code for experimental purposes. It is easier to use a Java scrapbook page than create a new class. A scrapbook page
Watch point is a special type of break point that suspends execution when specified filed is accessed or modified.
Setting a watchpoint is simple. First select a field in the Outline view and choose Toggle Watchpoint from its context menu.
Now you have to configure this watchpoint. This is done by selecting the watchpoint in the view and choose Properties from its context menu. Don’t forget to configure the important properties
Before you start writing unit tests, you must import junit.jar, so we have access to the testing framework. Follow these steps to import the required jar: Right-click on the project name, and choose Properties.In the tree on the left, select Java Build Path.Next, choose Add External JARs… and browse to find junit.jar.
It will be located in "<eclipsedir>\plugins\org.junit_<version number>\junit.jar".
Once you successfully
Its always useful to wrap strings if they are too long. This provides better readability. Eclipse has support for this.
String literals can wrapped when you edit them. Place your cursor at the point of literal where you want to wrap and press Enter. For example: Java Code: String message= "Java is fun to learn and it sure is a popular programming language.";
I kept the cursor at ‘sure’ and pressed enter key. The String was changed to:
String message= "Java is fun to learn and it sure is a popular programming language.";
Its always a good idea to include refactoring information into the JAR file when you are exporting it from Eclipse. Eclipse’s JAR Export Wizard offers this option.
Here is how it works: File > ExportSelect JAR fileSelect: Export refactorings for checked projects
This is very useful because then all the clients that are using older version of JAR will be able to migrate an old version of the JAR file to a new one using the Refactor > Migrate
Working on a project, I need to search all the methods defined in my workspace or in a package or in a class with a specific return type. Eclipse search feature (ctrl + h) provides support for this. We all have used eclipse search window a lot of times but many of us don’t know how to really use it to great affect.
To search the methods with a specific return type, type Java Code: * String
is used as wildcard for method name and String is the return
Mark occurrences is a nice feature in Eclipse. It simply marks/highlights all the occurrences of a variable, method or a type.
This can be done by clicking ‘Mark Occurrences’ icon on the menu bar. If you like to use short cut keys, then use Alt+Shift+O. If you select methods return type, and mark occurrences is enabled, all the method exit points will be highlighted.
You may also select a super class or interface and then
Ever heard of hot code replace in reference to debugging in Eclipse? Well, its sure is a powerful and useful feature. It enables you to change code while debugging. It simply means that you may change the code in debug mode and see its affect.
Hot code replace is supported in 1.4 or higher VM. There are some changes like adding or deleting methods, class variables or inner classes which cannot be hot swapped. This depend on the support provided by a particular VM. This might also