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
32
votes
7 answers

javac does not work in ubuntu terminal

When I try to compile a java program with javac, I get an error: The program 'javac' can be found in the following packages: * default-jdk * ecj * gcj-4.6-jdk * gcj-4.7-jdk * openjdk-7-jdk * openjdk-6-jdk Try: sudo apt-get install
Prasanna
  • 2,593
  • 7
  • 39
  • 53
31
votes
5 answers

Why is the number of local variables used in a Java bytecode method not the most economical?

I have a snippet of simple Java code: public static void main(String[] args) { String testStr = "test"; String rst = testStr + 1 + "a" + "pig" + 2; System.out.println(rst); } Compile it with the Eclipse Java compiler, and examine the…
pf_miles
  • 907
  • 1
  • 8
  • 17
31
votes
8 answers

Javac is not found

I'm running Windows 8 and I can not get javac to work. I have set my PATH in environmental variables to C:\Program Files (x86)\Java\jdk1.7.0_17\bin I have tried both with and without ';' but to no avail. I recently had this issue on my desktop…
Arktri
  • 577
  • 2
  • 6
  • 9
29
votes
1 answer

unable to run javac on Ubuntu

I'm trying to run javac on a Ubuntu terminal. But I get the following: $ javac The program 'javac' can be found in the following packages: * openjdk-6-jdk * ecj * gcj-4.4-jdk * gcj-4.6-jdk * gcj-4.5-jdk * openjdk-7-jdk Try: sudo apt-get…
Shuo
  • 4,749
  • 9
  • 45
  • 63
29
votes
2 answers

Compiling four java files within one package using javac

I have four java files in my folder. They are all in the same package. Here's the package declaration package com.osama.GHide All of these classes are in the same package. I want to know how can I compile them using javac (i mean i do not know how…
prometheuspk
  • 3,754
  • 11
  • 43
  • 58
29
votes
6 answers

Would Java inline method(s) during optimization?

I wonder if JVM/javac is smart enough to turn // This line... string a = foo(); string foo() { return bar(); } string bar() { return some-complicated-string computation; } into string a = bar(); Or strip unnecessary call to foo() in release…
Schultz9999
  • 8,717
  • 8
  • 48
  • 87
28
votes
4 answers

When was Javac StringBuilder/StringBuffer optimization introduced?

I know that Javac compiler is able to transform String concatenation + using StringBuilder/StringBuffer, and I'm curious to know starting from which version this change was introduced? I'm using this sample code: public class Main { public static…
Nicolas C
  • 1,584
  • 2
  • 17
  • 33
28
votes
1 answer

why parallel execution on java compile take linear growth in time

time javac Main.java --> 0m1.050s time javac Main.java & javac Main.java --> 0m1.808s time javac Main.java & javac Main.java & javac Main.java --> 0m2.690s time javac Main.java & ... 8 time …
Bhuvan
  • 4,028
  • 6
  • 42
  • 84
28
votes
3 answers

Should I use javac -O option to optimize?

javac has an interesting -O option: Optimizes compiled code by inlining static, final and private methods. Note that your classes may get larger in size. This option seems to not be popular (hidden?), I've just discovered it today, on CodeCup…
Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
28
votes
1 answer

Annotation Processor, generating a compiler error

I'm trying to create a custom annotation that, for example, ensures that a field or method is both public and final, and would generate a compile time error if the field or method is not both public and final, as in these examples: //…
kuporific
  • 10,053
  • 3
  • 42
  • 46
28
votes
3 answers

Android: javac vs Dalvik

My understanding is that Google didn't like Oracle's licensing policy for using the JRE in Java ME so it just rewrote it using its own JVM specification that mimics the JRE but behaves a little bit differently, especially when it comes to making…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
27
votes
6 answers

Maven: javac: source release 1.6 requires target release 1.6

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…
Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
27
votes
5 answers

JDK/JRE/JVM/Java SDK | What do they all mean? Sometimes you can develop with JRE and sometimes you need JDK?

To tell the truth, I am quite confused on all these terms (JDK/JRE/Java SDK). I am not sure what each one does. When I first started doing simple java examples in eclipse, I am pretty sure I only had the JRE, which I believed was the default java…
Javed Ahamed
  • 2,804
  • 6
  • 32
  • 41
27
votes
7 answers

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

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 …
Not a bug
  • 4,286
  • 2
  • 40
  • 80
27
votes
5 answers

Javac "cannot find symbol"

I've the root directory like this : ├── classes └── src └── vehicles ├── Bicycle.java └── BicycleMain.java Bicycle.java package vehicles; public class Bicycle { public int cadence; public int gear; public int speed; …
andrian
  • 423
  • 1
  • 8
  • 15