javac

java comand works but not javac?

走远了吗. 提交于 2019-12-06 07:46:49
ok so I got a new PC Windows 7 Pro 64 bit Service Pack 1 I installed jdk-7u25-windows-x64 ( jdk 1.7.0_25) It is installed in default location C:\Program Files\Java\jdk1.7.0_25 I set the JAVA_HOME environment variable to C:\Program Files\Java\jdk1.7.0_25 I added %JAVA_HOME%\bin to the Path environment variable (yes I used a ; before I added it) Clicked Ok Closed all CMD windows opened them up And now If I run the command java I get the expected output But If I run the javac command I get this C:\Users\AJ>javac 'javac' is not recognized as an internal or external command, operable program or

Java Classes: Anonymous vs Nested vs Private

一曲冷凌霜 提交于 2019-12-06 06:49:53
问题 Can someone explain the difference between anonymous classes, nested classes and private classes in Java? I'd like to know the runtime costs associated with each and the compiler approach to each, so I can get a grip on which is best to use for e.g. performance (potential for compiler optimisations), memory usage, and general acceptability with other Java coders. By anonymous classes I mean those declared inline in a function in that weird Java way. This is often seen in examples of Swing

How to change the defaults system java encode form in windows?

大憨熊 提交于 2019-12-06 04:57:22
When I tried to compile (use javac)some java sources files include a comment line which has some unrecognized char like ascii code 129 (~A), error got. The sources code looks like the following: // ascii 129 is ? (Acutally it show ~A in VIM but show ? when I directly copy it here) The above code line is a comment, it should not cause any error, but if it did, I think it should be a problem about the jave encode form, how can I solve this problem? Thanks. Wa kentcdodds Take a look at this answer. It worked for me, and I don't have to worry about it anymore :) https://stackoverflow.com/a/623036

How can I compile classes in packages, to execute them later with “java Program” (without the package name)?

五迷三道 提交于 2019-12-06 03:28:09
I have a quick question regarding javac and packages in Java. I have a simple program (we'll call it Program.java) which is currently in the following directory: myRepository/myProgram In Program.java and other .java files in the myRepository/myProgram directory, I have declared package myProgram.* and also included import myProgram.*; . So when I type javac myProgram/Program.java , it compiles fine and it runs fine if I type java myProgram/Program . However, I'm trying to get the .class files to be produced in the myRepository directory, not myRepository/myProgram , which is where the source

Do repeating annotations need a public container?

半城伤御伤魂 提交于 2019-12-05 19:24:22
I noticed a discrepancy between Eclipse's compiler and javac while using repeating annotations. The repeating annotation and its container were in the same package, but the former was declared public, while the latter remained package-private. Eclipse had no problem with the arrangement, even though the repeating annotation was referenced in another package. javac, on the other hand, refused to compile, saying value() in [container] is defined in an inaccessible class or interface My question is, which one is correct? I couldn't find any rule about this in the JLS. Does that mean it's open to

Issue running java program from batch file, runs fine in IDE

北城以北 提交于 2019-12-05 18:25:58
I'm doing some basic java homework for a class on my new laptop - issue is, I can't seem to get the program to compile and run from my batch file using the directions the instructor gave me. I've set the Path variable to my JDK inside the Environment Variables settings. My program is a simple shipping program to keep track of shipment information - I have the program working flawlessly in NetBeans (which our instructor advised us to use for developing the code), but he's going to be testing them using batch files, so we're also advised to test them on our systems with one we create prior to

Exporting a package from system module is not allowed with --release

二次信任 提交于 2019-12-05 18:00:11
问题 I have the following program: module-info.java module a { } Main.java public class Main { public static void main(String[] args) { System.out.println(sun.nio.ByteBuffered.class); } } This program successfully compiles with the --add-exports option: > javac --add-exports java.base/sun.nio=a module-info.java Main.java However, when I add the --release argument, it fails: > javac --add-exports java.base/sun.nio=a --release 9 module-info.java Main.java error: exporting a package from system

Java compiler in java [duplicate]

空扰寡人 提交于 2019-12-05 17:21:55
This question already has answers here : Closed 8 years ago . Possible Duplicate: implementing a compiler in “itself” I was reading about the Java compiler and realized that it was written in Java. How can that be possible? I mean, isnt this like "Chicken and egg" problem? How can we write the compiler in the same language? The original was written in C. Then you can write the next version in Java. :) JasCav The problem you are addressing is really a problem with any compiler. For example, many compilers are written in C. Well...how do you compile a C compiler without having a C compiler

JDK8 type inference issue

浪尽此生 提交于 2019-12-05 17:10:32
I'm trying to run the following code which is compiled fine under JDK8 thanks to type inference: public static <A,B> B convert(A a) { return (B) new CB(); } public static void main(String[] args) { CA a = new CA(); CB b = convert(a); //this runs fine List<CB> bl = Arrays.asList(b); //this also runs fine List<CB> bl1 = Arrays.asList(convert(a)); //ClassCastException here } However, running this throws ClassCastException: CB cannot be cast to [Ljava.lang.Object, but the CB b = convert(a) works fine. Any idea why? Holger Whenever you create a generic method with a signature that promises to

javac -Xlint:overrides not working

狂风中的少年 提交于 2019-12-05 13:00:40
I'm trying to get my java build to fail when I have a class that overrides a superclass method without specifying the @Override annotation. The build is being done via ant, and I've added the following elements to my <javac> task: <compilerarg value="-Werror"/> <compilerarg value="-Xlint:unchecked,overrides"/> The unchecked option is being followed, but the overrides option is being ignored. I also tried separating the two Xlint options into two separate <compilerarg> elements, to no avail. Am I misunderstanding what this option does? One note: this is JDK6 on MacOSX (10.6). Could I be running