When editing Java code in Eclipse I can modify the code while it's running in various ways and have those changes take effect without restarting my program.
What is the technology underlying this feature? Is it part of Eclipse, or is it something I can do with the command line tools and the tools that come with the JDK?
Its part of the JVM and its called HotSwap.
http://download.oracle.com/javase/1.4.2/docs/guide/jpda/enhancements.html
This feature is usually called "hot code replace" and was introduced in Java 1.4 - it's part of the Java Virtual Machine Debug Interface and various APIs on top of that.
So it's not specific to Eclipse, but I don't think any of the command line tools that come with the JDK support it.
Related
Im new to app development and was wondering if it would be possible to include another jdk. For example java 17 and run a jar that needs to be run in this exact version? I think termux has an api that you may use for these purposes but is there another possibility? These jars are only console based and without any gui.
I first tried to use the jar as a android library inside the app, which did not work since it was compiled in java version 17. I tried decompiling the jar and recompiling it with the version I was using. The problem is that all the libraries used are on other versions than I need them to be and so I could not recompile it. I also thought about writing the application in c# but I am not used to it at all, which would throw many new problems that I would be willing to take if it would be a possibility to work out my project.
Q: Is loading the code into your Android application an option?
A: No.
Android loads code from ".dex" files not ".class" files.
The ".class" files would need to be translated using dx.
The Android dx command doesn't understand Java 17 ".class" file format.
Also the code in the JAR is likely to depend on classes in the Java SE class library that the Android doesn't provide.
Q: What about running it in a separate Android VM?
A: No.
An Android VM requires ".dex" files; see above.
Also, the Java SE class library issue; see above.
Q: What about launching an OpenJDK or Oracle Java 17 JVM on the Android device to run the JAR?
A: In theory Yes, but in practice No. As far as I am aware, there is no port of OpenJDK Java SE to the Android OS platform.
Q: What about using Termux?
A: OK ... that might work. See Is it possible to install the JDK on an android device?.
I have no experience with this, and don't know what problems you may run into doing this. But I suspect that you wouldn't be able to distribute something that relies on Termux via the Google Playstore.
Another option is to download the source code1 for the application and try to build it in your Android dev environment
If the code uses Java classes / packages / libraries that are not available for Android, recode the relevant parts of the application to use Android equivalents instead.
Ditto if the code uses Java language features that are not yet supported in Android Java.
It probably won't be easy. It may turn out to be impractical.
1 - You said in a comment that the code your are trying to use is "open source". So the "download source and build it" option is available to you. I'm puzzled why you tried to decompile and recompile it instead ...
I have a java application that consists of various files and I need to run my project. I have jdk 14 installed and have also set the Environment Variables. But when I click on Launch project, it just keeps loading and loading and nothing else happens. It does not show me any error log or anything. I am really confused and been trying to solve this for a week. In launch, it does not give me any option of java. It says Launch in angular. Any help would be appreciated?
VS Code is basically an editor for sourcecode files of different languages. As such, it does have any inbuilt Java execution options.
To debug your Java programs, you will need to install the appropriate Java extensions for VS Code.
Having Jdk installed is a prerequisite to use Java on VS Code but it alone is not enough.
I'm just about starting to learn Java. Reading about, I installed Netbeans.
Running Apache Netbeans IDE 11.2.
The Java version is 13.0.2.
I'm promptly follow the Quickstart guide on the netbeans website.
File>>New project>> Java >> Java Application.
Errhmm, I don't have this 'Java' option. All I have is
So what's the difference between Java & Java with Maven/Cradle/Ant . At this point in time, I intend to start with basics of Java programming and then move on from there. SO which option am I meant to be starting with? If I'm missing Java, how can I add it ? Going through the installation procedures didn't give me any option to choose from.
p:s - this is all running on Mac OS Catalina
You can start with any of Java with ... option. I use Java with Ant option.
Maven, Gradle, Ant are build-tool addons i.e. they provide additional support if you intend to use any of these as your build tool.
When you choose Java with Ant option, it will let you create, compile, debug and run your Java programs without requiring anything additional. After using this option, you will get an interface as shown in the screenshot given below:
Maven, Gradle and Ant are build tool which allows you to compile, unit test, package and (if you like) even deploy your Java applications (they do support other languages btw).
I suggest you to start with one of those (Maven is very popular and probably a little bit easier than the others) instead of relying on your Java IDE specific features.
Once you master a build tool you can change IDE (IntelliJ is also a very good option ;-)) and will still work as before. You also find plenty of resources and help (like Stackoverflow) if you need hit some problems.
Best of luck!
I'm pretty new to programming and to Java, so I'm really not sure.
I know that JDK has its own compiler and the JRE too so would I really need Eclipse?
You need the JRE to run java code on your computer and the JDK to write it. However, many programmers tend to prefer an IDE (Integrated Development Environment) to use along side for actually writing the code, debugging, and execute it much more efficiently. Eclipse is a good example of one, and one of the many used/preferred IDE's (in my opinion at least) out there. However, others exist too:
DrJava
Netbeans
BlueJ
JCreator
These editors are much more preferred because they make it easier to learn / write code. However, you may choose a normal text editor (like sublime, atom, textedit, notepad, textmate, etc..) or even the command line. Mac & Linux have "vim" built in which is a command line editor too which I tend to prefer.
Yes, the JDK and JRE are necessary to run java but Eclipse is the tool that will allow you to code, debug and execute easier.
Think of JDK as the engine of a car and Eclipse or any other IDE like the wheel.
I'm writing a program with Java7 and JavaFX2, but I'll need to show it to people who only have access to machines with Java 6 installed (with no JavaFX).
Is there any way I can find a solution to this short of asking them to install Java7 and JavaFX2?
Perhaps you can create a self-contained application package by "bundling" your program with Java 7 and JavaFX 2. That way you don't have to worry about what's on or not on your user's machine.
You can read more about self-contained application packaging at http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm.
Theoretically yes, but you have to check if that is conform to the license conditions of Sun/Oracle the owner of JavaFX:
You could sue tools like http://one-jar.sourceforge.net/
They pack all your java into one jar.
Another possibility you could obfuscate your application and include JavaFX.
But this, too might violate the license conditions.
Both solutions might be more work, than the effort off installing JavaFX to the (one)clients computer.
Try JavaFX2 for JavaSE6
On page: http://www.oracle.com/technetwork/java/javafx/downloads/index.html
Download Download JavaFX 2.2.3 for Java SE 6 ...
If you are using Eclipse JDT, you can configure your projects "Java Compiler", by "Enable project specific settings", to "Compiler compliance level" value 1.6. This should produce bytecode in a version suitable for Java 1.6 VM. I suppose, but am not sure, that Eclipse shall also warn you if you use library elements not present in the 1.6 library version; though you can be careful about that with or without warnings. As with the previous solutions, JavaFX you can just package in your application's JAR if the license agreement allows it.