2,494 questions
Advice
0
votes
3
replies
104
views
Explicit class reference during static initialization not allowed. Why?
Note. I hope "why" questions do fall into the "other" category.
This compiles.
class MyClass {
private static final String STRING;
static {
STRING = "abc&...
3
votes
1
answer
103
views
Java code runs in IDE, but fails to compile in terminal [closed]
I'm curious to know why I get this error when compiling my java file from the terminal.
I expect the program to compile into an executable file, yet instead I get errors about my packages not existing....
1
vote
0
answers
75
views
Why doesn't the Java compiler in IntelliJ IDEA complain about filename case mismatches? [duplicate]
I'm learning Java and experimenting with compiling source files. I understand that Java is case-sensitive, and that the filename must match the public class name exactly — including the case.
public ...
2
votes
1
answer
142
views
javac 21 Xlint not showing warnings for missing serial version ID on an anonymous class unlike Eclipse
I have a Maven parent POM that configures the Maven Compiler Plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</...
1
vote
1
answer
157
views
Does java compiler (javac) require JVM to compile the java code? [duplicate]
So I got to know that javac compiler is written in Java. And JVM converts the bytecode (compiled Java code) to machine code for execution.
Two questions:
If javac is written in Java, does compiling ...
7
votes
1
answer
341
views
Why does using instanceof pattern matching on a record field with a switch expression in the same method cause a java.lang.VerifyError?
I found this minimal set of code which seems to break any Java version I can find. (Also reproducible in https://www.onlinegdb.com/online_java_compiler with Java 23.0.2+7-58). The example is not meant ...
0
votes
1
answer
201
views
ktor sample app not building due to java compiler not found
I am new to ktor and am following the ktor tutorial (https://ktor.io/docs/server-create-a-new-project.html) and am unable to build the sample app (5th step of unpacking, https://ktor.io/docs/server-...
1
vote
1
answer
646
views
How to specify an ASM and lombok version to Maven on Java 24 project?
I am working on a project expecting Maven to resolve version issues and dependencies but keeps crashing on compile phase.
First I had the known "unknown reference" for jdk 24:
[JAVAC][com....
-2
votes
1
answer
149
views
Reflection API and JVM and JIT [closed]
The compiler compiles the source code into bytecode that is then converted into machine code by the JVM or the JIT compiler. If the JIT compiler converts the bytecode to machine code then there is no ...
1
vote
0
answers
110
views
Simple Maven project with maven.compiler.release not working
I have the following simple POM, with only one .java file in src/main/java:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0&...
3
votes
1
answer
124
views
How Java internally processes `String` concatenation operator `+` in a chain?
Here is the code:
import java.util.Random;
public class StringConcatCompilerOptimization
{
private static long compute() {
var random = new Random();
var l = random.nextLong();
...
0
votes
0
answers
58
views
Java compiler (via Apache Ant) not detecting jars in library folder (generated by Apache Ivy)
I've very recently begun working with Ant as my primary buildtool, and have been enjoying it so much that I really would rather stick with it for a while. The only frustrating issue I've run into is ...
2
votes
0
answers
310
views
Error: Cannot query the value of this provider because it has no value available when running react-native run-android
I am encountering an issue while trying to run my React Native application on Android using the command:
react-native run-android
The build fails with the following error:
Could not determine the ...
1
vote
2
answers
273
views
Unable to import com.sun.tools.javac.util.Pair
I'm new to java and currently using open-jdk and javac 21 and Eclipse IDE.
I'm trying to import om.sun.tools.javac.util.Pair and getting the error -
"The type com.sun.tools.javac.util.Pair is not ...
0
votes
0
answers
116
views
Error: class file for okio.ByteString not found
I am attempting to compile a program using the following command line:
javac -cp .:json-20210307.jar:okhttp-4.11.0.jar:okio-3.5.0.jar:kotlin-stdlib-1.9.0.jar RebootDevice.java
I get the following ...
2
votes
0
answers
137
views
Is it possible to use the Java 17 compiler to compile a Java Applet that calls netscape.javascript.JSObject.getWindow()?
I know applets are no longer formally supported. I have some legacy code that can still run using IE 11/Edge in compatibility mode. I can also run applets in any browser using Webswing.
My applets ...
1
vote
3
answers
485
views
Flutter error: Execution failed for task ':app:compileDebugJavaWithJavac
I encountered this problem after updating android studio. None of my apps build in android studio:
Launching lib/flavors/main_dev.dart on sdk gphone arm64 in debug mode...
Warning: This version only ...
1
vote
1
answer
1k
views
Frustrating IntelliJ build failure - JCTree$JCImport does not have member field JCTree qualid
I am building a Spring Boot project in IntelliJ, and getting a build error:
"com.sun.tools.javac.JCTree$JCImport does not have member field JCTree qualid"
I have no references to that class ...
1
vote
0
answers
153
views
How can I improve the performance of my ANTLR4 generated Parser(for java grammar, in C++)?
The antlr4 version is the latest, at the time of posting, 4.13.2, compiled from source.
I am using the java8-grammar provided by the grammars-v4 antlr repo
I intend to parse large projects for static ...
-1
votes
1
answer
107
views
Why can't my class be run after declaring package and be found by another class in the same package/folder?
I am having problems understanding how packages work. Not using any IDE.
I have the following folder structure:
~/dropbox/api/data
Inside the data folder, there are (only) Producer.java, Consumer.java....
2
votes
0
answers
79
views
Javac thinks a lambda may actually be an instance of a class, "ambiguous call". Why? [duplicate]
Why can the Java compiler not compile this?
private ButtonGroup groupButtons(AbstractButton... buttons) {
return groupButtons(() -> new ButtonGroup(), buttons);
}
private <BG extends ...
-1
votes
1
answer
76
views
How to solve the issue resulting in output of the error message "class not found wrong class name"? [duplicate]
I have the following Java code in a file:
package hello_project;
public class Hello {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
The ...
-4
votes
1
answer
84
views
Why does using lambda break definite assignment in Java?
Attempting to compile the following code with java-1.21.0-openjdk-amd64 results in these errors
.../TransactionProfile.java:[60,22] variable emvData might already have been assigned
.../...
0
votes
0
answers
56
views
Using com.sun classes without --add-opens
I am making a lib that modifies the AST with an annotation handler for parameter injection (src: http://github.com/PhoenixOrigin/DependencyInjector). Right now, all users are required to include
...
0
votes
1
answer
55
views
Issue with javac makefile
I have an issue with the makefile I am doing using java. So:
./bin/fp2/poo/utilidades/TitularInterfaz.class:
./bin/fp2/poo/utilidades/CodigoPostalInterfaz.class \
...
1
vote
1
answer
319
views
How to compile a Java class with javac without any dependencies even on the base classes like java.lang.*?
I want to "recreate" J2ME / CLDC with a recent version of javac (e.g. 11.0.19) and compile a purposely built Java program without any or minimal base classes. Obviously classes like java....
0
votes
0
answers
125
views
No openjdk development package found, please install JDK package,
I have my java installed and linked.
Still when I run another config it shows no openjdk development package found. Although I have java installed and linked using a pre built release
pegasus@pegasus:...
2
votes
1
answer
378
views
Is there a way to separate Java annotation processing errors from other compilation errors?
I have a maven module with 1000+ Java source files. Some of these have annotations that are processed via processors Dagger and Immutables, each of which generates code. When I have an error in a ...
1
vote
2
answers
108
views
Java compiler throws 'might not have been initialized' error incorrectly?
Here's a sample method:
boolean method(int value, boolean check1, boolean check2) {
String code;
boolean valueIncorrect = false;
boolean otherIncorrect = false;
if (value < 0 || ...
3
votes
0
answers
142
views
How tu suppress warnings issued by javac task
Recent version of Moshi (1.15.0) is issuing a warning
Kapt support in Moshi Kotlin Code Gen is deprecated and will be removed in 2.0. Please migrate to KSP. https://github.com/square/moshi#codegen&...
2
votes
0
answers
109
views
Strange Compiler Error with Collectors.toMap() : reference to method is ambiguous, both Map and List match
This class doesn't compile (using javac 17 or 21), because the second invocation of set() is allegedly ambiguous, while the first one is OK:
import java.util.HashMap;
import java.util.List;
import ...
0
votes
1
answer
921
views
How to specify Java version in VS Code?
I have created a virtual machine to run some java code in it and have specified the VM to run with java 11
ubuntu@go-v12as34df:~$ java -version
openjdk version "11.0.21" 2023-10-17
OpenJDK ...
1
vote
0
answers
61
views
How to disable "constant folding" in java compilation with javac? [duplicate]
I have the following Java code:
public class App{
public int sum(){
return (1 + 2) + (3 + 4);
}
}
After compiling it using javac App.java and inspecting the bytecode with javap -v App, I ...
1
vote
2
answers
103
views
How does java compile source code to bytecode when there are multiple class files?
I learning java. I want understand how this compilation process is done.
Imagining how java compiler would compile is simple when there is one file. It would compile line by line. How about having ...
-2
votes
1
answer
84
views
Java println string not showing up in CMD [closed]
I am trying to execute the simple java application in CMD using javac but the outputs of System.out.println is not coming out.
Let me show you my code in my MyFirstProgram java file.
public class ...
0
votes
1
answer
106
views
Problem when trying to execute a java file after compiling with UTF8 encoding
i am currently trying to run a java file in the terminal inside the corresponding package, which i created in eclipse (so its not the default package). However, the problem began after i tried to ...
0
votes
1
answer
450
views
Gitlab-runner maven build fails with Permission denied message BUT succeeds with debug option on
I'm trying to build a Java project with maven image with Gitlab-runner.
There was no issue until yesterday, I encountered the error below saying that
"Permission is denied".
This is the ...
3
votes
2
answers
781
views
Why is the maximum string literal length in Java 65534?
I compiled this code. (use javac 21.0.1)
public static final String MAX = "AAAAA ...";
If I repeat 'A' 65534 times in a literal, the compilation is OK.
But if I repeat 'A' 65535 times in a ...
0
votes
0
answers
36
views
How could I add and image to a JLabel, when the image is in a parent directory in Java?
Using java
Lets pretend we are in folder "src". The parent directory contains folders "src", "assets" and "bin".
Since I am in the folder "src", how ...
-1
votes
1
answer
518
views
Command Line shows only jdk 20 version of java, not others [closed]
I want to see the list of all jdk versions available in my system. However, when I type in java and javac version to the cmd line, it gives me only jdk 20 version. How can I do an implementation to ...
-3
votes
1
answer
101
views
NULL as an eighth 'primitive' data type [closed]
A mindless query arising from Java's less known data type 'null'.
Would somebody be able to clarify whether or not 'null' is a literal reserved by the Java language and thus the disparity between it ...
0
votes
0
answers
39
views
Why javac adds clone-method and how java separates and links methods with same signature? [duplicate]
Let's look at the following example.
public class T1 implements Cloneable {
private T1(T1 g) {}
public T1 clone() { return new T1(this); }
}
There are two clone methods in a bytecode.
$ ...
0
votes
0
answers
99
views
How to modify java bytecode after compilation using compiler plugins?
I want to modify some java classes bytecode during/after compilation phase, but before packaging, in order to use custom invokedynamic bootstrap methods.
In order to do so, I have written a Java ...
0
votes
0
answers
42
views
Which gcc O2 option do this constant folding?
I am not familiar with gcc,this code:
int a=145;int b=267+a;
printf("%d/n",b);
if comiple with no optimize option,will use the "addl" command,but if open O2 option,it will show me ...
0
votes
0
answers
188
views
How to make javac to ignore "unmappable character for encoding UTF-8" error (offending char is in comments)
I am compiling some legacy java code using plain javac. The OS is linux and JDK level is:
java version "1.8.0_361"
Java(TM) SE Runtime Environment (build 8.0.8.0 - pxa6480sr8-20230314_01(...
2
votes
1
answer
2k
views
Java Default Encoding
Is it still necessary on Windows to add the -encoding UTF-8 parameter to the Java Compiler, when using German Umlaut ß in sources?
I thought that UTF-8 is the default for Java, isn't it?
class Main {
...
2
votes
1
answer
162
views
How to trigger an error/warning immediately upon compile/run if an item on my class-path is missing
I have a very simple source file -- HelloWorld.java
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("hello world");
}
}
I have the ...
0
votes
1
answer
83
views
what happens between static and dynamic polymorphism [closed]
can't really find the proper answer.
if we have:
1.Animal cat = new Cat();
2.Animal animal = new Animal();
Animal and Cat both has method makeSound();
1.as I understand early binding in Java happens ...
0
votes
0
answers
232
views
Could not find or load main class "Name of class" in VSCode
When I use the java/javac command on cmd as in
javac Theory/HelloWorld.java
java Theory.HelloWorld
it works just fine, yet when I do that on the VSCode terminal it doesn't work at all and says "...
0
votes
1
answer
50
views
Unchecked warnings of java compiler does not occur in some cases
Consider this very simple generic class:
class GenericTest<T> {
T t;
GenericTest(T t) {
this.t = t;
}
}
I created multiple objects of this class, one of them is raw type:
...