Latest Questions

Get Answers to Your Coding Questions

36
Votes
Published 18 Sep, 2022
Java - Finding the median value of an array?

I was wondering if it was possible to find the median value of an array? For example, suppose I have an array of size nine. Would it possible to find the middle slot of this array?

40
Votes
Published 06 Sep, 2022
Java - Calling flush() in @Transactional method in Spring Boot application

Is it possible that calling Hibernate flush() in the middle of @Transactional method will save incomplete results in the database? For example, is it possible that this function could save "John" to t...

44
Votes
Published 03 Sep, 2022
Java - Android Studio can't delete files when compiling

When I compile my app in order to run it on the emulator, Android Studio (version 3.0 RC2) complains because it can't delete the 1.jar file inside my project folder. Here is the error message: Error...

100
Votes
Published 02 Sep, 2022
Java - Clojure/Java: Java libraries for spectrum analysis of sound?

I am looking for a library that can accept a chunk of audio data and return the average amplitude over time within a given frequency band. I've already asked this question over at comp.dsp, but it's...

55
Votes
Published 07 Sep, 2022
Java - back commandbutton in jsf

how would one implement a back-button as a commandbutton that works universally? with back button i don't mean the browser-button, but rather a button that sits somewhere on the page. it is not always...

22
Votes
Published 19 Sep, 2022
Java - Deploying my application at the root in Tomcat

I have the war file of my application. I need to deploy this at the root level. The current URL is http://localhost:8080/war_name/application_name.

68
Votes
Published 16 Sep, 2022
Java - Multipart file maximum size configuration in Tomcat 8

My application server is Tomcat and I need is to upload files (large size) to my application. The body size of POST requests is really long like 15 MB or more. Is there any type of configuration or...

18
Votes
Published 11 Sep, 2022
Java - LinkedHashMap LIFO or FIFO?

Is LinkedHashMap LIFO or FIFO in nature? If my map is of the form: map.put(1,"one"); map.put(2,"two"); what would be the order if I was to iterate on the map using keyset?? EDIT: I think I did act...

56
Votes
Published 15 Sep, 2022
Java - Spring Boot - infinite loop service

I want to build a headless application which will query the DB in infinite loop and perform some operations in certain conditions (e.g. fetch records with specific values and when found launch e-mail...

92
Votes
Published 19 Sep, 2022
Java - POST InputStream with RestTemplate

I have a client that needs to POST a large number of large json files to a server. I've been able to get it working by reading each of the files into memory and posting the entire file with RestTempla...

22
Votes
Published 12 Sep, 2022
Java - Why are my fields initialized to null or to the default value of zero when I've declared and initialized them in my class' constructor?

This is meant to be a canonical question and answer for similar questions where the issue is a result of shadowing. I've defined two fields in my class, one of a reference type and one of a primiti...

97
Votes
Published 04 Sep, 2022
Java - Java implementation of C# SignedCms

I am working on an implementation of C# SignedCms functionality in Java. I am using bouncycastle libs. The problem is I get java signature that is different from the one generated with SignedCms....

84
Votes
Published 02 Sep, 2022
Java - How do I turn a String into a InputStreamReader in java?

How can I transform a String value into an InputStreamReader?

20
Votes
Published 18 Sep, 2022
Java - How do I use multiple consumers in Kafka?

I am a new student studying Kafka and I've run into some fundamental issues with understanding multiple consumers that articles, documentations, etc. have not been too helpful with so far. One thing...

98
Votes
Published 06 Sep, 2022
Java - Remove white space and special characters in java

I have String which contains some special characters and white spaces as well.I want to remove white spaces and special character I am doing it as String str = "45,%$^ Sharma%$&^,is,46&* a$#...

74
Votes
Published 15 Sep, 2022
Java - Calculating Manhattan Distance

I'm implementing NxN puzzels in Java 2D array int[][] state. am required to use the Manhattan heuristic in the following way: the sum of the vertical and horizontal distances from...

69
Votes
Published 16 Sep, 2022
Java - How to undo/reset PowerMockito.mockStatic?

Assuming I have the following classes public class StaticClass { public static void staticMethod() throws SomeException { System.out.println("staticMethod"); } private StaticCla...

47
Votes
Published 26 Aug, 2022
Java - BeanDefinitionRegistryPostProcessor - How to register a @Configuration class as BeanDefinition and get its @Beans registered as well

Let's suppose I have this @Configuration class: @Configuration public class SomeConfig{ @Bean public MyBean myBean(){ return new MyBean(); } @Bean public Another anoth...

95
Votes
Published 19 Sep, 2022
Java - Datagram Transport Layer Security (DTLS) on Android/Java

Has anyone used DTLS on Android or is there an open source Java implementation that supports DTLS? What are my other options for securing UDP traffic on Android?

74
Votes
Published 26 Aug, 2022
Java - Assigning a null value to an int

If the following code is possible: Integer a = null; int b = a; Does it mean that a function returning a possible null value for an integer is a bad practice? Edit 1: There are several different o...

28
Votes
Published 20 Aug, 2022
Java - Sum two arrays element-by-element in Java

What is the easiest way to sum two arrays element-by-element? I know that you can use a for loop such as the following: int[] a = {0, 1, 2}; int[] b = {3, 4, 5}; int[] c = new int[a.length]; for (in...

55
Votes
Published 16 Sep, 2022
Java - Spring Boot RestTemplate List

I get a response like this: { "data":[ { "object1":"example", "object2":"example", "object3":"example", "object4":"example", "object5":"exa...

86
Votes
Published 03 Sep, 2022
Java - Convert java.util.Date to String

I want to convert a java.util.Date object to a String in Java. The format is 2010-05-30 22:15:52

60
Votes
Published 03 Sep, 2022
Java - Hibernate transaction not successfully started

Consider this simple Hibernate scenario: session = getHibernateSession(); tx = session.beginTransaction(); SomeObject o = (SomeObject) session.get(SomeObject.class, objectId); tx.commit(); This cod...

63
Votes
Published 23 Aug, 2022
Java - "Records" preview feature in IntelliJ 2020.1 with Java 14 fails with compiler error during Maven `install`, but runs otherwise

I am trying to use the JEP 359: Records (Preview) feature in Java with IntelliJ 2020.1.1 RC. I defined a class like this: package work.basil.example; import java.time.LocalTime; public record LocalT...

48
Votes
Published 20 Aug, 2022
Java - Setting timeouts in Spring Rest Template

Application is using Spring rest template to call a webservice and i am using restTemplate.exchage(url) to call the webservice. Currently we are not passing any timeout value for this webservi...

63
Votes
Published 23 Aug, 2022
Java - Copy with clipboard manager that supports old and new android versions?

I'm trying to copy text programatically on android, the most voted answer on another question provided these lines but when using them I get error: Class requires API level 11 (current min is 8): Cli...

52
Votes
Published 23 Aug, 2022
Java - How to execute button by clicking on another button java?

menuBar = new JMenuBar(); // File Menu JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); // File->New JMenuItem newMenuItem = new JMenuItem("New"); frame.setJMenuBar(menuBar); newMenuItem....

67
Votes
Published 19 Sep, 2022
Java - Why is it possible to declare a variable without an initial value?

I'm reading Gilles Dowek's Principles of Programming Languanges: He says that it's also possible to declare a variable without giving it an initial value and also that we must be careful not to use a...

22
Votes
Published 23 Aug, 2022
Java - How to view all implementors of a given interface in NetBeans for Java?

I'm trying to evaluate NetBeans, being a veteran Eclipse user. In Eclipse I could press F4, and I would a class hierarchy for a given class or Interface. For example - show me all the classes that imp...