Netbeans problems with reflection - java

Why Netbeans takes so much time in java.lang.Class.getDeclaredField(String)?
I have isolated my problem and I have two projects:
I created a Netbeans Platform program with one module that has one window and one button in it. So when I click it, program runs the function that I need.
I created a form that will call that function.
So now I have two programs that are the same and run from an AWT thread. The key difference is that one runs under Netbeans Platform structure and the other one is alone.
Profiling the two programs I found that the big problem is when it calls "java.lang.Class.getDeclaredField(String)" Netbeans program takes 30,784 ms and Swing program takes 2,055 ms
It seems to me that Netbeans has some sort of security that checks when somebody is trying to access a class through reflection.
Does anybody knows what is it? and how to turn it off??
Thanks
HS

Related

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.

Eclipse: quick run/preview vs. run main

I am wondering why they 'quick run/preview' displays object different that when you select 'main run' in Eclipse. I personally find that objects look better/neater/more elegant in quick run/preview mode than when I when I run and compile the application via the 'main run' option.
Can anyone tell me there is such a big difference, and what I need to do to actually make my application and its objects look like in 'quick run/preview' mode?
Quick run/preview in Eclipse is used to compile the code and run it more efficiently than normal run. I'm assuming you are referring to this when you are building GUI's?
Anyhow, quick run/preview is just to quickly preview your application regardless of the looks.
I'm assuming you want your GUI to have the Look and Feel of a Windows application rather than the "metal" Java GUI look.
This is done relatively easy as you can both make the "Look and Feel" of your application be based on whatever OS you are running or which one you prefer.
Refer to this simple article here.

Java/C++ background program to get keypress to run exe

Right, my title probably made no sense. However I'll explain it now.
I have a program coded in C++ that I wish to allow a keycombo to be pressed to run the program. My program does not run all the time it only runs when clicked then closes when the operation is complete. It simply does it's function then closes itself. Now here is the question.
Would it be simpler to attempt to edit my C++ program to run all the time via a thread in a class that then called the other class to run that did the function then stopped and listened for keypress again.
Or
Create a Java program that runs all the time and listens for a keyEvent and upon doing so runs the other programs exe. Then bundle the exe and jar in to one exe that is installed and run so they have access to each other.
If I did it this way is it even possible as far as I know key events need to have focus to be able to be detected. Meaning that I would need to be running the program as my main window to detect it? Or is that not true.
I'd looked at the java route as my Java is better than my C++. Is this do-able and if so what approach would be the better one?
Hope this is explained well enough let me know otherwise.

How to get the running time of Java plugins using Eclipse

Now I am using a plugin based Java to put into a third party software (ImageJ) to process images. After inputting images, it shows the GUI where I can choose the segmentation parameters and tracking parameters. But it runs slowly after setting parameters on the GUI. Hence, I want to know which part(Segmentation or Tracking) makes the Java code run slowly.If I use Eclipse, can I get the running time of each part and how I can get it because it's a plugin and the running time will be different if I change the parameters on the GUI and input images. Thank you so much.

Java GUI not displaying in eclipse on Ubuntu

I'm working on a GUI program written in Java (using Swing) in Eclipse. I usually develop on Windows, and I am able to run\debug the program in Eclipse and it displays just fine. (I'm using a JUnit test to run the different windows of the GUI program).
However, I recently put Ubuntu on my machine on a second partition on my hard drive, installed Eclipse, and tried to run the JUnit test, but the GUI window appears for a second then disappears. The rest of the JUnit test runs just fine, (0 errors, 0 failures) but I can't see the GUI. Anyone know why this would happen? Thanks.
Ok, I figured it out. GUIs aren't meant to be run in JUnit tests, because as soon as the tests are completed, the program will exit, and the GUI will immediately close. For some reason, the program was staying open when I ran the JUnit test in Windows, but that's not really supposed to happen.
Because, in the current project that I'm working on, it makes more sense for me to open the GUI in a JUnit test, I implemented the following workaround: I had the method that ran the GUI simply wait until the GUI is closed before it continued to execute. To do this, I used the mechanism described here.

Categories