Most viewed questions in Java

0 votes
1 answer

Removing whitespace from strings in Java

st.replaceAll("\\s+","") removes all whitespaces and non-visible characters (e.g., ...READ MORE

Dec 30, 2020 in Java by Gitika
• 65,910 points
4,914 views
0 votes
0 answers

Exception in thread "main" java.lang.Error: Unresolved compilation problems

I am facing issues importing classes and ...READ MORE

May 7, 2022 in Java by narikkadan
• 63,420 points
4,898 views
0 votes
2 answers

Ho do I Iterate through a HashMap which contains duplicate values

for (Map.Entry<String, String> item : params.entrySet()) { ...READ MORE

Jul 24, 2018 in Java by samarth295
• 2,220 points
4,846 views
0 votes
1 answer

What is the simplest way to read JSON from a URL in java

Read json from url use url.openStream() and read contents ...READ MORE

Jun 13, 2018 in Java by samarth295
• 2,220 points
4,837 views
0 votes
2 answers

How an object array can be converted to string array in java?

System.arraycopy is the most efficient way, but ...READ MORE

Aug 8, 2018 in Java by Sushmita
• 6,910 points
4,787 views
0 votes
1 answer

How do I resolve the "java.net.BindException: Address already in use: JVM_Bind" error?

If you are aware about what port ...READ MORE

Feb 22, 2022 in Java by Aditya
• 7,680 points
4,725 views
0 votes
1 answer

How to pass an object from one activity to another on Android

One option could be letting your custom ...READ MORE

Jun 25, 2018 in Java by Rishabh
• 3,620 points
4,666 views
0 votes
2 answers

How can we add leading zeros to the number in Java?

From Java 1.5 you can use the String.format method. ...READ MORE

Aug 26, 2019 in Java by Sirajul
• 59,230 points
4,657 views
0 votes
2 answers

Does Java thread.sleep() puts swing ui to sleep?

You are correct about the code putting ...READ MORE

Oct 24, 2018 in Java by Sushmita
• 6,910 points
4,626 views
0 votes
2 answers

How to log SQL statements in Spring Boot?

HI.. try using this in your properties file: logging.level.org. ...READ MORE

Sep 25, 2020 in Java by SRI

edited Sep 25, 2020 by Sirajul 4,579 views
0 votes
3 answers

How to read input from Console using Scanner Class?

A simple example: import java.util.Scanner; public class Expl { ...READ MORE

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

What is the difference between hashset and treeset?

HashSet vs TreeSet: 1- Hashset gives better performance (faster) ...READ MORE

Jun 20, 2018 in Java by Akrati
• 3,190 points
4,557 views
0 votes
0 answers

How to store and fetch nested json data from dynamodb in java

I want to maintain a book library. ...READ MORE

Sep 7, 2020 in Java by saswat
• 120 points

edited Sep 7, 2020 by Gitika 4,543 views
0 votes
1 answer

Abstract class provides partial abstraction. How?

An Abstract class in java may have ...READ MORE

Jun 25, 2019 in Java by Sirajul
• 59,230 points
4,532 views
0 votes
1 answer

How to prevent java.lang.NumberFormatException in Java?

"N/A" is not integer. It must throw NumberFormatException if you ...READ MORE

Jun 26, 2018 in Java by sharth
• 3,370 points
4,475 views
+1 vote
1 answer

concat() vs “+” operator : In Java for String concatenation

Basically, there are two important differences between ...READ MORE

Apr 27, 2018 in Java by Rishabh
• 3,620 points
4,472 views
0 votes
1 answer

get a class instance of generics type T

The short answer is, that there is ...READ MORE

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

Converting a date string to a DateTime object using Joda Time library

Use DateTimeFormat: DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss"); DateTime dt = ...READ MORE

Jul 24, 2018 in Java by scarlett
• 1,290 points
4,458 views
+1 vote
1 answer

Error: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2

Hello @Jino, It is just a JVM bug ...READ MORE

Nov 21, 2018 in Java by Nabarupa
4,421 views
0 votes
1 answer

Unable to find valid certification path to requested target - error even after cert imported

Unfortunately - it could be many things ...READ MORE

Nov 27, 2018 in Java by Daisy
• 8,120 points
4,399 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,327 views
0 votes
1 answer

Purpose of “String args[]” in the “psvm” of Java

Let me give you the complete explanation ...READ MORE

May 7, 2018 in Java by code.reaper12
• 3,500 points
4,286 views
0 votes
1 answer

java.lang.OutOfMemoryError: GC overhead limit exceeded Error

This simply means that for some reason ...READ MORE

May 31, 2018 in Java by misc.edu04
• 1,450 points
4,282 views
0 votes
2 answers

Performing HTTP POST operation in JAVA

I'm using JSON-Java to build my JSON object: JSONObject json ...READ MORE

Nov 26, 2018 in Java by Sushmita
• 6,910 points
4,262 views
0 votes
0 answers

Trying to avoid detection using selenium chrome driver (Java)

I am trying to do an automated ...READ MORE

Jul 14, 2020 in Java by laiman
• 330 points
4,254 views
0 votes
3 answers

Increment the date in Java by 1-day

import java.time.LocalDate; public class DateIncrementer { static ...READ MORE

Aug 1, 2018 in Java by Akrati
• 3,190 points
4,247 views
0 votes
1 answer

Why clone() method is protected in Java?

The clone() is protected because it is ...READ MORE

Nov 13, 2018 in Java by geek.erkami
• 2,680 points
4,240 views
0 votes
1 answer

jQuery.click() vs onClick

So, using a string that is tied ...READ MORE

May 30, 2022 in Java by gaurav
• 23,260 points
4,238 views
0 votes
1 answer

Access method without creating Object

This is not possible in java. You ...READ MORE

Feb 7, 2019 in Java by Dheeraj
4,223 views
0 votes
2 answers

One line initialization of an ArrayList object in Java

In Java 8 or earlier: List<String> string = ...READ MORE

Jul 26, 2018 in Java by samarth295
• 2,220 points
4,186 views
0 votes
2 answers

“Could not find or load main class” mean?

Use the final modifier to enforce good initialization. Avoid returning ...READ MORE

Sep 18, 2018 in Java by Sushmita
• 6,910 points
4,181 views
0 votes
2 answers

Is there a SortedList in Java?

Since all lists are already "sorted" by ...READ MORE

Nov 2, 2018 in Java by Sushmita
• 6,910 points
4,171 views
0 votes
2 answers

Splitting a string between letters and digits

Using Python: https://stackoverflow.com/a/63936955/8117673 READ MORE

Sep 17, 2020 in Java by Himanshu
4,148 views
0 votes
0 answers

create multiple excel sheets.xlsx based on each iteration

Prob : I have a method executeunixcommand ...READ MORE

Jul 14, 2020 in Java by Jyra
• 580 points
4,144 views
0 votes
2 answers

How can I Copy files from one directory to another in Java

Java 8 Path sourcepath = Paths.get("C:\\data\\temp\\mydir"); ...READ MORE

Aug 10, 2018 in Java by samarth295
• 2,220 points
4,137 views
0 votes
2 answers

Result of character addition in Java

Binary arithmetic operations on char and byte ...READ MORE

Aug 22, 2019 in Java by Sirajul
• 59,230 points
4,116 views
0 votes
1 answer

How to automatically deploy a jar from s3 to aws lambda?

You could probably create a lambda function ...READ MORE

Apr 2, 2020 in Java by Jake
4,095 views
0 votes
1 answer

Does Java have a "IN" operator or function like SQL? [duplicate]

The Java language is designed to be ...READ MORE

Feb 2, 2022 in Java by Vaani
• 7,020 points

edited Jun 22, 2023 by Khan Sarfaraz 4,087 views
0 votes
1 answer

Start script missing error when running npm start

It seems that there is an undefined ...READ MORE

Feb 10, 2022 in Java by Soham
• 9,700 points
4,084 views
0 votes
1 answer

Method for escaping HTML in Java

242 StringEscapeUtils from Apache Commons Lang: import static org.apache.commons.lang.StringEscapeUtils.escapeHtml; // ... String source ...READ MORE

Jan 9, 2019 in Java by developer_1
• 3,320 points
4,056 views
0 votes
1 answer

How to read an XML file using XPath in Java?

Import the packages required to work with ...READ MORE

Jun 14, 2018 in Java by Akrati
• 3,190 points
3,971 views
0 votes
1 answer

Remove duplicates from an ArrayList in Java

Here is the function for doing this. // ...READ MORE

Mar 6, 2019 in Java by Heena
3,966 views
0 votes
1 answer

Java and MySql: Check if database exists

You can get the list of databases ...READ MORE

Aug 27, 2019 in Java by Kunal
3,949 views
0 votes
1 answer

How to determine day of week by passing specific date?

You can use java.util.Calendar: Calendar c = Calendar.getInstance(); c.setTime(yourDate); int dayOfWeek ...READ MORE

Oct 30, 2018 in Java by Daisy
• 8,120 points
3,942 views
0 votes
1 answer

How to resolve 'Must Override a Superclass Method' Errors after importing a project into Eclipse ?

Eclipse is defaulting to Java 1.5 and ...READ MORE

Jan 10, 2019 in Java by developer_1
• 3,320 points
3,930 views
+1 vote
2 answers

Factorial of a number using while loop

import java.util.*; public class Fact { ...READ MORE

Mar 19, 2020 in Java by leela
• 140 points
3,907 views
0 votes
1 answer

Angular JS Uncaught Error: [$injector:modulerr]

 The answer to your question is simple ...READ MORE

Feb 18, 2022 in Java by Aditya
• 7,680 points
3,875 views
0 votes
1 answer

Error:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

Hello @kartik, Include servlet-api-3.1.jar in your dependencies. Maven <dependency> ...READ MORE

Jun 3, 2020 in Java by Niroj
• 82,880 points
3,864 views
0 votes
1 answer

Can we convert a string to hexadecimal in java

I find this to be an easy ...READ MORE

Jul 4, 2018 in Java by Akrati
• 3,190 points
3,861 views
0 votes
0 answers

Clickable span not calling javascript even though w3school example works

I have a clickable span element that ...READ MORE

Apr 13, 2022 in Java by Rahul
• 3,380 points
3,847 views