New answers tagged java
Score of 0
0
votes
JUnit Test cases failing after upgrading to Gradle 9, Springboot 4 and Java 25
I was able to resolve the issue by adding the below under my dependencyManagement section
dependencyManagement {
applyMavenExclusions = false <-- this fixed it
imports {
mavenBom &...
Score of 0
0
votes
Using Prometheus to monitor Spring Boot Applications in Kubernetes Cluster
Prometheus + Grafana is a natural fit if Kubernetes is already the deployment model and you need cluster-wide monitoring.
But for a relatively small deployment, it may be worth questioning whether the ...
Score of 0
0
votes
Best practice for setter in a bidirectional self-referencing relationship
To use getters and setters in a self-referenced JPA (Java Persistence API) entity, you map the relationship back to the same class type. This is commonly used for hierarchical data structures.
@Entity
...
Score of -1
-1
votes
JUnit Test cases failing after upgrading to Gradle 9, Springboot 4 and Java 25
The error
java.lang.NoClassDefFoundError: org/springframework/http/HttpStatusCode
occurs when your runtime application attempts to load the HttpStatusCode interface, but cannot find it in the ...
Score of -1
-1
votes
What is the optimized regex to match the email pattern in java
The slowdown is mainly caused by backtracking. With a very long string that doesn’t contain a valid email, the regex engine can end up trying many different ways to match the repeated parts before ...
Score of 1
1
vote
Extra non-character or empty character or absence is getting printed at the end of target string being matched by regex pattern using find() in java
Issue : the last output its giving extra line with an empty character where string is already matched till last character at index 42 , its printing unnecessary printing extra index of 43 , any ...
Score of 0
0
votes
JUnit Test cases failing after upgrading to Gradle 9, Springboot 4 and Java 25
Change spring-boot-starter-web to spring-boot-starter-webmvc.
Use spring-boot-starter-webmvc-test for the tests for MVC.
Execute
-./gradlew dependencyInsight --dependency spring-web --configuration ...
Score of 0
0
votes
Extra non-character or empty character or absence is getting printed at the end of target string being matched by regex pattern using find() in java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String regex = "((\\d\\d\\d\\d)(\\w\\w\\w)(\\W\\W))";...
Score of 0
0
votes
Best practice for setter in a bidirectional self-referencing relationship
In a bidirectional relationship, I would keep both sides of the relationship synchronized. Instead of allowing setParent() to update only the parent field, I would use methods such as addChild() and ...
Score of 0
0
votes
JUnit Test cases failing after upgrading to Gradle 9, Springboot 4 and Java 25
This is probably due to changes in the web dependency of Spring Boot 4. Use spring-boot-starter-webmvc instead of spring-boot-starter-web and spring-boot-starter-webmvc-test for MVC tests. Next, ...
Score of -1
-1
votes
FileNotFound exception in Java/Clojure interop
This error occurs in Clojure development when the Clojure runtime cannot find your Listening namespace on the classpath. It usually means there is a mismatch between your folder structure, file name, ...
Score of -1
-1
votes
MBT build fails during personal vector setup
It might be helpful to run mvn clean package separately first, and then run MBT on the built package to avoid MBT timing out while waiting on maven
Score of 3
3
votes
How to set JDK character coding to windows-1252?
To read a text file with ANSI character encoding in Java, you should specify the Windows-1252 (or ISO-8859-1) character set explicitly. If you use txt files in Windows and text editors like Notepad, &...
Score of 1
1
vote
FileNotFound exception in Java/Clojure interop
The ns creation in your Clojure code is wrong. Use :import to add mappings to Java classes; :require is used to refer to other Clojure namespaces. See https://clojuredocs.org/clojure.core/ns
(ns ...
Score of 5
5
votes
How to set JDK character coding to windows-1252?
FileReader reader = new FileReader(filename);
If you have a 'method banlist', put that one on the list. You should never invoke that one.
Whenever anything converts text to bytes or vice versa, a ...
Score of 3
3
votes
Accepted
How to understand and implement "get each worker tools" and then "get tools" in my Stream API test task for Java developer?
In your example you are doing steps 3.2 and 3.3 in a single stream operation. What you were asked was doing them in two separate operations. The end result was correct, but the way the task was ...
Score of -1
-1
votes
Is temporarily overriding equals method possible?
Direct Answer to your question: it's not easily possible to "override" equals method in Java, However, there is way to achieve what you want. Here is what we can do:
User class:
public class ...
Score of 1
1
vote
Accepted
SQS messages sent with delay are intermittently failed
Ah shoot, I found the problem: because my function sends those wakeup messages back to itself, it eventually triggers a recursive loop detection feature in AWS. The message was showing up on the ...
Score of 0
0
votes
Change the System Brightness Programmatically
This is very similar to the kotlin answer by rtsketo, but this creates a stand-alone function instead of an extension function.
/**
* Set brightness of the screen (window) of this app.
*
* @param ...
Score of 1
1
vote
JDBC typed getters throw ArrayIndexOutOfBoundsException for the tree-model Time column in Apache IoTDB
Which getter is intended to be portable for that column when code relies on ResultSetMetaData rather than knowing IoTDB's result layout in advance?
You can always use ResultSet::getString() if you ...
Score of 1
1
vote
How do you check if the proxy in Windows Proxy Settings is on?
there is one very straightforward way to check this:
public class Main {
public static void main(String[] args) {
if(System.getProperty("http.proxyHost") != null) {
...
Score of 1
1
vote
Cannot send input after starting communication
Correct way to do it is:
import java.util.Scanner;
public class A {
public static void main(String[] args) {
System.out.print("Input value for x: ");
Scanner scanner = ...
Score of 0
0
votes
Regrading Wildfly Console Management connection with Wildfly 37/39
This looks like a WildFly 37+ Aesh/JANSI compatibility regression specific to Windows CMD. The NoSuchMethodError breaks terminal input, which explains why the SSL certificate prompt hangs, while Linux ...
Score of 0
0
votes
Getting "A Java agent has been loaded dynamically" warning in IntelliJ after upgrading Java 17 to 21
That worked for me in my java project that uses gradle:
build.gradle file
configurations {
mockitoAgent
}
dependencies {
mockitoAgent("org.mockito:mockito-core") { transitive = ...
Score of 5
5
votes
How to make this stream gatherer threadsafe?
So I am trying to understand how thread safety works with parallel stream
For this, you should consult the API docs for the java.util.stream package, to which Gatherer belongs. Your initializer, ...
Score of 4
4
votes
How to make this stream gatherer threadsafe?
Is my understanding correct or is the stream framework internally synchronizes access to the state objects while performing combiner and finisher operations?
This is closest to the truth. Explicit ...
Score of 3
3
votes
Accepted
A NoClassDefError occurs when loading soft dependencies in an MC Bukkit plugin
I think this may because using the method reference requires loading MethodProvider to construct the MethodProvider::new method reference and when that class is loaded, the verifier has to check ...
Score of 0
0
votes
Zebra SDK execption RFID_API_COMMAND_TIMEOUT when trying to reconnect
The RFID_API_COMMAND_TIMEOUT error may also be caused by Zebra DataWedge working in background. Disabling (reconfiguring) DataWedge may require Android restart
Score of 8
8
votes
I need to make Java Swing Timer more accurate
Your variable naming is terrible, making your code hard to follow. Primary example: speeds express progress per unit time, but what your code labels as "speeds" have units of time per ...
Score of 0
0
votes
Draw formatted text with libgdx
Years later, we have the TextraTypist library (https://github.com/tommyettinger/textratypist), which does a lot of stuff (probably more than you need) including italics/bold and scaling.
Score of 3
3
votes
Jena API for retrieving Classes, Individuals, Properties, and Annotations in Jena 6.2.0
Jena 3.15.0 was released 2020-05-15.
Jena now has a replacement for the org.apache.jena.ontology code.
It is in the module jena-ontapi.
The root of the code package is org.apache.jena.ontapi
...
Score of 3
3
votes
Hive 3.1.3 fails with ClassCastException on Java 17
This error occurs because you are running an older application (Hive) or library built for Java 8 (or earlier) on Java 9 or higher. In Java 8 and below, the system class loader (ClassLoader....
Score of 0
0
votes
alfresco custom action for secure timestamp - error using BouncyCastle
I've had similar errors with BouncyCastle before, and in my case they were usually caused by another dependency bringing in a different version of BouncyCastle transitively.
Different BouncyCastle ...
Score of -1
-1
votes
Household Appliances Scheduling Project using Genetic Algorithm in Java
I think the main issue is the chromosome representation.
For one appliance, an int[48] works fine because you have 48 time slots.
But you have 3 appliances, so you need either an int[3][48] or a ...
Score of 0
0
votes
Accepted
Time limit exceeded in Strings Rotations of Each Other
indexOf searches starting from the start of the String, whilst lastIndexOf starts the search from the end. See here and here. So, if s2.equals(s1.substring(n) + s.substring(0, n)), then, if n is 1, ...
Score of 14
14
votes
Why is Collectors.collect not able to infer the types in this stream pipeline?
The following code compiles and runs fine:
List<String> letters = Arrays.asList("a", "b", "c", "d");
letters.stream().gather(
Gatherer....
Score of 4
4
votes
Accepted
JSON Serializing java.sql.Time, java.sql.Date, and java.sql.Timestamp with minimal allocation
You can drop both GregorianCalendars and get true zero-allocation extraction with pure integer math, the same epoch-day algorithm java.time.LocalDate uses internally (Hinnant's civil_from_days):
...
Score of 0
0
votes
Intermittent latency at java.io.RandomAccessFile.open0 while Tomcat classloading?
I doubt that is somehow tomcat-related at all. You are correct that `RandomAccessFile.open0` call is not something we would expect to find in threaddumps - this call is relatively cheap, unless it ...
Score of 9
9
votes
Why is Collectors.collect not able to infer the types in this stream pipeline?
The "obstacle" for the compiler to match the correct types in your example is the lambda. It does not specify its input types and Gatherer is declared with unlimited type parameters, so that ...
Score of 0
0
votes
Accepted
Return type overloading in Java and abstract inheritance
Method Inference by Return Type?
Your first question is reasonably discussed in the answers to this question. The problem is pretty trivial and can be discussed further if you have further questions.
...
Score of 0
0
votes
HackerRank Task "Mini Max Sum" solution not passing 3 of the 13 test cases
I understand the question is "why my code doesn't work", but to be fair, I think it creates a lot of unnecessary complexity (tracking min and max values).
You can simply use lambdas to sort (...
Score of 0
0
votes
javax.xml.ws.WebServiceException when invoking WSDL service
The problem is that your generated client is still trying to connect to localhost:8080:
http://localhost:8080/kestrel/SystemService
The 404 Not Found means that the server was reached, but the ...
Score of 2
2
votes
How to configure RestClient timeout in Spring Boot 4?
Finally found an example in the Spring Boot IO docs that shows how to use ClientHttpRequestFactory to apply the settings explicitly:
If you need to apply other customization in addition to an SSL ...
Score of 0
0
votes
Rounded Swing JButton using Java
Since the borders were not filled correctly, I used @override:
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
final Color bgColor = c....
Score of 0
0
votes
How to map a C function to Java Native Method using JavaCpp
It would look something like this:
import org.bytedeco.javacpp.annotation.*;
@Platform(
include = "mylib.h",
link = "mylib"
)
public class MyLib {
static {
...
Score of 0
0
votes
Recording System Audio via Java
You need to open a TargetDataLine. Open it with AudioSystem.getTargetDataLine, not TargetDataLine.open().
Here is a full example:
import java.util.Scanner;
import java.io.ByteArrayInputStream;
import ...
Score of 0
0
votes
How to map a C function to Java Native Method using JavaCpp
There are no problems to use JavaCPP for building a bridge for C library. All C functions will be placed in one global Java class.
Score of 3
3
votes
Accepted
How to make icon show with jpackage if in AppData
When you use jpackage, the images represented by --icon parameter (assuming the file is a valid icon format) are encoded into the EXE file. It should not matter at all whether you have used --win-per-...
Score of 1
1
vote
Read zip in zip for updating
In-Place ZIP Modification
The format of a ZIP file does not really support modifying entries in-place. There are some strategies that could work for random access readers, but those same strategies ...
Score of 0
0
votes
Model context protocol
Traffic monitoring should be responsibility of the http/api gateway, not your Java application. For Streaming HTTP MCP server implementation you may also try Tachyon if you want to support the latest ...
Top 50 recent answers are included
Related Tags
java × 1915063android × 280793
spring × 130657
swing × 79709
spring-boot × 78484
eclipse × 59281
hibernate × 59259
arrays × 52303
maven × 48783
multithreading × 39524
json × 39187
xml × 36402
selenium-webdriver × 35468
string × 32697
spring-mvc × 32347
jpa × 31808
mysql × 30476
jsp × 27057
arraylist × 26399
javafx × 25026
tomcat × 23577
regex × 23526
android-studio × 23016
servlets × 22982
jdbc × 22554