Installing Java on Windows 8 - java

I'm in a Java I class and I have a new-ish laptop with Windows 8 on it. I've installed Java and changed the environment variables, created a Path, etc. When I enter java or javac in the cmd, it comes back with information. But when I enter "java-version" (as I'm instructed to do in the class to test if Java is working) it says, "'java-version' is not recognized as an internal or external command, operable program or batch file".
I've even attempted a HelloWorld program in spite of this, and as you can imagine, I got the same message. I'm not even able to change the directory.
Is there some special way to install this on Windows 8 or what?

You need to type java -version instead of java-version

First of all ensure you have typed Java -version space between Java and -version
No there's not special way to install Java on windows 8 machine, Just ensure that you have added ..\Java\jdk_(version)\bin and ..\Java\jre\bin in environmental variables.
Steps to be followed :
Right click on my computer go to properties
Then go to Advanced
system properties then click on environment variables
and add both path in Path variable under System Variables add semicolon between two paths
after all process don't forget to restart your PC

There is no special way to install java on windows 8. You can install java in normal way what you did in windows 7 or vista or windows xp and configure. Then run java -version, It will give your java version.

Related

Confused about what jdk and jre my command prompt is using for java

I was super confused about compatibility on a java tool I was using and ended up downloading different versions of java so now I do not know what versions of jdk or jre I am actually using. When I compile I use -- release 8 in my command prompt, what does that exactly mean?
Currently my programs folder has jdk-18 in the java folder
and my program files(x86) folder has
jdk1.6.0_45
jdk 1.7.0_80
jre 1.8.0_ 321
jre6
jre7
My java home environment variable is C:\Program Files\Java\jdk-18
My classpath has the file C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar
when I type java -version in my command prompt I get
java version "1.8.0_321"
Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
Java HotSpot(TM) Client VM (build 25.321-b07, mixed mode)
So does that mean my cmd uses jre 1.8.0_ 321? What about the jdk? How do I change it if I need to?
When you run java -version - first java found in PATH environment variable is used. To be sure use commands where java (Windows) or which java (Linux) - it will tell you the location.
When you run mvn install - JDK found in JAVA_HOME environment variable is used. To be sure use mvn -version - it will tell you the location.
When you run from IDE - IDE settings matter, usually you specify JDK per project.
When you run javac --release 8 Something.java you are asking compiler to produce output compatible with the version you specified - it has nothing to do with JDK you are actually running it on. This flag was added in JDK 9, so if it doesn't fail for you then it means you are running on JDK>=9.
If you want to be 100% sure just fully qualify the path - for example on Windows "C:\Program Files\Java\jdk1.8.0_152\bin\javac.exe" Something.java
So does that mean my cmd uses jre 1.8.0_ 321?
Yes.
What about the jdk?
Unclear.
Run javac -version and that will tell you what version compiler you will run by default.
The versions of the Java tools that you get when you type java, javac, jar (etcetera) at the CMD prompt are solely determined by the PATH environment variable setting in effect at the command prompt.
The other variables do other things ... but not this.
How do I change it if I need to?
If you want to change what typing java does, change PATH.
Note that the PATH variable is a standard Windows environment variable that affects all* commands, not just the Java tools. There should be lots of tutorials on how to set PATH, and on the Windows CMD prompt in general. You should probably take the time to read them.
You can also just use the absolute path for the Java tools; e.g. "C:\Program Files (x86)\Java\jdk1.7.0_80\bin\java.exe" is probably the correct path for the Java 7 java command. (You can easily check ... and find the correct path by looking at the installation tree.)
Regarding your other variables:
My java home environment variable is C:\Program Files\Java\jdk-18
That is presumably JAVA_HOME. That tells (many) 3rd-party tools which Java tools to use. But unless you have configured PATH to depend on JAVA_HOME, it won't alter what typing java does.
My classpath has the file C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar
That is presumably CLASSPATH. That variable provides a default path that java will use to find classes to load. For example, if you run java com.acme.Example, it will use CLASSPATH to search for the compiled Example class.
So "C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar" is almost certainly incorrect. (That JAR file contains the classes that implement various Java tools. It doesn't need to be on the classpath, unless your Java application is running one of those tools. And even then there would need to be other things on the classpath for your application to work.
You need to do some reading on what the Classpath is, how it works, and how to set it correctly. Setting it to stuff randomly is a sure fire way to make your Java code not work ...

Java installation in mac

I am new to mac. Running the javac / java -version command yields negative result. However, I do see java under system preferences. I have not installed JDK/JRE yet. On clicking the java icon, under update, it shows that the system has the recommended version of java. Java 8 update 144. What is the java icon doing under system preferences when I have not installed JDK/JRE.
It is JRE, which comes along with OS by default. I'm not sure, how did you executed java -version command. In my case, I get proper information about installed JRE.
You probably need to check your User and System variable under Java
Also, it is obvious to get error when executing javac without installing JDK.

Force java path mac

Before you answer "export JAVA_HOME=whatever >> ~/.bash_profile", just know it won't work. I even restarted my terminal and typed echo $JAVA_HOME, and got the right path.
How do you force (and I mean FORCE, not tell-java-it-exists) a custom path for the java home directory. My java 7 in installed in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java. Java doesn't recognize the java path. When I type java -version, it says 1.7.10_60. But, when I type java -version:1.7.10, it says it doesn't exist. When I launch my binary, it says Java 7 is required. It is a UNIX executable, and won't launch with the java command (with or without -jar).
You need to install the actual JRE (that path looks like just a plugin installation for applets). You can get it here

Run a Java program with java.exe in the same directory without installing

I know there are lots of posts similar to this, but all of their answers require creating an .exe file. I want to know how to run a program in a folder without installing java.
I don't want to install Java 8 as it breaks some of my programs. I want to run a java program in a folder using a start.bat file that points to the java.exe file in the same directory. Like this:
"java.exe" -jar program.jar
The error is like this:
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.7', but '1.8' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.
Since the command window is opened in the same directory, "java.exe" should point to the java runtime.
Can I maybe copy java.dll to the directory to make it work? How can I do this without installing java 8? Could I use java ME?
Why don't you create a .bat file that declares a new JAVA_HOME and appends to the PATH just for this DOS/batch session, then you can point to a place where you have the required JRE (however, you kind of have to install it... it's a Windows thing).
I understand you are reluctant to install the JDK/JRE 8 on your Windows because of this: "I don't want to install Java 8 as it breaks some of my programs". But trust me, you can always change the JRE version on the Java Control Panel (windows >> control panel >> Java) and change the JAVA_HOME & PATH environment variables, you might have problems with your browser's plugins though, the Java install will affect them as well.. I guess, in that, case you can either try to skip this part of the install process or.. install JDK 7 again afterwards?
IF you just want to run this program, you can also install VirtualBox and create a VM with windows and install the JDK8 there, avoiding any problems in your OS.

Switch between 32-bit and 64-bit JDK platform on Windows 7

I am using Windows 7 on my laptop. I am working with jpcap libraries which work only on 32-bit JDK. Having both 32 and 64 bit JDKs installed on my machine. How can I switch between 64-bit and 32-bit JDK?
I tried changing the %JAVAHOME% and %PATH% environment variables, but it didn't work. Should I change anything in the registry?
#Srikant Sahay, Thank you very much! It did work on widnows 8.1 64 bit OS.
I am able to Switch between 32-bit and 64-bit JDK platform on Windows 8.1 on demand. The trick, as Srikant suggested, is to set the path before all other path variables. Make sure you put fist in the path variable.
java -d32 -version ( or simply )
java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)
However, only one instance works at a time. Either you choose the 32 bit version or the 64 bit version. So, if you type "java -d64 -version" you will get
Error: This Java instance does not support a 64-bit JVM.
Please install the desired version.
Therefore, if you instead want a 64bit JVM you should put the JDk installation folder(in my case "C:\Program Files\Java\jdk1.7.0_51\bin" since the OS is 64 bit by default) first in the path variable.
cheers!
You can either set your path, or switch between JDK's in your IDE. Personally I use JetBrains IntelliJ IDEA and set the JDK via the IDE.
Setting via IDE:
From within a project:
click File -> Project Structure
Select Project under Project Settings
Select the Project SDK. If yours is not listed, click New -> JDK and browse for the JDK
From a new project:
Click File -> New Project
Select the Project SDK. If yours is not listed, click New -> JDK and browse for the JDK
If you want to set your path:
Follow the directions listed on the java.com site.
Keep in mind that your jar will run using whatever version of java is specified in your PATH.
If your PATH variable is not working, try cleaning up your path variable by removing unnecessary entries and rebooting. After reboot add Java to the path and reboot again.
If your still having issues, try executing using the absolute path of the java version your trying to use to ensure it works. If it does work, check your path variable against it to ensure it is accurate.
No, don't touch the registry. Each running Java application gets a single unique JVM instance. So a single java program cannot run some parts of the code in one JVM and other parts of the code in another JVM, as far as I know. You can, however, choose which JRE a particular java program runs in, so you can run the entire jpcap program in your 32 bit java version. Use a startup script (batch file) that points to the exact location of java.exe. When you run "java MyClassName" it's really just finding the java executable on the PATH environment variable, so by explicitly specifying your path, you get to choose your version. In other words, if you run a java program using "java MyClassName" (or if a program on your machine does so) it will use the java.exe application found on your PATH environment variable. Applications themselves can use whatever environment variables they choose: typically the ones used for java are JAVA_HOME and JRE_HOME. So you might want to try setting both of those and then trying to run your program again.
Set the path of your java in System Environment Variables PATH variable. Set it to be before any other path (even System 32 if java or javaw is present there).

Categories