Most answered questions in Java

0 votes
1 answer

Escaping strings in JSON

You can find a JSON library in your ...READ MORE

Oct 4, 2018 in Java by geek.erkami
• 2,680 points
23,808 views
0 votes
1 answer

How do you produce a double in Java

double num = 5; When you do this, ...READ MORE

Oct 4, 2018 in Java by anto.trigg4
• 3,440 points
579 views
0 votes
1 answer

How to Read/Write String from a File in Android

Writing a File in android: private void writeToFile(String ...READ MORE

Oct 3, 2018 in Java by sharth
• 3,370 points
6,970 views
0 votes
1 answer

Non-static method within Static method in Java

As per my knowledge, you are getting this error ...READ MORE

Sep 28, 2018 in Java by anto.trigg4
• 3,440 points
1,039 views
0 votes
1 answer

System.exit() method in Java

System.exit() is a method of System class ...READ MORE

Sep 28, 2018 in Java by code.reaper12
• 3,500 points
1,277 views
0 votes
1 answer

“Missing return statement” within if / for / while in Java

Putting a return statement in any of the ...READ MORE

Sep 27, 2018 in Java by code.reaper12
• 3,500 points
8,690 views
0 votes
1 answer

Find Oracle JDBC driver in Maven repository

Download the jar and place it in ...READ MORE

Sep 26, 2018 in Java by Daisy
• 8,120 points
2,965 views
0 votes
1 answer

What is the best Java email address validation method?

Apache Commons is generally known as a ...READ MORE

Sep 26, 2018 in Java by Parth
• 4,630 points
551 views
0 votes
1 answer

Calling remove in foreach loop in Java

To safely remove from a collection while ...READ MORE

Sep 26, 2018 in Java by sharth
• 3,370 points
8,610 views
0 votes
1 answer

Using Jackson to deserialise an array of object

First create a mapper : import com.fasterxml.jackson.databind.ObjectMapper;// in ...READ MORE

Sep 26, 2018 in Java by Sushmita
• 6,910 points
4,948 views
0 votes
1 answer

How to convert a string representation of a hex dump to a byte array using Java?

public static byte[] hexStringToByteArray(String s) { ...READ MORE

Sep 26, 2018 in Java by sharth
• 3,370 points
1,674 views
0 votes
1 answer

object references an unsaved transient instance - save the transient instance before flushing

You should add cascade="all" (if using xml) ...READ MORE

Sep 26, 2018 in Java by Parth
• 4,630 points
34,304 views
0 votes
1 answer

How can we get the current location in Android?

First you need to define a LocationListener to handle ...READ MORE

Sep 25, 2018 in Java by Parth
• 4,630 points
746 views
0 votes
1 answer

Increasing the JVM memory using command line

You can adjust your JVM memory needs by ...READ MORE

Sep 25, 2018 in Java by geek.erkami
• 2,680 points
459 views
0 votes
1 answer

Unescaping HTML character entities in Java

I guess you can use this function: StringEscapeUtils.unescapeH ...READ MORE

Sep 25, 2018 in Java by anto.trigg4
• 3,440 points
387 views
0 votes
1 answer

notify() vs. notifyAll() in Java

notify() is used to wake any thread in the wait ...READ MORE

Sep 20, 2018 in Java by code.reaper12
• 3,500 points
1,766 views
0 votes
1 answer

Fetching screen resolution using Java

You can fetch the screen resolution using the Toolkit.getScreenSize() method ...READ MORE

Sep 20, 2018 in Java by anto.trigg4
• 3,440 points
4,310 views
0 votes
1 answer

revalidate() vs repaint() in Java Swing

You need to call repaint() and revalidate() both in order ...READ MORE

Sep 20, 2018 in Java by code.reaper12
• 3,500 points
10,204 views
0 votes
1 answer

Array indexOf() in Java

You can use this indexOf() method through Arrays utility class. If the ...READ MORE

Sep 20, 2018 in Java by geek.erkami
• 2,680 points
2,662 views
0 votes
1 answer

Various Advice in Spring AOP

Below are the various advices available in AOP: Before: These types ...READ MORE

Sep 12, 2018 in Java by geek.erkami
• 2,680 points
1,115 views
0 votes
1 answer

@RequestMapping annotation in Java Spring

The @RequestMapping annotation in Spring Framework is ...READ MORE

Sep 12, 2018 in Java by code.reaper12
• 3,500 points
3,267 views
0 votes
1 answer

Spring AOP vs AspectJ AOP

Well, below I have listed down few ...READ MORE

Sep 10, 2018 in Java by v.liyyah
• 1,300 points
1,167 views
0 votes
1 answer

@Qualifier annotation in Spring Framework

When you create more than one bean ...READ MORE

Sep 10, 2018 in Java by code.reaper12
• 3,500 points
1,546 views
0 votes
1 answer

Executing commands with parameters in Java

Try using the below command: Runtime.getRuntime().exec(new String[]{"php","/var/www/script.php", "-m", ...READ MORE

Sep 5, 2018 in Java by geek.erkami
• 2,680 points
2,706 views
0 votes
1 answer

Java anonymous code blocks

The anonymous code blocks in Java are ...READ MORE

Sep 5, 2018 in Java by anto.trigg4
• 3,440 points
1,421 views
0 votes
1 answer

How to download a file from spring controllers?

@RequestMapping(value = "/files/{file_name}", method = RequestMethod.GET) public void ...READ MORE

Sep 4, 2018 in Java by code.reaper12
• 3,500 points
2,602 views
0 votes
1 answer

SuppressWarnings (“unchecked”) in Java

@SuppressWarnings("unchecked") is used when Java generics just don't ...READ MORE

Sep 4, 2018 in Java by anto.trigg4
• 3,440 points
8,347 views
0 votes
1 answer

Bean life cycle in Spring Bean Factory Container

Bean life cycle in Spring Bean Factory ...READ MORE

Aug 30, 2018 in Java by code.reaper12
• 3,500 points
2,838 views
0 votes
1 answer

Add jars to maven 2 build class path without installing them?

wn voteA quick&dirty batch solution (based on Alex's answer): libs.bat @ECHO ...READ MORE

Aug 30, 2018 in Java by samarth295
• 2,220 points
947 views
0 votes
1 answer

Constructor injection vs Setter injection in Spring Framework

Here, I have listed down few differences. ...READ MORE

Aug 30, 2018 in Java by anto.trigg4
• 3,440 points
2,990 views
0 votes
1 answer

Generate UML diagrams from Java code?

You could also give the netbeans UML ...READ MORE

Aug 30, 2018 in Java by samarth295
• 2,220 points
847 views
0 votes
1 answer

How to calculate the interval between 2 dates

The following code might be helpful: public static ...READ MORE

Aug 29, 2018 in Java by bug_seeker
• 15,520 points
683 views
0 votes
1 answer

Enums be subclassed to add new elements?

I suggest you take the other way ...READ MORE

Aug 29, 2018 in Java by Parth
• 4,630 points
462 views
0 votes
1 answer

Simple HTTP server in Java using only Java SE API

You can write a pretty simple embedded Jetty Java ...READ MORE

Aug 29, 2018 in Java by Parth
• 4,630 points
1,644 views
+1 vote
1 answer

How do I do a HTTP GET?

If you don't want to use external ...READ MORE

Aug 28, 2018 in Java by Neha
• 6,300 points
435 views
0 votes
1 answer

How to create a temporary directory/folder in java?

If you are using JDK 7 use ...READ MORE

Aug 28, 2018 in Java by Frankie
• 9,830 points
6,095 views
+1 vote
1 answer

How to calculate days between two dates?

You are making some conversions with your ...READ MORE

Aug 28, 2018 in Java by Frankie
• 9,830 points
2,604 views
0 votes
1 answer

Spring configuration file

A Spring configuration file is an XML ...READ MORE

Aug 28, 2018 in Java by v.liyyah
• 1,300 points
6,114 views
0 votes
1 answer

Types of IOC containers in Spring Framework

There are basically two types of IOC ...READ MORE

Aug 28, 2018 in Java by misc.edu04
• 1,450 points
25,231 views
0 votes
1 answer

Retrieve a file from a server via SFTP

Below is an example using Apache Common ...READ MORE

Aug 28, 2018 in Java by samarth295
• 2,220 points
678 views
0 votes
1 answer

Why is the Scanner skipping nextLine() after using next() or nextFoo()

public static void main(String[] args) { ...READ MORE

Aug 28, 2018 in Java by samarth295
• 2,220 points
1,427 views
0 votes
1 answer

What are the Foreign key constraints in Android using SQLite

You can use, Foreign key constraints with ...READ MORE

Aug 24, 2018 in Java by geek.erkami
• 2,680 points
1,548 views
0 votes
1 answer

Removing an Integer from a List<Integer> in Java

In Java, the method best suiting your argument ...READ MORE

Aug 24, 2018 in Java by anonymous
1,302 views
0 votes
1 answer

Double decimal formatting in Java

Using String.format, you can do this: double price ...READ MORE

Aug 23, 2018 in Java by Parth
• 4,630 points
398 views
0 votes
1 answer

How to replace 2 or more spaces with a single space in String and how to delete leading and trailing spaces?

before=" Hello world "; String after ...READ MORE

Aug 22, 2018 in Java by Parth
• 4,630 points
539 views
0 votes
1 answer

Why Java String class is declared as final?

String class is made final in Java ...READ MORE

Aug 22, 2018 in Java by code.reaper12
• 3,500 points
5,401 views
0 votes
1 answer

Iterable.forEach() vs foreach loop

The advantage comes into account when the ...READ MORE

Aug 21, 2018 in Java by Parth
• 4,630 points
574 views
0 votes
1 answer

Replace String with another in java

String s = "HelloSuresh"; s = s.replace("Hello",""); System.out.pri ...READ MORE

Aug 21, 2018 in Java by Parth
• 4,630 points
621 views
0 votes
1 answer

How to count the number of occurrences of an element in a List?

We can use the static frequency() method. int ...READ MORE

Aug 21, 2018 in Java by sharth
• 3,370 points
5,306 views
0 votes
1 answer

Gracefully stopping a java thread

The preferable way will be to use a ...READ MORE

Aug 21, 2018 in Java by anto.trigg4
• 3,440 points
1,019 views