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
42
votes
5 answers

Running java in package from command line

I have read the previously posted questions. Some are vague and none solved my problem so I am forced to ask again. I have two simple classes, package One; import One.Inner.MyFrame; public class test { public static void main(String args[]) …
user2756339
  • 685
  • 1
  • 10
  • 17
42
votes
13 answers

How to run a .class file that is part of a package from cmd?

I keep getting errors when I make my .class part of a package and try to run it from cmd. Here's the code that works after using javac and then java: class HelloWorld { public static void main(String[] args) { System.out.println("Hello…
user2666594
41
votes
4 answers

Differences between classpath and sourcepath options of javac

I read the Sun documentation and a lot of posts on Stack Overflow, but I'm still confused about the differences between the Java compiler options -cp and -sourcepath. Let say I have this directory structure: c:\Java\project1\src (where the Java…
Alex
  • 577
  • 1
  • 5
  • 8
40
votes
4 answers

How can I compile and run a Java class in a different directory?

I'm writing a makefile that compiles a .java file in a different directory, and then I want to run it, without changing directories. I want to do something along the lines of: $(SQM_JAVA_TOOL_DONE) : $(SQM_JAVA_TOOL) $(shell cd /home_dir) …
vette982
  • 4,782
  • 8
  • 34
  • 41
40
votes
8 answers

Java compilation errors limited to 100

I have a Java file,which when I compiled, I will be able to see only first 100 errors on console after that java compiler(javac) exits. How will I be able to see all the compilation errors on console? Thanks in advance- opensid
openssid
  • 711
  • 3
  • 8
  • 18
39
votes
5 answers

javac optimization flags

I've recently been writing a lot of code in C and am now switching over to Java. I'm currently implementing a large data structure and was wondering whether there were any optimization flags I can turn on when I invoke the Java compiler in order to…
themaestro
  • 13,750
  • 20
  • 56
  • 75
39
votes
1 answer

What is the difference between using javac and javax.tools.JavaCompiler?

Maven Compiler Plugin documentation states: The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want…
Vic
  • 21,473
  • 11
  • 76
  • 97
38
votes
1 answer

Why does javac insert Objects.requireNonNull(this) for final fields?

Consider the following class: class Temp { private final int field = 5; int sum() { return 1 + this.field; } } Then I compile and decompile the class: > javac --version javac 11.0.5 > javac Temp.java > javap -v Temp.class …
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
38
votes
4 answers

javac source and target options

I have seen the compile options like discussed in Which JDK's distributions can run `javac -source 1.6 -target 1.5`?. I understand the individual options for source and target. I don't understand why source version is higher that the target…
bobby
  • 2,629
  • 5
  • 30
  • 56
37
votes
3 answers

Reference is ambiguous with generics

I'm having quite a tricky case here with generics and method overloading. Check out this example class: public class Test { public void setValue(Parameter parameter, T value) { } public void setValue(Parameter parameter,…
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
37
votes
1 answer

In Java Lambda's why is getClass() called on a captured variable

If you look at the byte code for Consumer println = System.out::println; the byte code generates by Java 8 update 121 is GETSTATIC java/lang/System.out : Ljava/io/PrintStream; DUP INVOKEVIRTUAL java/lang/Object.getClass…
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
35
votes
2 answers

Drawbacks of javac -parameters flag

I want to try some frameworks features that required names of parameter in runtime, so I need to compile my app with -parameters and it will store the names of parameter in JVM byte code. Which drawbacks except the size of jar/war exist of this…
VladS
  • 4,116
  • 4
  • 16
  • 17
33
votes
10 answers

Illegal Character when trying to compile java code

I have a program that allows a user to type java code into a rich text box and then compile it using the java compiler. Whenever I try to compile the code that I have written I get an error that says that I have an illegal character at the beginning…
muckdog12
  • 400
  • 1
  • 4
  • 10
32
votes
3 answers

Ant: passing compilerarg into javac

I have ant script that compiles: ... I need to increase heap memory of compiler,…
32
votes
11 answers

How to compile a java source file which is encoded as "UTF-8"?

I saved my Java source file specifying it's encoding type as UTF-8 (using Notepad, by default Notepad's encoding type is ANSI) and then I tried to compile it using: javac -encoding "UTF-8" One.java but it gave an error message" One.java:1: illegal…
asela38
  • 4,546
  • 6
  • 25
  • 31