BreadcrumbsHome / Java Eclipse Tutorial – Part 4.1: Searching and Navigating Source Code
Java Eclipse Tutorial – Part 4.1: Searching and Navigating Source Code
Last Updated on Thursday, 14 May 2015 Written by Chad Darby Saturday, 9 August 2014
In this video tutorial, I will show you how to use Eclipse to search and navigate your source code. I’ll discuss the following topics:
– Opening a class by name
– Viewing a quick outline
– Examining the type hierarchy
Please subscribe to this channel 🙂
|1||Installing the Eclipse IDE||03:18|
|2||Create a Java Application with Eclipse||03:44|
|3||Exploring the Eclipse User Interface||04:50|
|4.1||Searching and Navigating Source Code (part 1)||04:18|
|4.2||Searching and Navigating Source Code (part 2)||06:06|
|5||Generating Java Source Code||05:12|
|6.1||Refactoring Code - Extract Constants and Variables||04:13|
|6.2||Refactoring Code - Extract Methods, Rename Methods and Variables||04:19|
|7||Debugging Java Source Code||04:34|
|8||Adding JAR Files||05:17|
|9||Running JUnit Tests||05:08|
|12||Setting Eclipse Preferences||04:09|
Time – 00:00
Hi. This is Chad (shod) at luv2code.com. Welcome back to another tutorial on Eclipse. In this video you will learn how to use Eclipse to navigate and search for your source code. We’ll learn how to open a class by name. We’ll also discuss how to view a quick outline and we’ll also examine the type hierarchy.
Time – 00:20
Okay, so let’s get started. Let’s start with the most common task. You have a project that has a lot of Java files and you need to find the specific class and you know the name of the class. Instead of wading through all of the classes, you want to simply open a class by name.
Time – 00:38
In this example I have the source code from Oracle downloaded for the Java SwingSet. As you can see, this project has a lot of code. What I’ll do here is I’ll actually open a class by name. Instead of picking it directly from the list, I’ll make use of this menu option called Navigate. I’m going to Navigate and then I select Open Type and then I can type in the name of the class that I want to look up.
Time – 01:00
Here I’ll type html demo. Notice as I type the actual name, you see a list and so here is the one that I’ll open, html demo, hit okay and then this will actually open the Java class.
Time – 01:12
One thing that’s really nice when you’re doing the actual search, you can do Navigate, Open Type, that you can even make use of wildcards. If you simply wanted to look for anything that started as a demo, you could say demo star. Okay and it’ll give you that list, or you could even use star demo and it’ll give you a list of all of those items. A really cool feature for looking through your code.
Time – 01:36
All right. I’ll show you another feature of Eclipse. First let me close this file and I’ll open up another one. I’ll do navigate, open type and I’m going to open up SwingSet2. There we go. This opens up the SwingSet2 class. What I’d like to do is take a look at all the methods that are available in this class.
Time – 01:58
You can normally list the methods by simply selecting the class over in the package explorer, doing a click and seeing all the methods and that’s a useful approach. You could also make use of a feature in Eclipse called the Quick Outline. The Quick Outline will simply show you a popup of the methods for a class right in the same window. You can access this Quick Outline by saying right click and then going to the Quick Outline.
Time – 02:21
This will give you a list of all of the fields and methods for a given class and you can scroll down. You can choose a method that looks interesting to you and select it, like create themes, and it will take you directly to that code. It’s a really nice feature.
Time – 02:38
Another thing you can do with this Quick Outline is that you can actually filter on the method names that you display. I’ll do right click, say Quick Outline and so here there is an editable text box where you can begin to type in information and it’ll filter on those method names in real time and then you can choose a method and then go there directly.
Time – 03:00
The next feature that we’ll discuss is the type hierarchy. The type hierarchy allows you to display the inheritance tree for a class. You can do the type hierarchy by going to Navigate and then selecting Open Type Hierarchy. This will bring up the actual inheritance tree for the class.
Time – 03:17
Here we see we have this class called SwingSet2 that extends a JPanel and when you select the parent class will show you the methods and fields that are found at that level. A JPanel extends JComponent, Container, Component and all the way to the top of java.lang.Object. It’s very useful if you need to investigate the inheritance tree for a type.
Time – 03:41
I’m going to show you another feature related to type hierarchy and that’s called the quick type hierarchy. This shows you the type hierarchy as a popup on the actual screen. You can access the quick type hierarchy by going to a right click and then selecting Quick Type Hierarchy. It will also show you the inheritance tree right here on the screen. If you select either one of these items, it’ll take you directly to the source code for those classes. It also has an editable box where you can filter on any specific parent class.
Time – 04:12
Okay, so this wraps up our discussion. In this video you learned how to use Eclipse to navigate and search for your source code. Please subscribe to our channel to view more videos in Eclipse and Java. Also visit our website, luv2code.com to download Java source code.