Questions tagged [javac]

javac is the primary Java compiler, included in the Java Development Kit (JDK) from Sun Microsystems (now Oracle), and also in versions from other vendors.

javac is the primary Java compiler, included in the Java Development Kit (JDK) from Sun Microsystems (now Oracle), and also in versions from other vendors.

The compiler accepts source code conforming to the Java language specification (JLS) and produces bytecode conforming to the Java Virtual Machine Specification (JVMS). javac is itself written in Java. The compiler can also be invoked programmatically.

2467 questions
95
votes
11 answers

Is the creation of Java class files deterministic?

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…
mstrap
  • 16,808
  • 10
  • 56
  • 86
94
votes
11 answers

How to intentionally cause a custom java compiler warning message?

I'm about to commit an ugly temporary hack in order to work around a blocking issue while we wait for an external resource to be fixed. Aside from marking it with a big scary comment and a bunch of FIXMEs, I'd love to have the compiler throw an…
pimlottc
  • 3,066
  • 2
  • 29
  • 24
81
votes
6 answers

Optimization by Java Compiler

Recently, I was reading this article. According to that article, Java Compiler i.e. javac does not perform any optimization while generating bytecode. Is it really true? If so, then can it be implemented as an intermediate code generator to remove…
Mahesh Gupta
  • 2,688
  • 9
  • 30
  • 46
76
votes
19 answers

Maven Unable to locate the Javac Compiler in:

When i try to generate a war file, it is showing some error like [ERROR] Unable to locate the Javac Compiler in: [ERROR] C:\Program Files\Java\jre7\..\lib\tools.jar When i do echo %path% it shows …
BKK
  • 1,199
  • 6
  • 16
  • 24
75
votes
14 answers

javac command line compile error: package javax.servlet does not exist

I have a Servlet class in which I import javax.servlet.* and javax.servlet.http.*. When I try to compile it in command prompt I get the error package javax.servlet does not exist I use JDK 1.7.0 and Tomcat 6.0. I compile using javac. I am not…
Karadous
  • 1,555
  • 3
  • 26
  • 37
73
votes
4 answers

Setting the target version of Java in ant javac

I need to compile a jar file using ant (1.7.0) to run under a specific version of Java (1.5). I currently have Java 1.6 on my machine. I have tried setting: I…
peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217
72
votes
7 answers

JDK 11.0.2 compilation fails with javac NPE on anonymous parameterized class type inference

Code (spring-web 5.1.2) public static void main(String[] args) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set(HttpHeaders.AUTHORIZATION, "token"); HttpEntity
Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78
72
votes
6 answers

What is the $1 in class file names?

C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet>dir Volume in drive C has no label. Volume Serial Number is 2041-64E7 Directory of C:\Program Files\Java\jdk1.6.0_05\CoreJava\v1\v1ch2\WelcomeApplet 2009-07-02 23:54 …
omg
  • 136,412
  • 142
  • 288
  • 348
71
votes
8 answers

Unable to locate an executable at "/usr/bin/java/bin/java" (-1)

I am having a pathetic issue with Java in my mac osx 10.7.3 . Previously I installed it and it was working fine. After some changes in the .bash_profile and .profile file in the course of time, I am having an error like Unable to locate an…
Sabya
  • 1,419
  • 1
  • 10
  • 14
67
votes
6 answers

How to write code in Java 11, but target Java 8 and above?

I am working on a small library and for obvious reasons I would like to write code using all the Java 11 features (except modules I guess for now), but I would like the library to be compatible with Java 8 and above. When I try this: javac -source…
neshkeev
  • 6,280
  • 3
  • 26
  • 47
64
votes
5 answers

How to compile multiple java source files in command line

I know running javac file1.java produces file1.class if file1.java is the only source file, then I can just say java file1 to run it. However, if I have 2 source files, file1.java and file2.java, then how do I build the program?
Alfred Zhong
  • 761
  • 2
  • 6
  • 5
63
votes
3 answers

Is there a performance difference between Javac debug on and off?

If I switch on the generating of debug info with Javac then the class files are 20-25% larger. Has this any performance effects on running the Java program? If yes on which conditions and how many. I expect a little impact on loading the classes…
Horcrux7
  • 23,758
  • 21
  • 98
  • 156
62
votes
1 answer

Make javac treat warnings as errors

I have an Ant file that compiles my program. I want the javac task to fail if any warning was reported by the compiler. Any clue on how to do that?
Itay Maman
  • 30,277
  • 10
  • 88
  • 118
61
votes
7 answers

Suppress javac warning "...is internal proprietary API and may be removed in a future release"

When I compile the Spring JDBC source on OS X with JDK 1.7.0, I get this warning: warning: CachedRowSetImpl is internal proprietary API and may be removed in a future release How do I suppress the warning message during a compile? I already know…
Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
60
votes
9 answers

How can I suppress javac warnings about deprecated api?

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.
IttayD
  • 28,271
  • 28
  • 124
  • 178