Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Hi, I'm new to IJ Idea and I've noticed every time that I run a program, I see four different paths printed out in the console along with my desired output. It also takes a few seconds to print any program that I'm trying to print compared to PyCharm, which prints out in a flash. Is there something that I can do to minimize this path to get a faster printout?
Sorry, I don't think there is.
Process finished with exit code
Will always be there, but that does not slow down your program. Neither does the path with information about the file and the IJ edition. Printing something simple should take under 100 ms; something complicated still only should take 2-3 seconds. I will keep researching to see what can be done to make it building faster.
The "paths" are just parameters that Intellij is passing to the JVM; given that you haven't manually added any extra parameters, it's likely you can't remove them. The slowness is also unlikely to be related to these parameters, it's just the time required for IntelliJ to launch the compilation process and run the program.
There are alternative VMs/projects that are meant to have a faster start time (GraalVM, Quarkus??) - you could try something like that if you're feeling adventurous.
You could try to avoid having to frequently rerun your code, for example by having unit tests to test it, or don't quit after the code is done - depends on the use case.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
I am currently working on a large code that will take a long time to run again. When I put breakpoint in the code and the code stops, do I need to restart the server every time? I have to troubleshoot a lot of code, and do not have time to restart the server every time.
No, a breakpoint stops the execution in the caught StackFrame at the position the breakpoint was set and triggered. After that, you can either continue stepping through manually line-by-line deciding if you either go into the execution of the given line or step over it (you can also step back - out of the method you are currently at). Or you could skip to the next breakpoint.
But if you make any changes, the code has to recompile and the server has to restart for your changes to take effect.
A more enterprise approach would be to write unit tests for the bits and pieces you tinker with and test them in isolation.
Depending on the number of dependencies it could mean runtime of milliseconds up to a couple of seconds. Take a look at Test-Driven-Development.
It is never too late to start writing tests. ;)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
At work i often work with Spring Boot Backends. Every now and then i need to optimize methods to run faster, so that the user dont have to wait and the request doesn't time out.
After watching this video: https://youtu.be/oewDaISQpw0?t=566 . I really liked the idea of having execution time shown per line of code, rather than of the full method. I began searching for similar tools for Java, but found nothing.
So i began thinking of a own solution.
I created a class that takes a .java file and edits it in a way, that there is a time print after every line, compiles it and loads it into the code to execute it. Before execution i redirect the System.out stream to catch the time prints. This kinda works, but only for standalone classes with no dependencys, with does not really work for me with my Sring service depending on other services and repositories. So i thought about replacing the class at runtime with my edited class, which does not really work in java(?). I also tried to use a InvocationHandler to catch the method calls of my service and route them to my edited class, but i still would need the dependencys and apparently the method proxy does only really work for interfaces.
My goal would be to have method and class annotation, that would mark the classes/methods to be speedtested. When called their times would be recorded and served on an exposed endpoint as a formatted .html.
Im kinda out of ideas right now and could need some help.
Thanks in advance.
What you're looking for is a Profiler. Most can tell you execution time per method, and memory usage, identified as 'hotspots' - where either the majority of time is spent, or most memory consumed.
Netbeans has a built in Profiler feature:
https://netbeans.apache.org/kb/docs/java/profiler-intro.html
Also, take a look at VisualVM:
https://visualvm.github.io/download.html
There's other commercial products available too if you search for 'Java profiler'
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Is it possible to compile & run scala code dynamically within Java code.
It is possible to achieve a similar result with JS using mozilla rhino. But, I wonder if it is possible with scala?
Theoretically, yes. But you will need to do a lot of things:
ensure the user entered valid scala code
transfer that source code to the server
compile the scala code
run it from within your server (catch errors, deal with resource leaks, ...)
So, possible: yes. Reasonable: not so much.
Obviously: a lot of work
getting to a decent user experience: even more work (like: telling the user exactly where in his source code input your compilation step found a bug ... hard)
And of course: opens your system for a ton of attack vectors.
If you want your users to be able to run code on the backend server, one wonders: why don't they have admin access to that machine already, and are able to deploy there code right there on the server themselves?!
Sure, Scala has its REPL, and as that one comment pointing to an existing answer implies: it is definitely possible to do that.
But as said: we don't do things because we can, but because it makes sense doing it!
twitter util-eval library seems provide what I need, but it is discontinued.
Here is an old fork:
https://github.com/m3dev/twitter-util-eval
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am beginning to write a basic "study-buddy" program as a side project. One important feature I want to implement is that the program can access the state of other programs running to prevent you from accessing them / yell at you. For instance, if you had Chrome open to Facebook, or if you launched a video game.
First off, is this even possible/reasonable to accomplish in Java? Second, specifically with Chrome, how can I access the programs state from another program that I am writing? More generally, how can I access ALL programs running on the computer and check to see whether anything violates "study-permissible" programs?
I would put this as a comment, but my reputation point is not enough.
One way is using the commands the operating system provides. You can run a command with
Runtime.getRuntime().exec("<command name>");
This will give you the related process and you can get the output of that process just as manually running the process. Then, you can utilize the output.
Basically if the OS provides you that information manually, you should be able to get the information within Java.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm writing small java networking programs for school; obviously RTFM is de rigueur, but in developing skeleton code is it efficient (it's obviously lazy) to just run it by the compiler to see if I've forgotten some checked exception (rather than: RTM-> manually check ...)?
One "Hack" I have done is make a script to periodically compile my c++ source file everytime I save it. Then script autoclears the terminal window and the top errors are visible. The window is also set as "always ontop". This catches semicolons and other trivial errors/typos very quickly and I can fix immediately.
I don't see why not do something similar in Java or any other language. I don't see this as lazy, it takes some effort to do, and it seams like a good tool for more than finding out if you are missing checked exceptions. You can even write a parser to be analyse the errors for you and give you copy & paste code to potentially fix some of the errors, like the checked exceptions.
For Java, eclipse does a really good job on the checked exception side, it even pre-inserts the exceptions for you when you press CTRL+1. When using eclipse I haven't had the need to do something similar as I did in c++ because eclipse does a good job parsing Java sources and putting a marker on errors such as typos and other things even before you save the file.
Yes - the compiler is an essential tool in developing anything that is more than 5 lines long. An IDE such as IntelliJ will compile real time as you type immediately highlighting errors.