lazy and efficient approach to checked exceptions [closed] - 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.

Related

Is there a tool or a way to speedtest java classess/methods per line of code? [closed]

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'

IntelliJ Idea output console [closed]

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.

How to inject and run Scala code in a running JVM [closed]

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

How to debug the Java compiler source code (Javac) itself? [closed]

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 want to know the detail compilation process from the Java code to the bytecode, such as how a line Java code translate to the bytecode,so I want to set the breakpoint in the Java compiler source code, however I don't know how to do that , is there any reference or steps for that ?
BTW,
I don't ask how to use the Java debuger(obviously I know how to use it), I mean how to debug the Java compiler source code instead of the Java source code.
Your question about how the compiler works is too broad to answer here. Go read a standard compiler text book.
Regarding debugging a compiler:
I tend to heavily use assertions in the compiler (self-diagnosing) and large suites of small target language test programs focused on various language features that self-verify their correct functioning. (My last compiler has around a thousand of these test programs built over a period of 10 years, and a script to compile and run them all). Often a failure of an assertion or a test hints to me where the compiler is wrong and mere inspection identifies the bug.
I often add special code to dump out key information about the state of the compiler and traces of activities that I can enable with special undocumented command line switches. These special dumps indicate where the compiler goes astray, and again often enable code inspection to identify the location of the bug.
Failing that, I use a debugger for the language in which I have written the compiler.
I don't consider these techniques as particularly special. They are useful when trying to work with any large, complex application.

How to protect a java application from reverse-engineering or code stealing? [closed]

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 20 days ago.
Improve this question
I want to reveal my desktop java application to public, but I'm not sure how to protect it from reverse-engineering or source code stealing?
Is it possible to convert the application to an exe file? and if it is, wouldn't that be enough to protect it?
If it's really worth someone's time to reverse engineer your source from the binary, they will. You might be able to make it slightly harder, but never impossible.
You can use a Java Obfuscator such as ProGuard.
ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions. It renames the remaining classes, fields, and methods using short meaningless names. Finally, it preverifies the processed code for Java 6 or for Java Micro Edition.
A Java executable and a native executable are both just a bunch of machine code (with optional annotations and stuff). So there's essentially no difference in terms of how easy it is to reverse-engineer.
If you are compiling with javac, you can use the -g:none flag to eliminate all debug info from being compiled into the executable.

Categories

Resources