Stack Overflow » Java
905 FOLLOWERS
Ask all your Java-related questions here and find quality solutions & suggestions. Stack Overflow is the largest, most trusted online community for developers to learn, share their programming knowledge and build their careers.
Stack Overflow » Java
5m ago
I've created an MCTS algorithm for a game; it works so now I want to optimize it. One simple way to do so is simulating not once, but multiple times in parallel to use the entire CPU and get more accurate results. For this purpose I created a method that just calls the simulate method multiple times, waits till the simulations are done and returns all the winners. For calling the tasks I use ExecutorService with a fixed thread pool. Sadly it seems that creating the tasks takes quite a long time, more than 3-4 times the time to simulate once, making multithreadding not viable in my domain. Now ..read more
Stack Overflow » Java
5m ago
I am writing a term paper for the university. The task is to write two programs, one of which collects some information, signs it with a digital key, and saves the encrypted data and the key to separate files. The next program collects the same information, reads the encrypted data and keys, and verifies the digital signature.
Step number two is to write an agent that uses java.lang.instrument.Instrumentation; and possibly third-party libraries such as javaassist to do bytecode substitution so that the program always gives a successful verification result
I tried to implement this with the hel ..read more
Stack Overflow » Java
5m ago
I'm creating a REST API and i wanna create dynamic queries (e.g generate a SQL query based on a object and yours properties, ignoring null properties) for my routes, what is the best way to approach this?
I heard about query by example, but he couldn't deal with nested objects (e.g a user that have a address object, that have a street, so on). How to create a fluent solution for this without need create for every entity a query using Criteria with a lot of ifs to ignore null properties and do right joins, etc ..read more
Stack Overflow » Java
5m ago
I'm having troubles. In my project, I need this line in build.gradle in order for one folder in my project to be imported correctly:
dependencies {
implementation project(':cachetool')
}
However, when I run the application, I get:
Circular dependency between the following tasks:
:cachetool:classes
\--- :cachetool:compileJava
+--- :cachetool:compileKotlin
| \--- :cachetool:jar
| +--- :cachetool:classes (*)
| +--- :cachetool:compileKotlin (*)
| \--- :cachetool:inspectClassesForKotlinIC
| +--- :cachetool:classe ..read more
Stack Overflow » Java
5m ago
I have a block of code like follows:
@Nullable SomeUrn someUrn = Optional.ofNullable(somePage)
.map(somePage::someEntity)
.map(entity -> {
if(entity.isMember()) {
return entity.getMember();
} else {
LOG.error("Expected a member but received " + entity);
return null;
}})
.orElse(null);
Is there a better way to handle the error case in Java 8?
I tried
.map(entity ->
Optional.ofNullable(entity)
.map(ent -> ent.getMember())
.orElseGet(() -> {
LOG.error("Expe ..read more
Stack Overflow » Java
1h ago
My directory structure: java\codes\yash.java
My code is below:
package codes;
public class yash {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
I got error below:
Error: Could not find or load main class yash Caused by: java.lang.NoClassDefFoundError: codes/yash (wrong name: yash)
I tried by keeping yash.java file in java directory instead of code directory where I didn't need to add package in the yash.java file and it worked.
But with the above approach its not working ..read more
Stack Overflow » Java
1h ago
In my application, I need to pick these (sfa, sfb, fbx, obj) specific files which I have saved before, from the file manager in an Android device across different providers
I tried this
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
//intent.putExtra("CONTENT_TYPE", "*/*");
activityResultLauncher.launch(intent);
but it always opens like this, I don't see any file manager here
If anyone knows how to do this with these file formats (sfa, sfb, fbx, o ..read more
Stack Overflow » Java
1h ago
I have created a cutom tag key and associated value for a particular instance in GCP compute engine. How i can update/delete the tag key by programatically by using google compute engine sdk in java?
Can someone guide me how i can do this? Please provide sample code if possible ..read more
Stack Overflow » Java
1h ago
We want to use @Cacheable in Spring Boot with redis, and we want the redis content to be JSON so it is human readable.
This is done in our CacheConfiguration with
@Autowired
public CacheConfiguration(ObjectMapper objectMapper) {
// we need to modify the default objectMapper for redis so make a copy
this.objectMapper = objectMapper.copy()
.activateDefaultTyping(
objectMapper.getPolymorphicTypeValidator(),
ObjectMapper.DefaultTyping.NON_FINAL,
JsonTypeInfo.As.PROPERTY
);
}
@Bean
public RedisCacheManagerBuilderCustomizer redisCache ..read more
Stack Overflow » Java
1h ago
I have a Spring Boot Java application that exchanges data with an external API using a Feign client. This API only accepts data encoded in Windows-1251 for non-Latin characters. I have configured my Feign client to send the data, and it works fine when it consists of Latin characters only. However, when I need to transfer mixed data, it encodes using Percent Encoding.
Here is an example: The string parameter I need to transfer: Тест The Windows-1251 and then Percent Encoding representation of that string (the desired option): %D2%E5%F1%F2 The Percent Encoding representation of that string only ..read more