javac

Will JRE 1.4 support classes compiled with Java 1.5 & 1.6?

回眸只為那壹抹淺笑 提交于 2019-11-28 08:55:42
问题 Will code compiled using 1.5 and 1.6 run on a 1.4 JRE? We weren't sure which Java versions the 1.4 JRE supports. We know that if the code in question implements 1.5 or 1.6 supported features then it definitely won't compile... and that there are some risks with "backwards compiling" but wasn't sure if the 1.4 JRE would refuse to even load the 1.5/1.6 compiled classes or not. Update : I confirmed you get a java.lang.UnsupportedClassVersionError exception if you run an 1.6 class file on JRE 1.4

How to compile java package structures using javac

时光毁灭记忆、已成空白 提交于 2019-11-28 07:37:39
I am trying to compile (from the command line) a java package that imports another package of my own. I was following a tutorial online but it seems that I get an error when I try to compile the final java file (CallPackage.java). Here is the file structure: + test_directory (contains CallPackage.java) -> importpackage -> subpackage (contains HelloWorld.java) Here is CallPackage.java: /// CallPackage.java import importpackage.subpackage.*; class CallPackage{ public static void main(String[] args){ HelloWorld h2=new HelloWorld(); h2.show(); } } and here is HelloWorld.java: ///HelloWorld.java

What Java code will force javac 1.6 to use the 'swap' and 'nop' opcodes?

馋奶兔 提交于 2019-11-28 07:25:03
问题 I'm working on an amateur JVM implementation, and I'm trying to make sure I have test coverage for all of the opcodes in the spec. I've gotten it down to the last few, but nop and swap have been eluding me. For example, here's a simple function that might use swap : static int do_swap() { int a = 56; int b = 32; return b%a; } But the bytecode produced by javac 1.6 avoids swapping in lieu of local storage: static int do_swap(); Code: 0: bipush 56 2: istore_0 3: bipush 32 5: istore_1 6: iload_1

How can I suppress javac warnings about deprecated api?

走远了吗. 提交于 2019-11-28 07:08:15
When I compile, javac outputs: Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details.` I wish to suppress this warning. Trying -Xlint:none does not seem to help. Thomas Owens From what I can tell in the docs, you can't do it on the command-line. According to the javac documentation , -Xlint:none only disables warnings "not mandated by the Java Language Specification". It appears that warning you of the use of deprecated APIs is managed by the language spec. Your best option would be to fix the use of deprecated APIs. However, an option

Any risk using a single dollar sign `$` as a java class name?

你说的曾经没有我的故事 提交于 2019-11-28 07:02:40
问题 Originally I was using the underscore _ as a class name. The new Java8 compiler complains that it " might not be supported after Java SE 8 ". I changed that to $ , and there is no warning any more. However I remember that $ is used by Java to indicate an inner/embedded class in the byte code. I am wondering if there is any risk to use a dollar sign $ as a class name Some background to this question. What I want to do is to overcome the fact that Java doesn't support pure function, and the _

what's the difference between -source and -target compatibility?

怎甘沉沦 提交于 2019-11-28 05:43:31
When using the Java compiler ( javac ), we can specify two kinds of compatibility. One is using -source and the other is using -target . What is the difference between these two? For example, -source 1.5 and -target 1.6 ? Also, is there any case where we use a different source and target compatibility level? From the javac docs : -source Specifies the version of source code accepted. -target Generate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier versions of the VM. In your example: -source 1.5 and

how to compile multiple java files when there are java files in other packages

北城以北 提交于 2019-11-28 05:04:43
I am compiling multiple files in a directory (javac *.java) but I have a problem when I try to do this: I get compile errors saying that say javac cannot find a symbol of an object. I have multiple packages that contain java files that are needed to run the main program. But it seems that trying to compile these one by one won't work. It runs fine in my IDE but I'm interested in learning how it's done via Command Prompt. The main program is in the drivers folder. I have tried compiling the files in order of dependency but that didn't work out. Javac documentation provides all the necessary

Maven: javac: source release 1.6 requires target release 1.6

て烟熏妆下的殇ゞ 提交于 2019-11-28 04:58:34
NOTE: This appears to be a limit in the "javac" program. I have Java 6 code that needs to be built for a Java 5 JVM. My previous work with the javac ant target (both with the JDK compiler and with ecj) led me to believe that it would simply be a matter of setting source and target for javac. Hence this pom.xml fragment: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.5</target> </configuration> </plugin> which works as expected from within Eclipse 3.7 with Maven support.

“Cannot find symbol” error - even on a ridiculously simple example

本小妞迷上赌 提交于 2019-11-28 04:47:35
问题 So I've been trying to solve this problem for a matter of hours now. I've scoured the internet, I've scoured StackOverflow, I've asked some co-workers (I'm an intern) and honestly no one can tell me what is going on! I put together a really really simple example to show you what I'm doing (and I get the error even with the simple example) I have two .java files. One is Test.java the other is testClass.java . //testClass.java package test; public class testClass { private int someMember=0;

Package not found; javac

你。 提交于 2019-11-28 04:37:24
问题 This is annoying. I have a directory structure like this -lib --some jar files -packageName --Main.java --SomeOtherPackage --SomeOtherJavaClass.java Main.java imports SomeOtherPackage . And both java files uses jars in the lib. What I do is add the jar files independently in the CLASSPATH. And then run as: javac packageName/Main.java but it gives the error that Package not found SomeOtherPackage . Shouldn't it automatically realize the dependency and build SomeOtherPackage as well? What would