Latest Questions

Get Answers to Your Coding Questions

92
Votes
Published 11 Sep, 2022
Java - GraphQL implementation Java

I am having 5 rest API's(java) with different endpoint URL,and each have different request,response format.So I have combined them as a single API with a common JSON complex request and response as a...

38
Votes
Published 25 Aug, 2022
Java - Surround string with another string

I there any utils method in Java that would enable me to surround a string with another string? Something like: surround("hello","%"); which would return "%hello%" I need just one method so the co...

22
Votes
Published 20 Aug, 2022
Java - Checking if file is completely written

Currently I'm working on the project that does processing files from source directory in one of it's routines. There's a Java process that's looking for specified directory and tries to read and proce...

24
Votes
Published 19 Sep, 2022
Java - Connecting to Heroku Postgres from Spring Boot

I'm looking for the simplest, cleanest way of connecting to Heroku Postgres in a Spring Boot app using JPA/Hibernate. I don't see a good, complete example for this combo in either Heroku or Spring Bo...

16
Votes
Published 29 Aug, 2022
Java - Waiting for a function to finish execution and using the results

Here's the scenario I have an activity(A) which has a button and textview. I have another class(B) with methods for performing various functions. After creating an instance of class B, one of it's pu...

59
Votes
Published 09 Sep, 2022
Java - JFreeChart BarChart -> NO gradient

my bar chart is always drawn with a gradient color by default. I just want a simple color without any styled effects. Can anyone help ? Code: final JFreeChart chart = ChartFactory.createBarChart...

64
Votes
Published 19 Sep, 2022
Java - java.lang.IndexOutOfBoundsException: setSpan (N ... N) ends beyond length 10500

