javac

Is the creation of Java class files deterministic?

筅森魡賤 提交于 2019-11-28 03:44:18
When using the same JDK (i.e. the same javac executable), are the generated class files always identical? Can there be a difference depending on the operating system or hardware ? Except of the JDK version, could there be any other factors resulting in differences? Are there any compiler options to avoid differences? Is a difference only possibly in theory or does Oracle's javac actually produce different class files for the same input and compiler options? Update 1 I'm interested in the generation , i.e. compiler output, not whether a class file can be run on various platforms. Update 2 By

“Cannot find symbol” for my own class

僤鯓⒐⒋嵵緔 提交于 2019-11-28 03:14:28
问题 I do not have a %CLASSPATH% set up. As I understand, this should not be a problem because Javac will assume a classpath of the current directory. As you can see below, javac is unable to find my Case class even though it's in the same exact directory. Any thoughts on why this is happening? This code works fine when I use Eclipse. C:\Documents and Settings\joep\My Documents\GCJ\src\codejam2011\Round0\D>dir /B Case.class Case.java EntryPoint.java C:\Documents and Settings\joep\My Documents\GCJ

Config Maven 2 to print out javac commands during compile phase

风格不统一 提交于 2019-11-28 03:09:08
问题 Is there any way to force Maven 2 (>2.0.10) to print the actual javac commands it's executing. We keep running out of memory even though we've bumped up the max using MAVEN_OPTS. I'd like to be able to see the actual command being executed that is running out of memory. I've tried using the verbose setting below in the pom file's plugin management section but that doesn't seem to give me the javac command: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin<

Why does array[idx++]+=“a” increase idx once in Java 8 but twice in Java 9 and 10?

霸气de小男生 提交于 2019-11-28 02:30:49
For a challenge, a fellow code golfer wrote the following code : import java.util.*; public class Main { public static void main(String[] args) { int size = 3; String[] array = new String[size]; Arrays.fill(array, ""); for(int i = 0; i <= 100; ) { array[i++%size] += i + " "; } for(String element: array) { System.out.println(element); } } } When running this code in Java 8, we get the following result: 1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 91 94 97 100 2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98

How to compile and run with this folder structure

梦想与她 提交于 2019-11-28 02:24:09
I have my java source files in src/net/... folders and .jar files in lib folder. How to compile and run this files with command line without writing build script ? Lets say you have your code files in [someDirectory] | +-[lib] | | | +-someLib.jar | +-someOtherLib.jar | +-... | +--[src] | +-[net] | +-[name] | +-[one] | +-[two] | +-[main] | +-Main.java <- code you want to compile and execute then if your console is in someDirectory> you can compile it with someDirectory>javac -cp "lib\*" src\net\name\one\two\main\Main.java but this will produce Main.class file in same directory as Main.java so

How to run Javac from Eclipse

倾然丶 夕夏残阳落幕 提交于 2019-11-28 01:21:32
I'm trying to run 'javac' tool on a compiled .class file in Eclipse. I open External Tools Configuration them fill the filds: Location: C:\Program Files\Java\jdk1.6.0_25\bin\javac.exe Working directory: ${workspace_loc:/Main/bin} Arguments: ? I want to ask you what must I write in the Arguments field, and am I fill* Location * and Working directory: fields right ? Launching the javac compiler from within Eclipse can be a very useful feature in some cases (e.g. for testing purposes, to compare the javac output with the output of the Eclipse compiler, to recompile individual class files with

Why calling method with generic return on a generic class is considered unsafe by javac?

空扰寡人 提交于 2019-11-28 00:42:57
Consider the following code: public class Main { public static class NormalClass { public Class<Integer> method() { return Integer.class; } } public static class GenericClass<T> { public Class<Integer> method() { return Integer.class; } } public static void main(String... args) { NormalClass safeInstance = new NormalClass(); Class<Integer> safeValue = safeInstance.method(); GenericClass unsafeInstance = new GenericClass(); Class<Integer> unsafeValue = unsafeInstance.method(); } } If I compile it with: $ javac -Xlint:unchecked Main.java It returns: Main.java:16: warning: [unchecked] unchecked

Can I use JAVAC to compile a project with multiple files and directories?

余生颓废 提交于 2019-11-28 00:36:29
问题 I'm working on a very large project that has associated class files in multiple directories, all stemming from the root dir \src. I'm trying to compile a file in src\solution\ (called Console.java) that uses imports from other directories in the src, which are still uncompiled. So if I want to compile Console.java outside of an IDE, how do I go about doing that? Oh yeah, I also have some external JARs which need to be included in the build. Thanks! I appreciate it! 回答1: I would look at using

Which JDK's distributions can run `javac -source 1.6 -target 1.5`?

本小妞迷上赌 提交于 2019-11-28 00:28:54
NOTE: Please do not comment on all the perils of cross-compiling. Thank you. I have a situation where we need to have Java 6 source compiled for a Java 5 JVM (to be sure that JAX-WS usage is correct). Previously we have done this with ant ant script (which apparently can), but after migrating to Maven we have found that it ends up with javac complaining: $ javac -source 1.6 -target 1.5 javac: source release 1.6 requires target release 1.6 Is there any Java distribution for Linux (Ubuntu 11.10, x86) where the javac can do this? EDIT: It appears not, as the limitation is in javac which is the

Why does Java compiler allow static variable access through null object? [duplicate]

血红的双手。 提交于 2019-11-27 21:54:10
This question already has an answer here: How come invoking a (static) method on a null reference doesn't throw NullPointerException? 5 answers I was pointing some tricks and came across this. In following code: public class TestClass1 { static int a = 10; public static void main(String ar[]){ TestClass1 t1 = null ; System.out.println(t1.a); // At this line } } t1 object is null . Why this code is not throwing NullPointerException ? I know this is not proper way to access static variables but question is about NullPointerException . To add some additional info to the current answers, if you