find the class in debug - java

I'm writing Java in eclipse and I'm just wondering if there's a shortcut or a way to open the class of the screen you are looking at when debugging an application.
So, I'm debugging a very large application, and at some point I open a dialog within the application, and I want to know which class in the Java project contains the code responsible for this dialog. Is there a shortcut to open this class in eclipse?

If you just want to go to a specific implementation of method or a class, ctrl + click will take you to the code (if it is not third party code, you will be able to see it)
If you are asking how to see the code getting executed in debug mode, use F6 key instead of F8.

Related

Execute commands/code on the fly during debug mode in Eclipse

On Visual Studio while developing using ASP.NET with C# or VB, I used to be able to execute code or call some APIs on the fly using the console or debug window.
I am asking if this can be done using Eclipse while debugging JSP or Java classes, and how?
Tarek
The Display view in Eclipse is used to do this. You can open using the shortcut Ctrl+3 and search for Display.
There, you can inspect, evaluate expressions and execute code during the current debug context. To execute code in the view for instance, you would select the code that is typed in the view and press Ctrl+U (the same can be done by right-clicking on the selection and clicking on the appropriate option from the context menu).

Java noob, wondering if I made a mistake regarding packages

So to give context, I am new to Java and have no other programming experience. The IDE I am using is NetBeans. I picked up a book called "Sams Teach Yourself Java" and the tutorials in this book are having me put all the different classes I write in the same package. The problem with this is that when I want to run a class with attached arguments I can't just run the file from the "Run" tab. The book tells me to run it as a main project. But if I select run as main, one of my other classes runs. I figured out a work-around buy setting a main class, but I haven't found anything online about this and want to make sure I am not doing something stupid. This is my first question and any tips on how to ask effective questions on this site are appreciated.
While learning, there is nothing wrong with putting many classes in the same package. The reasons for separating classes into different packages can wait until later lessons and learning.
You can run a particular class as a Java application in Netbeans, assuming it has the correct main() method, by pressing ctrl-shift-f5 while that class is the one currently selected (i.e., currently displayed in the editor pane). You can run the most recently run java application by pressing ctrl-f5, even if that class is not the one currently selected.
This question is clear enough. If you get to a programming problem, go far enough to have tried something that doesn't work as expected. To ask about it, try to show the smallest program that illustrates your problem; tell WHAT is happening that you do not expect (or not happening that you do). If there is an error message, include all of it, don't just describe it.
Is each class a new project/example from the book?
You could have multiple classes within the same package that each have a main method. Only the main method within the class that is selected to run/passed on will be called.
In NetBeans, there is a little drop down arrow that you can press and it should allow you to specify which one to call.
The application is running properly. That I can assure you. Since all the classes you created contains main method the compiler is confused because it does not know which class's main method should be executed successfully. Hence, it builds all the methods but does not execute them. If you observe the output tab, after clicking on the run button, it will always show build successful. This means it it building the classes but not executing them. To execute each class separately, either right-click on the class and then select the run option, or use the keyboard shortcut 'Shift+F6'. This shortcut executes the class you are currently working in.

Create and Run a simple java Program in intelliJ without all the advanced features?

I am just learning java and have come to a point where coding in 'vi' is killing my hands
I'm considering an IDE like 'intelliJ' with code Completion but don't want to use all that project tree , packages etc and be caught up in its complexity, i'll learn how to use an IDE later ,
Can someone tell me how to just create and run , just a .java file along with codee completiona and debuggin , so that i dont need to save with 'wq' , compile and open vi.filename.java each time, this is why i want an IDE , to make this easier, so please guide me on how to do just this in IntelliJ or suggest some other IDE with good codeCompletion,
I know this question is subjective but i;m askinng it since i just had a hard time typing a simple GUI quiz Application
I would just create new Java project (File/New Project/Java), select Create project from template and choose Command line app. This creates a project containing a class with empty main method, which you can run by hitting SHIFT + F10 or debug using SHIFT + F9.
This whole process takes only like 20 seconds.
And as far as the directory structure complexity goes, you have just one directory that you need to be concerned about - src/. You can keep all your classes in the default package if you want and therefore all your code will be in src/ without any subdirectories for packages.
I don't think it gets any easier than this.
Most IDEs make you create a project to start coding, so I usually have one project called 'test' for whenever I want to try a bit of code. Make one java class file that has a main class and use F5 or find the run option in the menu.

Debugging using Java source code

Is there a way to include whole Java source code into an eclipse project so the program is easier to debbug (e.g. by inserting println in methods you otherwise couldn't insert anything)?
I have a bug in my code. But to better understand why the bug in my code appears, I'd like to see what intermediate results in some system method (on which use the bug occurs) are.
For example, I'd like to know what JViewPort.scrollRectToVisible() exactly does and how my input behaves in it by printing out some intermediate results that occur in the method itself.
EDIT:
Instead of using JRE System Library X, I want to add the source code from JDK as if I had written the code myself. I want to be able to edit any System class just as I am able to edit any class I created myself. I want editable .java files, not packed .jars...
You would need to add the 3rd-party library to your Eclipse workspace as an project. (How you would do that depends on the code you are dealing with.) Once you have done that, you can hack your copy of the library to add trace prints etcetera.
A better alternative is to simply attach the source code for the 3rd-party library so that the debugger can show you source as you step through the code, set breakpoints,. Then use "advanced breakpoint" techniques instead of trace prints; e.g. http://www.vogella.com/articles/EclipseDebugging/article.html#advanced
You cannot change the library code, but you can view it by using de-compiler. The max you can do is this. Now if you change any code in the libraries which you reached via the de-compiler, you would find an error stating "the integrity of the .jar package has changed which is not allowed"
Eclipse have built-in support for what you wanna do.
All you have to do is set breakpoint and execute application in debugging mode.
You can use these icons in Eclipse debugging perspective.
Follow along Eclipse Debugging Tutorial for details.

Is there a way to find out the class of form using eclipse?

I am working on a large undocumented application written in swing/awt. I have to make changes to it and i need to find out what class a form belongs to when i open it. Is there a way to do this via eclipse?
For example: I open the application and to do something with the app such that some frame opens. How do i find out the class of that form? Can this be done through eclipse?
I know i can comb trough the logic but this is a very laborious and largely ineffective process, chunks of the logic are either in jar files or obfuscated.
Thanks.
For figuring out how a given Swing frame is put together, I have found Swing Explorer to be VERY helpful.
https://swingexplorer.dev.java.net/
After installing the Eclipse plugin, note that you need to "Run as ->" to invoke Swing Explorer properly.
I don't know if this is what you need, but maybe you should try searching(MainMenu-->Search) your entire Project for the specific Window title (String) that comes up with this particular window.

Categories