Trending questions in Java

0 votes
1 answer

What does NaN mean in Java?

"NaN" stands for "not a number". "Nan" ...READ MORE

Jul 12, 2018 in Java by Akrati
• 960 points
1,750 views
0 votes
2 answers

How can I sort values of a Map in Java using its key

Assuming TreeMap is not good for you ...READ MORE

Oct 10, 2018 in Java by Sushmita
• 6,910 points
957 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

Jul 25, 2018 in Java by samarth295
• 2,220 points
3,206 views
0 votes
2 answers

How do I use a Priority Queue

Use the constructor overload which takes a Comparator<? ...READ MORE

Oct 10, 2018 in Java by Sushmita
• 6,910 points
792 views
+1 vote
1 answer

How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

This error means you're trying to load ...READ MORE

Jun 8, 2018 in Java by Rishabh
• 3,620 points
2,975 views
0 votes
2 answers

How can I get the filenames of all files in a folder which may or may not contain duplicates

List<String> results = new ArrayList<String>(); File[] files = ...READ MORE

Sep 12, 2018 in Java by Sushmita
• 6,910 points
1,672 views
0 votes
3 answers

How can we use java.String.format in Scala?

String aString = "world"; int aInt = 20; String.format("Hello, ...READ MORE

Aug 29, 2018 in Java by Daisy
• 8,120 points
1,350 views
0 votes
2 answers

Can the size of dynamic array be changed?

import java.util.List; import java.util.ArrayList; import java.util.Random; public class A ...READ MORE

Aug 31, 2018 in Java by Sushmita
• 6,910 points
999 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,318 views
0 votes
1 answer

@Component vs @Repository vs @Service in Spring Framework

As you might be knowing, all these ...READ MORE

May 29, 2018 in Java by geek.erkami
• 2,680 points
3,358 views
+4 votes
3 answers

What are the steps to set Java_home on Windows?

Set Java Home JAVA_HOME = C:\Program Files\Java\jdk1.7.0 [Location ...READ MORE

Sep 18, 2018 in Java by Sushmita
• 6,910 points
1,707 views
0 votes
1 answer

How to pretty print XML from Java?

Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); //initialize StreamResult ...READ MORE

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

How can I calculate number of days between two dates?

You may refer this. This might work ...READ MORE

Jul 19, 2018 in Java by Akrati
• 3,190 points
1,056 views
0 votes
3 answers

How to convert File to Byte[] in Java?

import java.io.File; import java.nio.file.Files; File file; // ...(file is initialised)... byte[] ...READ MORE

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

Multiple return statements in Java

Yes, you have guessed it right. Language ...READ MORE

Jun 28, 2018 in Java by geek.erkami
• 2,680 points
1,979 views
0 votes
2 answers

How a static map can be initialized?

public class Test { ...READ MORE

Sep 12, 2018 in Java by Sushmita
• 6,910 points
865 views
0 votes
2 answers

Can we catch multiple exceptions in the same catch clause in Java?

In Java 6 and before versions, we ...READ MORE

Aug 10, 2018 in Java by sharth
• 3,370 points
1,218 views
0 votes
1 answer

What is Classpath in java?

Classpath is a parameter in the Java virtual machine or ...READ MORE

Jun 5, 2018 in Java by Daisy
• 8,120 points
2,873 views
0 votes
2 answers

Performing Iteration over each entry in a 'Map'

In Java 8 you can do it ...READ MORE

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

What is null in java?

"null" is a reference type and its ...READ MORE

Jul 31, 2018 in Java by Mrunal
• 680 points
704 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,497 views
0 votes
1 answer

How to use wait() and notify() concept in producer consumer situation

In this program, we have two threads ...READ MORE

Jul 20, 2018 in Java by Kalgi
• 52,360 points
907 views
0 votes
1 answer

Get parameters from the URL with JSP

To delete the subject record with its ...READ MORE

May 29, 2018 in Java by Parth
• 4,630 points
3,164 views
+1 vote
3 answers

Copy Java Array and make a duplicate of it

int[] a = {1,2,3,4,5}; int[] b = Arrays.copyOf(a, ...READ MORE

Aug 30, 2018 in Java by Sushmita
• 6,910 points
1,405 views
0 votes
1 answer

How can we import javax.servlet API in Eclipse?

Before installing Eclipse, ensure that you are ...READ MORE

Jun 7, 2018 in Java by Parth
• 4,630 points
2,696 views
0 votes
1 answer

Why there is the need of getters and setters in java

In Java getters and setters are completely ...READ MORE

Jun 26, 2018 in Java by scarlett
• 1,290 points
1,803 views
0 votes
1 answer

While using next() or nextfoo() , the upcoming nextLine() is skipped by scanner

That's because the Scanner.nextInt method does not ...READ MORE

Jun 6, 2018 in Java by mitto
• 160 points
2,656 views
0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

Jul 26, 2018 in Java by samarth295
• 2,220 points
2,612 views
0 votes
1 answer

Convert Milliseconds to “X mins, x seconds” in Java?

I wrote a function which converts milliseconds ...READ MORE

May 30, 2018 in Java by Rishabh
• 3,620 points
2,893 views
0 votes
3 answers

Adding text to a file using Java

try { final Path ...READ MORE

Sep 6, 2018 in Java by Sushmita
• 6,910 points
1,135 views
0 votes
2 answers

How to break the nested loop in Java?

You can use break with a label for the ...READ MORE

Sep 20, 2018 in Java by Sushmita
• 6,910 points
980 views
0 votes
1 answer

How can we run the .jar file by double clicking on windows 7 (64)?

Use the following method to run the ...READ MORE

Jun 28, 2018 in Java by sharth
• 3,370 points
1,606 views
0 votes
1 answer

Examples of GoF Design Patterns in Java's core libraries

Observer pattern throughout whole swing (Observable, Observer) MVC also ...READ MORE

Jun 27, 2018 in Java by developer_1
• 3,320 points
1,631 views
0 votes
1 answer

What is the difference between static and inner class?

An inner class, cannot be static, so ...READ MORE

Jul 11, 2018 in Java by sophia
• 1,400 points
1,026 views
0 votes
2 answers

Does Java allow to create static classes?

Java has "static nested classes", but they ...READ MORE

Sep 5, 2018 in Java by Sushmita
• 6,910 points
948 views
0 votes
2 answers

How to concatenate two arrays in Java?

public <T> T[] concatenate(T[] a, T[] b) ...READ MORE

Jul 19, 2018 in Java by Sushmita
• 6,910 points
2,466 views
0 votes
1 answer

Behavior of Integer Wrapper class and == operator

Well, this is happening because of the ...READ MORE

Jun 7, 2018 in Java by v.liyyah
• 1,300 points
2,458 views
0 votes
1 answer

Difference between JSF, Servlet and JSP?

Servlet - it's java server side layer. JSP ...READ MORE

Jul 3, 2018 in Java by samarth295
• 2,220 points
1,324 views
0 votes
2 answers

Does the finally block always execute in Java?

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

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

Running Command Line in Java

You may refer this: Runtime rt = Runtime.getRuntime(); Process ...READ MORE

Jul 20, 2018 in Java by Akrati
• 960 points
558 views
0 votes
1 answer

How can we split a comma separated String in Java?

String str = "..."; // write the ...READ MORE

Jun 12, 2018 in Java by Parth
• 4,630 points
2,169 views
0 votes
1 answer

Check whether the string is palindrome or not?

You may refer the below code: public static ...READ MORE

Jul 11, 2018 in Java by Akrati
• 3,190 points
910 views
0 votes
2 answers

How to round up a value to 2 decimal places?

double d = 2.34568; DecimalFormat f = new ...READ MORE

Aug 30, 2018 in Java by Sushmita
• 6,910 points
1,095 views
0 votes
3 answers

String to Double conversion in java

Double temp = Double.valueOf(str); number = temp.doubleValue(); READ MORE

Sep 10, 2018 in Java by Sushmita
• 6,910 points
1,388 views
0 votes
3 answers

How to check whether a string is empty or not? Is there a function for this?

str != null && str.length() != 0 alternatively str ...READ MORE

Sep 11, 2018 in Java by Sushmita
• 6,910 points
1,066 views
0 votes
1 answer

What is the use of serialVersionUID ?

The docs for java.io.Serializable are probably about as good ...READ MORE

Jun 21, 2018 in Java by Rishabh
• 3,620 points
1,718 views
–1 vote
1 answer

What is the difference between oracle JDK and open JDK

Both OpenJDK and Oracle JDK are created ...READ MORE

Jul 10, 2018 in Java by Akrati
• 3,190 points
936 views
0 votes
1 answer

What are the practical uses for AtomicInteger?

There are two main uses of AtomicInteger: As an ...READ MORE

Jul 18, 2018 in Java by Akrati
• 960 points
514 views
0 votes
1 answer

Iterating through a Collection, avoiding ConcurrentModificationException when removing in loop

You can either use the iterator directly ...READ MORE

Jul 3, 2018 in Java by Rishabh
• 3,620 points
1,158 views
0 votes
1 answer

How can we convert Strings to and from UTF8 byte arrays?

To convert STring to byte[]: String s = ...READ MORE

Jun 21, 2018 in Java by Akrati
• 3,190 points
1,629 views