I'm new to Java and OOP. I have a strange disorder that makes me extremely curious how things work. So I copied this code that use normalize() and I'm trying to get the source code of it but all I found is
public abstract String normalize(String path);
In:
FileSystem.java file
Of course, know what it does. But I'm curious how and why i cant find the code behind it.
Thank you
Michal
If you are using an IDE (like Eclipse), you can use it to find the concrete implementations of that method.
In Eclipse:
Ctrl + Shift + T and type java.io.FileSystem; click "OK"
Hover over the normalize method name. A menu will appear like below.
Click "Open Implementation"
If there is more than one implementation available, you will see a list. Click on the one you want to open.
If there is only one, then that single implementation will be opened automatically.
Related
Please let me know, Is there any possibility to get all classes with the corresponding methods of a project in one view in eclipse IDE.
Outline view is there but that's for only one class but i need for whole projects.
Kind of outline view for the whole projects.
Thanks.
Point given by HighCommander4
I think I know understand what your 'corresponding' means. In fact you want to see all classes in your project with all their methods. Simple as that.
What you are looking for is the 'Package Explorer' view. Basically it shows an Overview over your workspace, but it can do much more.
To view all classes and methods, select the project you are looking for, right click its src folder and select go into. Unfortunately you now have to manually elapse all classes, as there is no elapse all; only a collapse all.
If you are just looking for classes with methods that 'look like' the method you are corresponding to, the 'Search' view is what you are looking for.
To perform a search for a specific method, simply mark or select it and press Ctrl + Shift + G.
However, the 'Search' view will go through your complete workspace, but you can group the results after projects.
Edit: I never knew of Ctrl + Shift + G until I read Thomas' answer just know. Ctrl + G brings up the 'Search' view, too, but somehow it filters the results to a specific project (not the selected one).
If you are looking for classes that implement the method you are corresponding to, the 'Type Hierarchy' view is what you are looking for.
To build up a type hierarchy for a specific method, simply mark or select it and press Ctrl + T for a quick context menu style or press F4 to open the 'Type Hierarchy` view.
With the Shortcut Ctrl+Shift+G you can search for all references of a selected method.
I have written a project that includes a Character class. In this project, in a different package, I have another class that's trying to use it:
for (int i = 0; i < NUM_CHARACTERS; i++) {
Character c = new Character(10);
}
The problem is that Eclipse is automatically trying to use java.lang.Character:
What I would like to do, is find a way either via the contextual menu, keyboard shortcut, Quick Fix menu, etc. to have Eclipse provide me with alternate imports.
The issue is obviously that the class is part of the standard API, otherwise it would certainly ask me which Character class to import. Normally if you've imported the wrong one accidentally, you can just delete it from your import block at the top, and use Quick Fix to pick the right one.
But how, in this case, can I easily tell Eclipse I want to use a different class, without having to manually type the import into the top? I have a number of classes that will be named similarly to the java.lang classes, so I'm looking for a time-saving solution.
Ctrl+Space will give you an option to select the required package.
Just place the cursor at end like Character^ and press Ctrl+Space
where ^ show your cursor position. For example
Date class is present in java.util as well as java.sql, so when you will type
Date^ Ctrl + Space, it will pop-up with all the packages where Date class is present and you can choose your desired import from there.
Another way, Just delete all the auto imports & press Ctrl + Shift + O to organize imports. Eclipse will prompt you for all the place wherever there is any ambiguity in identifying the right package.
When hovering your mouse over a Class or variable, how come I don't see any information on the type of the class?
Is this not a feature in IntelliJ?
For example, in vs.net, if I mouse over any variable or class it will popup and tell me what namespace that belongs to etc.
And when I am using a method of a class, it also tells me the different overloads for the method (like types for each parameter, and a list of all the overloads).
This must be a feature in IntelliJ, I just don't know how to get it.
Can someone please clear this up?
Also, how can I tidy up the formatting of a page?
It doesn't work on hover yet, please star/vote the issue.
You need to use keyboard shortcuts for quick documentation pop-up or parameter info pop-up (Ctrl+Q and Ctrl+P with default Windows keymap, F1 and Cmd+P with default OS X 10.5+ keymap).
Code | Reformat Code... is the answer to your second question.
Formatting: Code -> Reformat (shortcut: Ctrl-Alt-L)
Hover doesn't produce the kind of information I'd like either. You can get info with Ctrl-Q ("Quick Help") in Windows or F1 in OS X, which will show where it's from and what it is, with most stuff in the popup window linked up in a reasonable way.
That popup view can also be pinned and/or docked; I often have it docked on the bottom.
If I'm in an interface and pointing to a method name, what can I do to quickly go to the ONLY implementation of that method?
Using Eclipse 3.6.
F3 is the typical "go to implementation". For interfaces that go to the interface definition.
Instead use Ctrl + T to see all implementations of the interface definition. You can then easily go to the one you want with the arrow keys and Enter. I believe that the first one is automatically selected so that Ctrl-T + Enter will do what you need.
I just checked this on my Eclipse 3.6 install: Hold control (command on Mac), hover over the method name and select "Open Implementation".
You may assign a keyboard shortcut to this action by using Window > Preferences > General > Keys and searching for "Open Implementation".
In the keymap (General > Keys) search for "open implementation" and map it to whatever you want. I chose Ctrl + Shift + I. Make sure you select "Editing Java Source" in the When box. I tested it, and having the cursor over the method name and pressing Ctrl + Shift + I took me directly to the implementation instead of showing the hierarchy that you get with Ctrl + T.
Also you can see an answer to a nearly identical question for other options:
In eclipse, ctrl-click goes to the declaration of the method I clicked. For interfaces with one implementation, how can I just directly to that implementation?
If someone still need this information nowadays (Eclipse version 2022), to jump into interface method definition starting from an #Override method, now in Eclipse you can see on the left, next to the method signature, a little white triangle. By clicking on that you will jump to the implemented interface method. here an image of the little triangle
Oterwise, if you are on a interface method definition and you need to jump to one of the implementations, you must use CTRL+T shortcut to see the list of available implementations and than click on one of them.
See this question on how to break on any exceptions.
I'm getting a million exceptions on startup. I've tried ignoring ClassNotFoundException, but it's no good, the IDE still seems to break on these (and other) exceptions.
So .. what's a decent configuration for this to catch only real exceptions caught from user code? (Ignore also any exception in jUnit, if applicable)
As mentioned by the other posters, Class Filters are the way to do this.
Specifically, you could add the package names for what you consider "your code" as a class filter. The syntax is a little opaque, but using a simple wildcard filter like:
com.whatever.package.*
sounds like it it will work for you. IntelliJ will break on any exception in any class in any package under here. You can of course define multiple wildcard filters if your code is in more than one place.
I was just messing with this earlier. Two ways to go:
1) Configure it to explicitly catch your exception, not "any exception" - if it's something like RuntimeException, this may not be filter-y enough.
2) Use the class results filter - this for whatever reason did NOT work for me. Ever.
I checked IJ and I see tons of options. Maybe the class filters is your option?
I'm adding this answer because I had a hard time finding the Class Filters sub-dialog mentioned in serg10's accepted answer. To see that sub-dialog do the following:
1) Open the View Breakpoints dialog using the following keyboard shortcut (Ctrl + Shift + F8), assuming you have not changed the binding for that shortcut.
2) Check the entry in the left hand column titled" "Java Exception Breakpoints". That should automatically check the child item titled "Any Exception" belonging to that top level element.
3) Click directly on the child item titled "Any exception". You should now see the Class filters drop-down box on the right hand side.
4) Check the check-box next "Class Filters". The View Breakpoints dialog should now look like this:
5) Click on the ellipsis next to the Class Filters drop-down box. You should now see the Class Filters dialog.
See these instructions to create a specific exception breakpoint. In short:
On the main menu, choose Run | View Breakpoints, or press ⇧⌘F8.
In the Breakpoints dialog box that opens, click add.
Select Exception Breakpoints from the drop-down list.
(source: jetbrains.com)
In the Select Exception Class dialog box, specify the desired exception class from the library, or from the project, and click OK.