I get this exception when I call EditText.setSelection() java.lang.IndexOutOfBoundsException: setSpan (N ... N) ends beyond length 10500 N can be any number. For example if I call setSelection(1047...

34
Votes
Published 03 Sep, 2022
Java - How to get cpu usage using java?

I would like to get cpu usage to update my database using java continuously. At the first loop, this code is readable the correct cpu usage. After then, it returns wrong values less than 0. So, I stuc...

31
Votes
Published 21 Aug, 2022
Java - How to make CXF generated code to unmarshal into JAX-B and ignore unmapped fields?

I call a web-service which can periodically add some element in their contract. Example: the SOAP response body contains: <picture> <active>true</active> <code>172&lt...

92
Votes
Published 02 Sep, 2022
Java - JavaFX: FXML: How to make the child to extend its size to fit the parent pane?

I have managed to load a child fxml(sub UI) under a parent fxml (mainMenu UI). I have created an AnchorPane with id "mainContent". This pane is bound to 4 sides and changes in accords to the stage....

190
Votes
Published 21 Aug, 2022
Java - Execute method on startup in Spring

Is there any Spring 3 feature to execute some methods when the application starts for the first time? I know that I can do the trick of setting a method with @Scheduled annotation and it executes just...

54
Votes
Published 15 Sep, 2022
Java - Spring-Boot How to properly inject javax.validation.Validator

I've got a problem injecting the Validator into the spring application bean when attempting to validate a model using JSR-303 (hibernate-validator) My main configuration class is: @EnableAutoConfig...

94
Votes
Published 14 Sep, 2022
Java - How to change default spring profil ("cloud") in cloud foundry

I want to launch my spring-boot application after a cf push with a custom profile named my_profile, but the app is always launched with the default one cloud profile. How can I specify the exact profi...

7
Votes
Published 25 Aug, 2022
Java - Maven: How to include jars in Eclipse, which are not available in repository?

I have copied the JARs into src\main\webapp\WEB-INF\lib. I use eclipse. If I add the jars one-by-one to Project-> Java Build Path-> Add jars, then I do Project-> Maven-> Update Project Configuration,...

11
Votes
Published 09 Sep, 2022
Java - Maven and eclipse: a reliable way to add non-Maven or external jars to a project?

Maven is great. It mostly keeps me out of jar dependency hell by specifying versions of dependent packages in the pom configuration, and applies them automatically. It also has great integration with...

91
Votes
Published 06 Sep, 2022
Java - Define an exception called "NO Match Exception" that is thrown when a string is not equal to "India"

In the problem I have to check whether a string is equal to "India" or not. If they are not equal then I have to throw an exception "No Match Exception" I am creating a class nomatchexception and fro...

86
Votes
Published 19 Sep, 2022
Java - Java Collections (LIFO Structure)

I am looking in the Collections framework of Java for a LIFO Structure (Stack) without any success. Basically I want a really simple stack; my perfect option would be a Deque, but I am in Java 1.5. I...

82
Votes
Published 02 Sep, 2022
Java - Overriding the java equals() method - not working?

I ran into an interesting (and very frustrating) issue with the equals() method today which caused what I thought to be a well tested class to crash and cause a bug that took me a very long time to tr...

136
Votes
Published 24 Aug, 2022
Java - Should I recommend sealing classes by default?

In a big project I work for, I am considering recommending other programmers to always seal their classes if they haven't considered how their classes should be subclassed. Often times, less-experienc...

76
Votes
Published 01 Sep, 2022
Java - Nested objects have not been saved by Spring JpaRepository

I have a Spring Roo application with GWT. On server-side I´ve got simple JpaRepository interfaces for all entities like: @Repository public interface MyEntityRepository extends JpaSpecificationExecut...

69
Votes
Published 01 Sep, 2022
Java - Why is Queue.poll faster than Iteration? (java.util.concurrent.ConcurrentLinkedQueue)

I have a piece of code that gets all the elements from a queue. I do not care about the state of the queue afterwards and I can be assured the queue will not be modified while I am removing the eleme...

70
Votes
Published 27 Aug, 2022
Java - SearchView.OnCloseListener does not get invoked

Im using an action bar and adding a searchView to it. I have implemented the searchView.onCLoseListener but this does not seem to be getting invoked. Any suggestions ? My code looks something like th...

64
Votes
Published 05 Sep, 2022
Java - can not read file from linux system using java

I am trying to read/write files on Ubuntu 12.04. I set permission of that directory by chmod -R 777 . But still when I call canRead() method on that directory it returns false. my directory is /root/...

87
Votes
Published 15 Sep, 2022
Java - How do I wait for multiple Mono's to complete at once and get the value

Similar in question to Waiting for running Reactor Mono instances to complete but I want to get the result ideally in another Mono. Here's the code I have. I tried the materialize solution but that...

31
Votes
Published 02 Sep, 2022
Java - Jackson How to retrieve parent bean in a custom Serializer/Deserializer

In a custom serializer/deserializer, is there a way to retrieve the parent bean of the field? For example: public class Foo { @JsonSerialize(using = MyCustomSerializer.class) public Bar bar...

19
Votes
Published 22 Aug, 2022
Java - build-helper-maven-plugin adding additional source

I am trying to add an additional source folder to my current maven project by using build-helper-maven plugin. This source folder contains some common classes, like utility classes. For that, here is...

42
Votes
Published 03 Sep, 2022
Java - Map Custom JdbcTemplate query result in an Object

I new in java and try to use spring framework. I have a question. By example, I have table : employee (id_employee, name) employee_product (id_employee_product, id_employee, product_name) if I s...

75
Votes
Published 01 Sep, 2022
Java - How to assert that some String contains at least one value from the List <String>?

I'm testing some UI functionality with Java and AssertJ. So when I receive some massive string from UI, I should verify if that String contains at least one predefined value from List&lt;String&gt;. I...

63
Votes
Published 09 Sep, 2022
Java - Why am I getting extra text nodes as child nodes of root node?

I want to print the child elements of the root node. This is my XML file. &lt;?xml version="1.0"?&gt; &lt;!-- Comment--&gt; &lt;company&gt; &lt;staff id="1001"&gt; &lt;firstname&gt;yong&lt;...

23
Votes
Published 01 Sep, 2022
Java - JsonObject Build Stackoverflow error

I am trying to build a jsonobject to be send with a post request. But instead i get the error as shown below: 03-02 13:54:50.340: E/AndroidRuntime(2862): FATAL EXCEPTION: main 03-02 13:54:50.340: E/A...