javac

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

别说谁变了你拦得住时间么 提交于 2019-12-10 09:52:44
问题 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 回答1: Take a look at this answer. It

Java compiler in java [duplicate]

♀尐吖头ヾ 提交于 2019-12-10 09:28:08
问题 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? 回答1: The original was written in C. Then you can write the next version in Java. :) 回答2: The problem you are addressing is really a problem with any compiler. For example,

do not use com.sun.xml.internal.*?

牧云@^-^@ 提交于 2019-12-10 03:26:32
问题 Is this statement true: com.sun.xml.internal package is an internal package as the name suggestes. Users should not write code that depends on internal JDK implementation classes. Such classes are internal implementation details of the JDK and subject to change without notice One of my colleagues used one of the classes in his code, which caused javac task in Ant fail to compile our project as the compiler couldn't find the class. Answer from Sun/Oracle says that this is expected behavior of

Does javac removes methods that are not referenced in the code?

那年仲夏 提交于 2019-12-10 03:06:09
问题 I have a code base and some methods are never used. Does javac remove the unused methods from the class file? 回答1: Q: I want to know if I have a code base and some methods are never used. Does javac remove the unused methods from the class file? A: No. What goes into the class, stays in the class file. ... however ... The JVM loads only what's needed into memory. RAM isn't "wasted" on unused classes. 回答2: No, it doesn't. To verify this, you can run javap -c foo.bar.MyClass and see all the

Covariant Return Type in Interface not compiling via Javac

不羁的心 提交于 2019-12-10 02:52:07
问题 I have the following structure: public interface BarReturn {} public interface FooReturn {} public interface FooBarReturn extends FooReturn, BarReturn {} public interface Foo { FooReturn fooBar( ); } public interface Bar { BarReturn fooBar(); } public interface FooBar extends Foo, Bar { FooBarReturn fooBar(); } Javac fails with the following message: FooBar.java:2: types Bar and Foo are incompatible; both define fooBar(), but with unrelated return types public interface FooBar extends Foo,

Set Java compiler compliance level

ε祈祈猫儿з 提交于 2019-12-10 02:45:21
问题 I need to compile a Java program on the command line, and I am trying to set the compiler level to a lower one (1.6). I tried like this but it didn't work: javac -1.6 Hello.java 回答1: Use -source and -target options: javac -target 1.6 -source 1.6 Hello.java 回答2: Use: javac -source 1.6 -target 1.6 Hello.java This information comes from running javac -help : Usage: javac <options> <source files> where possible options include: -g Generate all debugging info -g:none Generate no debugging info -g:

javac treating static final differently based on assignment method

こ雲淡風輕ζ 提交于 2019-12-09 13:07:36
问题 When I compile: public static final boolean FOO = false; public static final void fooTest() { if (FOO) { System.out.println("gg"); } } I get an empty method fooTest() {} . However when I compile: static boolean isBar = false; public static final boolean BAR = isBar; public static final void fooTest() { if (BAR) { System.out.println("gg"); } } the if statement is included in the compiled class file. Does this mean there are two different "types" of static final in java, or is this just a

Is there a Java library to generate class files from an AST?

余生长醉 提交于 2019-12-09 09:16:02
问题 This page describes how I can use the code generator in javac to generate code given that I can build an AST (using a separate parser which I wrote). The technique involves editing javac's source code to basically bypass the Java parser, so that one could supply his/her own AST to the code generator. This could work, but I was hoping to do it in a slightly cleaner way. I want to include the code generating part of javac as a library in my project so I can use it to generate code, without

Java: System cannot find the file C:\\ … java.exe

时光怂恿深爱的人放手 提交于 2019-12-09 04:12:28
I have installed Java 8 and set my JAVA_HOME and JRE_HOME paths and added %JAVA_HOME% to the start of the path variable. I created a helloworld.java application and am able to compile it using: javac helloworld.java However, when I try to run: java helloworld I get the error: The system cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe How can I solve this? Just set %JAVA_HOME% /bin to your path variable. 1.Just go to C:\ProgramData\Oracle\Java\javapath\ 2.You will find there shortcuts for java.exe,javaw.exe,javaws.exe which are pointing to a location where they actually are

javac show error without warnings

余生长醉 提交于 2019-12-08 19:32:12
问题 I'm using Sun's javac 1.6.0_26. I invoke it like this: javac -Xlint -encoding UTF-8 and usually if there are errors only them are displayed. However this code class Test{ public static void main(String args[]) { java.util.Date d = new java.util.Date(); system.out.println(d.getDate()); } produces both warning and error: java:5: warning: [deprecation] getDate() in java.util.Date has been deprecated system.out.println(d.getDate()); ^ java:5: package system does not exist system.out.println(d