Can I develop Java programs if I have only JRE installed? - java

I have JRE 1.7 installed on my system. Due to some admin issues I don't have JDK on my system. is there any way I can develop Java programs with JRE only?

No you can't develop java programs only with JRE
You will need JDK for compiling your programs.JRE provides only runtime environment,but JDK is something you will need to compile your code to make them executable by your JRE.You will need javac for compiling your code which is present in JDK.
However for resolving the issue of admin rights you are having, you can download and install eclipse which has its own built in compiler.

You need some program which compiles your sources, but that doesn't neccessarily have to be the JDK.
For example you can download Eclipse which only requires a JRE, it has it's own compiler (built-in) and you can develop with that. Eclipse does not require any admin priviliges, it's a zip file which you can download and extract.

You need to compile them in order to develop and that is why you need jdk

You can't develop any Java application since you need JDK(Java Development Kit) to compile your code. JRE(Java Runtime Environment) provides run time environment only. You can run your compiled code in JRE.

the answer is somehow "yes,but..."
java source code execution procedure is split into 2 steps :
1)compiling the source code into a byte-code,thus generating the .class file
2)interpreting the VM specific instructions from the .class file into native instructions
.java----javac---->.class----java---->native code
needless to mention that the "javac" , the compiler of the java source code is in not part of the JRE!
so in order to develop java programs without JDK you have to skip the first step and keep using exclusively the "java" tool,thus dealing directly with byte-code !
in some extent and if you're acquainted with the JVM internals,it's possible to write some lines of byte-code using hex or text editors and then running the .class file;but you will not go further then that specially when it comes to creating complex applications as this require super-human capabilities :that's a highly daunting task .
nevertheless,todays java frameworks almost all use direct byte-code manipulation and tools like the asm framework or javassit
javassist does not require the JDK and you can generate a class from scratch and then compile/run it
java -classpath .:javassist-x.x.jar test "some arguments"
(no need to compile classes)
but again,that is only for restricted use and in order to develop java applications you have to use some JDK...
finally,you have to strive to acquire full control upon what is running in you machine;recent frameworks are resource-greedy and needs a huge amount of resources(disk space,memory...) and many tools and framworks require full control,i mean administrator right : for instance i remember that once a time borland delphi refused to start and i had to give it full access rights to start...

I request you to resolve admin rights. Else I have two options for you.
1) You cannot do anything without Java Development Kit.
2)You can install a IDE to code Java which makes your work in the current situation simpler. Use Eclipse or NetBeans. I would recommend Eclipse to you anyway. You can download eclipse from this link https://www.eclipse.org/downloads/
Try downloading JDK from this http://www.oracle.com/technetwork/java/javase/overview/index-jsp-138218.html.
Hope this helps you.

JDK is needed to compile your java file into class file. And JRE will execute the generated class file and provides the output.
If you have admin problems in your m/c then you can install the JDK in some other m/c and take the class files into your system and execute them.

Eclipse includes its own compiler and doesn't depend on the JDK compiler. But indeed, the JRE is just the runtime environment and doesn't include the compiler or other development tools.

Do you need this to do you job or not? If it's your job, you should have access or they should install it. If you don't have access because it's not your job, I suggest installing the JDK at home (or on a laptop you can take with you)
Due to some admin issues I don't have JDK on my system.
Install it in your home directory or another directory you can write to. Your admins can't prevent you from installing the JDK if you have enough disk space.

JRE is not just sufficient, without compiling the code for that you need Jdk which have compiler to compile the code.

Related

Why aren't there compatible JREs for JavaSE12+?

I am getting an error when trying to run a .java file as a Java Application and I get the following error:
Unbound classpath container: 'JRE System Library [JavaSE-14]' in project <project_name>
I tried to change the execution environment and for JavaSE12 and later versions there are no compatible JREs. (But for JavaSE11 the compatible JRE is java-11-openjdk-amd64)
I do not know what to do because the project I am working on doesn't work with old Java versions. How can I choose an environment for the latest Java versions?
Note: I am using Ubuntu 20.04 if that makes any difference.
tl;dr
I am not a Linux user, so I may not know best. But I suspect the simplest approach to running your .java file is to:
Obtain and install a JDK for Java 15 for Linux
Call java app on the command-line, passing the path to your .java file.
Backwards-compatibility is a priority for the Java team. Most any existing Java app should be able to run with the latest version of Java. There are exceptions, but they are very few.
JRE is passé
The JRE (Java Runtime Environment) was a subset of the JDK (Java Development Kit), omitting some of the programmer tools. The JRE as a separate product seems to be getting phased out.
Oracle and much of the Java community has shifted away from the idea of regular users having Java installed on their personal computers. Instead, apps should be delivered with a JVM specific to their host platform bundled within the app. This bundling of a JVM can be done using newer tools such as jlink and jpackage.
For more info, read:
Java Client Roadmap Update - Oracle (2020-05)
Java is still Free
Obtain a JDK
You said you have a .java file to execute. That file must first be compiled before it can be executed. The more recent versions of the java app can do both steps at the same time, compile & execute.
First download and install a JVM for your host platform.
Java 11 is the current long-term support (LTS) version. Java 15 is the latest release. You may want to read about the six-month release cadence for Java.
You have a bounty of vendor choices providing implementations of Java. Here is a graphic flowchart I made to assist in choosing a vendor.
If the steps shown here are overwhelming, I suggest either:
Using apt-get or similar package installer to obtain a build of OpenJDK for Ubuntu. I am not a Linux-user, so I do not know the details.
Head over to AdoptOpenJDK to download an installer for Linux.
Some motivations to consider in selecting a vendor.
Compile & run your app
Once your JDK is installed, on a console (such as Terminal.app in macOS), run something like the following. The java command should both compile and execute your .java file, if that single file makes up your entire app.
java /path/to/some/folder/MyJavaApp.java

