I'm Having the following errors:
Error: Registry key Software\JavaSoft\Java Runtime Environment.
Error: Could not find java.dll.
Error: Could not find java SE Runtime Environment.
when I'm running Jre 7 86x from a folder that contains Unicode characters.
To reproduce this dysfunction follow those steps:
Copy Jre 7 86x folder to a folder in which it's name contains Unicode characters for example (功能障碍).
Try to execute java.exe / javaw.exe.
The system language must be different from any Unicode language (Chinese, Japanese, ...), in my case the system language is English.
Any clue what is going on?
Related
I have an Enum class in Java that contains the letter É:
public enum Types {
RÉSUMÉ
}
When trying to build the project, IntelliJ complains on the É sign:
error: illegal character: '\u2030'
RÉSUMÉ
^
I'm using Windows 10.
In the past, the same project was compiled and run with no problems on my computer. So it seems like something in the settings was changed that caused this.
There is no option to replace É with E
Any idea how to fix this?
EDIT
The code used to run with JDK 11 and was upgraded to Java 17. Maybe it has something to do with it. Trying to downgrade the JDK of the project (Settings -> Build -> Gradle -> back to JDK 11) didn't help
Character set & encoding of Java source code files
As commented, likely your source code files were written with a character encoding other than UTF-8. Now your compiler is expecting UTF-8, and reading your source code as such.
This problem could occur for either of two reasons:
Your settings for your compiler or IDE changed
👉 You changed your JDK from an earlier version of Java to Java 18 or later.
Earlier versions of Java by default expect source code to be written in the default character set of the host OS platform.
Java 18+ defaults to UTF-8 across OS platforms for most purposes.
The main clue for this character encoding misreading hypothesis is that code point U+2030 is not the LATIN CAPITAL LETTER E WITH ACUTE character, nor is it the composition of an uppercase E followed by the accent. No, the code point 2030 in hex (8,240 in decimal) is PER MILLE SIGN: ‰.
Java 18+ defaults to UTF-8
See JEP 400: UTF-8 by Default. To quote:
If source files were saved with a non-UTF-8 encoding and compiled with an earlier JDK, then recompiling on JDK 18 or later may cause problems. For example, if a non-UTF-8 source file has string literals that contain non-ASCII characters, then those literals may be misinterpreted by javac in JDK 18 or later unless -encoding is used.
You can easily verify if this new default is the source of your problem. 👉 Go back to your old project, and specify UTF-8 for compiling. Again, quoting the JEP:
Prior to compiling on a JDK where UTF-8 is the default charset, developers are strongly encouraged to check for charset issues by compiling with javac -encoding UTF-8 ... on their current JDK (8-17).
I have a very simple code:
public static void main(String[] arg){
FileSystems.getDefault();
}
It runs good in Java7
But throws UnsupportedCharsetException: GBK in java8, full stack as below:
Exception in thread "main" java.lang.ExceptionInInitializerError
at sun.nio.fs.WindowsFileSystem.<init>(WindowsFileSystem.java:67)
at sun.nio.fs.WindowsFileSystemProvider.<init>(WindowsFileSystemProvider.java:53)
at sun.nio.fs.DefaultFileSystemProvider.create(DefaultFileSystemProvider.java:36)
at java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:108)
at java.nio.file.FileSystems$DefaultFileSystemHolder.access$000(FileSystems.java:89)
at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:98)
at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:96)
at java.security.AccessController.doPrivileged(Native Method)
at java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:96)
at java.nio.file.FileSystems$DefaultFileSystemHolder.<clinit>(FileSystems.java:90)
at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
at com.yy.ent.test.Test1.main(Test1.java:26)
Caused by: java.nio.charset.UnsupportedCharsetException: GBK
at java.nio.charset.Charset.forName(Charset.java:531)
at sun.nio.fs.Util.<clinit>(Util.java:41)
... 12 more
I am using windows7 in Chinese
And my java8 is:
Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)
How can I solve this problem?
Either try changing "sun.jnu.encoding" property to something else, for example:
-Dsun.jnu.encoding=UTF-8
or check if your JVM contains "lib/charsets.jar" which is required for GBK support according to (http://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html)
It would seem that the JRE installer only installs "extended" character sets if the locale requires it: https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html
Oracle's Java SE Development Kit 7 (Java SE 7) for all platforms (Solaris, Linux, and Microsoft Windows) and the Java SE Runtime Environment 7 (JRE 7) for Solaris and Linux support all encodings shown on this page. Oracle's JRE 7 for Microsoft Windows may be installed as a complete international version or as a European languages version. By default, the JRE 7 installer installs a European languages version if it recognizes that the host operating system only supports European languages. If the installer recognizes that any other language is needed, or if the user requests support for non-European languages in a customized installation, a complete international version is installed. The European languages version only supports the encodings shown in the following Basic Encoding Set table. The international version (which includes the lib/charsets.jar file) supports all encodings shown on this page.
This should also apply to Java 8. I read this to mean, that the JDK supports all charsets (includes lib/charsets.jar). The JRE tries to install a minimal environment and won't install extended characters sets, such as GBK, if the installer is being run by a user with a European locale.
Solution:
Try installing the JDK or set your user's region and language to Chinese (Simplified), then re-install the JRE.
I have both java 6 and 7 installed for compatibility reasons. Right now, I need to use java 6 but I don't want to uninstall java 7. I looked carefully at the path and replaced java 7 with the path to java6 in java_home. closed and restarted another cmd window. Java 7 is 64 bit and java 6 is 32 bit.
Currently,
javac gives 1.6 which is what I expect, however, I'm not sure why java -version gives 1.7. How do I make it so that on windows 7 command prompt, when I type java - version, it would give java 6 instead?
i renamed the java 7 folder, and when I type java, I get this error:
C:>java
Error: could not open `C:\Program Files\Java\jre7\lib\amd64\jvm.cfg'
I thought the path would dictate what version of java will be used.
Thanks.
Don't rename the folder -- it simply will corrupt the existing installation. Instead make sure that in the PATH environment variable, a reference to %JAVA_HOME% exists before any path that contains Java. Typically a Java launcher exists in the Windows directory (e.g. the C:/Windows/system32 folder), which may still be using a different version than the one used by JAVA_HOME. Try to have %JAVA_HOME% referenced before that path in the PATH variable:
PATH = %JAVA_HOME%;other_paths
So I'm trying to get the latest version of Java. When I run:
java -version
I get:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
When I run:
javac -version
I get:
javac 1.6.0_65
Now I've just downloaded and installed JDK 8. When I go into System Preferences --> Java --> Update, I see:
Your system has the recommended vesion of Java.
Java 8 Update 05.
I guess I have a few questions:
1) Don't I want the JDK and my version of Java to match up?
2) Why does my Java Control Panel claim I have Java 8, but my work in the terminal (when checking my Java version) says otherwise?
Thanks for the help,
Mariogs
The probably "simple" answer is you have two versions of java installed. On the command line you currently use 1.6. Thus the old one is active. In system preferences you see the version of java 8.
Windows:
You can change the version of the command line to java 8. Set PATH environment variable and JAVA_HOME or via windows preferences. I recommend the first one.
Mac: /usr/libexec/java_home is the starting point for switching java versions on the command line. Check out this post to understand how to handle different java versions on the Mac. IMHO this answer is a good solution.
The Java Platform offers both the JRE and the JDK in order for users to run Java programs. The JRE stands for the Java Runtime Environment, and the JDK stands for the Java Development Kit.
The JDK is meant for Java developers - that is, those who build applications/write programs in Java. It contains tools that are needed for Java coding, including -javac to compile programs.
The JRE is meant for regular users - those who only need to run Java programs on their computer and are not interested in development.
The reason for the discrepancy in your case is because you're looking at the JRE and JDK and trying to compare the two. The current JDK that you have is Java 8, whereas the current JRE that you have is 1.6.0_65. It is problematic that your JRE version does not match your JDK version, but without your PATH variable or other information about your install, we can't help you fix your installation.
1) Yes, if you use the JDK at all, you want the JRE (runtime environment) to come from the JDK (development environment) (a JDK necessarily includes a JRE).
2) Likely your path variable is set so that you invoke Java from your Java 6 installation; you need to find the equivalent for your Java 8 installation and set the path for that. Without information about your operating system, we can't help you do that.
We should know the reason for this
Our OS comes with a predefined (built-in)set of tools and utilities. When we try to execute the command e.g. cls in the Windows command line then it is already present in system path variable and os will refer the corresponding binary of cls to execute the command.
However, when we install any third party tool/software then path variable is not updated accordingly.
When we install different versions of java on your system then installations go to different directories. E.g. JDK installation directory for Windows will be
C:\Program Files\Java\jdk1.8.0_161
Similarly, JRE installation directory for Windows will be JDK installation directory for Windows will be
C:\Program Files\Java\jre1.8.0_161
We need to update the path variable of OS to point to the appropriate directory. If we set the path of JDK then it will execute a binary from JDK bin directory.
Solution
we need to update JDK or JRE version specific directory location into PATH Environment variable.
Let me see if I can clear it up for you.
1)Yes, arguably you nearly want this to be true.
2)It could be few things, but most likely that a previous instillation was not properly removed. So one gets called instead of the other.
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.