JDK folder not available under program files [duplicate]

To tell the truth, I am quite confused on all these terms (JDK/JRE/Java SDK). I am not sure what each one does.
When I first started doing simple java examples in eclipse, I am pretty sure I only had the JRE, which I believed was the default java installer regular users use to be able to run java programs/applets on their system.
However, now in class we are using Google Appengine, and this requires the JDK which I am guessing is the same as Java SDK. After wasting some time finding out that installing the JDK meant I also had to add java/bin to the environment variables to get javac -version to work in the command prompt I find that only the JDK has javac...
How were my early java programs working without having installed the JDK and therefore not having javac? And really the main question... What is the difference between the JRE and JDK, and when do you use each one?
Thank you :)
JRE = Java Runtime Environment - what you need to run programs/software that require Java or use libraries written in Java. For example, OpenOffice requires the Java Runtime Environment
JDK/Java SDK = Java Development Kit/Java Software Development Kit - what you need to write programs that require Java or use libraries written in Java. For example, if you were to write your own word-processing tool in Java.
java comes with the JRE because it launches the VM (virtual machine). It can take in class files which are files that have been compiled using the JDK.
The JDK comes with javac because that's what you need to compile your .java files into .class files that can then run on the JRE.
Eclipse has its own built-in compiler (called ecj), which is probably the reason you could get away with not having the JDK installed to use it. It does not use javac.
Google App Engine uses the javac that comes with the JDK.
What is the difference between the JRE and JDK and when do you use each one?
JRE: Java Runtime Environment. It is used to run Java programs only. As Chris Jester -Young mentioned, Eclipse had a built in compiler. That's why you just needed JRE ( to run eclipse )
If you ship a Java program, the only thing the client need to have is this runtime environment
JDK: Java Develpment Kit, this also includes a JRE inside, but additionally have other tools for program development such as the java compiler javac among many others.
If you want to create java program you should use this.
There's no way you used the JRE to compile Java programs. javac, the Java compiler, only comes with the JDK.
You may write Java programs with whatever text editor, you don't need anything special to do this.
You need the JRE to run Java programs. The JRE includes the Java Virtual Machine, needed to run already compiled Java programs.
You need the JDK to compile Java programs. So if you are a Java developer, you may want to only install the JDK since it comes with the tools needed to compile, in addition to the Java Virtual Machine.
'Sometimes you can develop with jre'
No. Never.
You develop with the Java Development Kit. You run with the Java Runtime Environment or Engine or whatever it's called.

What is difference between JRE and JVM ? How does an applet works if there is no JDK present in a system? [duplicate]

To tell the truth, I am quite confused on all these terms (JDK/JRE/Java SDK). I am not sure what each one does.
When I first started doing simple java examples in eclipse, I am pretty sure I only had the JRE, which I believed was the default java installer regular users use to be able to run java programs/applets on their system.
However, now in class we are using Google Appengine, and this requires the JDK which I am guessing is the same as Java SDK. After wasting some time finding out that installing the JDK meant I also had to add java/bin to the environment variables to get javac -version to work in the command prompt I find that only the JDK has javac...
How were my early java programs working without having installed the JDK and therefore not having javac? And really the main question... What is the difference between the JRE and JDK, and when do you use each one?
Thank you :)
JRE = Java Runtime Environment - what you need to run programs/software that require Java or use libraries written in Java. For example, OpenOffice requires the Java Runtime Environment
JDK/Java SDK = Java Development Kit/Java Software Development Kit - what you need to write programs that require Java or use libraries written in Java. For example, if you were to write your own word-processing tool in Java.
java comes with the JRE because it launches the VM (virtual machine). It can take in class files which are files that have been compiled using the JDK.
The JDK comes with javac because that's what you need to compile your .java files into .class files that can then run on the JRE.
Eclipse has its own built-in compiler (called ecj), which is probably the reason you could get away with not having the JDK installed to use it. It does not use javac.
Google App Engine uses the javac that comes with the JDK.
What is the difference between the JRE and JDK and when do you use each one?
JRE: Java Runtime Environment. It is used to run Java programs only. As Chris Jester -Young mentioned, Eclipse had a built in compiler. That's why you just needed JRE ( to run eclipse )
If you ship a Java program, the only thing the client need to have is this runtime environment
JDK: Java Develpment Kit, this also includes a JRE inside, but additionally have other tools for program development such as the java compiler javac among many others.
If you want to create java program you should use this.
There's no way you used the JRE to compile Java programs. javac, the Java compiler, only comes with the JDK.
You may write Java programs with whatever text editor, you don't need anything special to do this.
You need the JRE to run Java programs. The JRE includes the Java Virtual Machine, needed to run already compiled Java programs.
You need the JDK to compile Java programs. So if you are a Java developer, you may want to only install the JDK since it comes with the tools needed to compile, in addition to the Java Virtual Machine.
'Sometimes you can develop with jre'
No. Never.
You develop with the Java Development Kit. You run with the Java Runtime Environment or Engine or whatever it's called.

Java compilation problem, Linux, project from Eclipse re-compile on Linux

I am trying to recompile an existing Java project exported from Eclipse. It is necessary to recompile this because I am running simulations remotely on other machines where a different (older) version of Java is installed. I have tried recompiling my .java file which specifies the simulation in question. However, it appears that it is necessary to recompile all other classes etc as well. Has anyone got an idea how to do this WITHOUT using Eclipse (I am not the Admin on the other machines and thus Eclipse is unavailable to me) and not manually because the project is quite huge?
Thanks a lot for any suggestions!
I recommend you to always have an command line way to build an application. The usual way to do this in Java is using ANT (or Maven).
As #Santiago Lezica says, Eclipse can generate an Ant file.
I believe that Eclipse allows you to build for an older target platform than the one you are currently running. That way you can do all of your builds locally.
The second approach has the advantage that you can fix any problems arising from compiling for the older platforms (e.g. use of new language features, use of new classes / methods) from the comfort of your own ... workstation.
There is another option that you should consider: Tell Eclipse to generate code for the old Java version (see the compiler options). That way, you can create code that runs on Java 1.3, even if Eclipse uses Java 5.
Not sure what your requirements are, but you could set the compiler level for your projects at the (older) level of your Linux installs. This would cause Eclipse to recompile it at that version, instead of a newer version.
At my company we use IBM's Rational Application Developer (instead of pure Eclipse), but I am assuming the option is in the same spot. If you right-click on your project, you can go to the Java Compiler options and then set the compatibility to the level of that on Linux (1.3, 1.4, etc.).
Since compile Java byte-code is supposed to be portable (for the most part), this should get you past most of your problems.
Otherwise, the other option is to use something like Ant or Maven scripts (which can be kicked off by Eclipse) and then just use a property to set the compiler right before you run it. This way you don't have to switch properties on your projects all the time, if you truly do need "newer" compiled code and can't live with "older" code on both systems.

Can I distribute a JDK with my application?

I am working on an application called Enchanting. The application, based on Scratch, emits Java source code and compiles it for uploading onto LEGO Mindstorms NXT Robots.
While the application is very early, users have a hard time installing it.
Right now Windows users have to:
download and install a Java Developer Kit
download and install LeJOS (a java library for the NXT)
possibly tweak environment variables
then they can download, install, and run Enchanting itself
If I could provide an installer that would include the JDK, and LeJOS, I could figure out the environment variables at run time, and the process becomes:
Download, install, and run Enchanting
Is there a way to redistribute a JDK?
(Incidentally, Processing (a simplified text-based programming environment) seems to offer a version that comes with the JDK, so it appears that there is a legitimate way to do so).
Addendum: I would like a Windows user who does not have java installed to be able to run a single .exe file to install the JDK, LeJOS, and Enchanting.
The information regarding redistribution is here for Java 10 JDK and here for Java 8 JDK. Currently Java 8's is substantially more detailed than Java 10's.
and you can use PackJacket, to package all the files you need and create an installer.
Assuming you satisfy all the legal terms required to distribute stuff, you can use izpack to install all the prerequisites, including a JDK/JVM and configuration of environment variables.
Quite a number of IBM Eclipse based tools have JDKs with them.
Or you could just emit bytecode directly. You could bundle a much smaller (than the JDK) JVM dynamic language then use it to compile to bytecode or use libraries made for that purpose.
(I got the following from the Projects using Kawa page)
App Inventor for Android uses Kawa to translate its visual blocks language.
...The Nice compiler (nicec) uses Kawa's gnu.expr and gnu.bytecode packages to generate Java bytecode. ...
It's this last one is the one that uses the Kawa language framework to generate bytecode.
Don't forget about Groovy, Jython, Clojure, and Ruby. Interesting fact about Groovy, the interpreter can compile Java code since Groovy is (more or less) a superset of Java.

Categories