Most viewed questions in Java

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
849 views
0 votes
1 answer

Serializing a lambda

With the release of Java 8, Oracle introduced the ...READ MORE

Nov 16, 2018 in Java by code.reaper12
• 3,500 points
847 views
0 votes
4 answers

How to convert a char to a String?

There are two ways you can do ...READ MORE

Dec 29, 2020 in Java by Roshni
• 10,520 points
842 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
842 views
0 votes
1 answer

What is JNI?

Java native interface, it is an interface ...READ MORE

Mar 7, 2019 in Java by Priyaj
• 58,090 points
839 views
0 votes
2 answers

How to read the files using Java?

You can use collections. try (Stream<Path> filePathStream=Files.walk(Paths.get("/home/you/Desktop"))) { ...READ MORE

Jul 10, 2018 in Java by Sushmita
• 6,910 points
838 views
0 votes
2 answers

How to test that an array contains a certain value?

public static final String[] VALUES = new ...READ MORE

Jul 17, 2018 in Java by Sushmita
• 6,910 points
833 views
0 votes
1 answer

What are the differences between a HashMap and a Hashtable in Java?

There are several differences between HashMap and Hashtable in Java: Hashtable is synchronized, whereas HashMap is ...READ MORE

Dec 21, 2020 in Java by Gitika
• 65,910 points
832 views
0 votes
2 answers

Understand working of String Builder and String Buffer

Basically, StringBuffer methods are synchronized while StringBuilder ...READ MORE

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

How to force garbage collection in Java?

Your best option is to call System.gc() which simply ...READ MORE

Nov 15, 2018 in Java by Frankie
• 9,830 points
829 views
0 votes
0 answers

Generate pdf from HTML in div using Javascript

I have the following HTML code: <!DOCTYPE html> <html> ...READ MORE

Dec 9, 2022 in Java by Nicholas
• 7,760 points
827 views
0 votes
1 answer

Hibernate show real SQL

If you want to see the SQL ...READ MORE

Jul 5, 2018 in Java by Sushmita
• 6,910 points
827 views
+1 vote
1 answer

How can we resolve java.lang.OutOfMemoryError in Java?

Work with smaller batches of HashMap Objects ...READ MORE

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

What is the equivalent of the C++ Pair<L,R> in Java?

In a thread on comp.lang.java.help, Hunter Gratzner ...READ MORE

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

What is Modeshape. How can i use this?

ModeShape is an open-source implementation of the JSR-283 specification and ...READ MORE

Mar 30, 2020 in Java by Gitika
• 65,910 points
820 views
0 votes
1 answer

Why java have transient fields?

Variables may be marked transient to indicate that they ...READ MORE

May 28, 2018 in Java by Daisy
• 8,120 points
819 views
0 votes
1 answer

What is the 'instanceof' operator used for in Java?

It's an operator that returns true if ...READ MORE

May 23, 2018 in Java by Rishabh
• 3,620 points
819 views
0 votes
1 answer

Extend an array after initialization

Here is the method I came up ...READ MORE

Mar 11, 2019 in Java by Esha Gupta
808 views
0 votes
1 answer

How to pad string in Java?

Padding to 10 characters: String.format("%10s", "foo").replace(' ', '*'); String.format("%-10s", ...READ MORE

May 1, 2018 in Java by Rishabh
• 3,620 points
807 views
0 votes
1 answer

Android Studio installation on Windows 7 fails, no JDK found

Adding a system variable JDK_HOME with value ...READ MORE

Dec 13, 2018 in Java by Daisy
• 8,120 points
805 views
0 votes
1 answer

How does contains() method work in evaluating objects?

Generally you should also override hashCode() each time you ...READ MORE

May 25, 2018 in Java by Rishabh
• 3,620 points
804 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
804 views
0 votes
2 answers

How can I split the String with any whitespace character as delimiter?

String string = "Today's weather"; String[] arrayOfString = ...READ MORE

Aug 23, 2019 in Java by Sirajul
• 59,230 points
803 views
0 votes
2 answers

How to convert an array to arraylist?

In Java 9 you can use: List<String> list= List.of("Hello", "World", ...READ MORE

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

How can I compare two integers properly?

Hi Divya, I hope this code snippet will ...READ MORE

May 31, 2019 in Java by sampriti
• 1,120 points
800 views
0 votes
0 answers

How can I fix 'android.os.NetworkOnMainThreadException'?

When I run the Android project for ...READ MORE

May 23, 2022 in Java by Kichu
• 19,050 points
799 views
0 votes
0 answers

How can I find the prime factors of an integer in JavaScript?

Using a for loop in javascript, I was attempting to determine the prime factors of a number, denoted as 'integer' below.  I can't seem to get it to work, and I'm not sure if it's because of my JavaScript or my calculating logic. //integer is the value for which we ...READ MORE

Dec 12, 2022 in Java by Nicholas
• 7,760 points
797 views
0 votes
2 answers

How to get input from user using System.console()?

Scanner in = new Scanner(System.in); int i = ...READ MORE

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

How to create text labels in Swing, Java?

In the frame, you can use the ...READ MORE

Aug 27, 2019 in Java by Jimmy
789 views
0 votes
1 answer

What is the difference == and equals() in Java?

Both the answers (Syntaxes) are correct. If ...READ MORE

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

What do you mean by object serialization ?

To serialize an object means to convert its state ...READ MORE

Jun 14, 2018 in Java by scarlett
• 1,290 points
787 views
0 votes
1 answer

Does a 32-bit byte code work in 64-bit JVM?

Yes, Java bytecode (and source code) is ...READ MORE

Jun 5, 2018 in Java by sophia
• 1,400 points
785 views
0 votes
1 answer

Why doesn't RecyclerView have onItemClickListener()?

I like this way and I'm using ...READ MORE

Dec 21, 2018 in Java by Daisy
• 8,120 points
782 views
0 votes
2 answers

When I am running eclispe on my computer it is throwing error. How to resolve it?

If you have downloaded the 64 bit ...READ MORE

Dec 10, 2018 in Java by Sushmita
• 6,910 points
775 views
0 votes
1 answer

What is ArrayIndexOutOfBoundsException ?

If You check System.out.print(names.length); you will get 3 ...READ MORE

May 11, 2018 in Java by sharth
• 3,370 points
775 views
0 votes
1 answer

Access restriction on class error

My guess is that you are trying ...READ MORE

Jun 21, 2018 in Java by Rishabh
• 3,620 points
774 views
0 votes
1 answer

How to initialize multi-dimensional array in java?

A multidimensional array in Java is really an array ...READ MORE

Jun 6, 2018 in Java by sophia
• 1,400 points
774 views
0 votes
2 answers

How to read a text file in Java?

You can use Scanner class to read ...READ MORE

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

How to reverse an int array in Java?

for(int i = 0; i < Data.length ...READ MORE

May 11, 2018 in Java by Akrati
• 3,190 points
768 views
0 votes
1 answer

How to calculate the difference between two date instances in Java?

You can use Joda Time Library. Interval i ...READ MORE

May 4, 2018 in Java by Parth
• 4,630 points
767 views
0 votes
1 answer

Sort a Map<Key, Value> by values

This might help solve your problem...!!!! public class ...READ MORE

Apr 18, 2018 in Java by Rishabh
• 3,620 points
767 views
0 votes
1 answer

Programming Test - Codility - Dominator

After I had Googled "computing dominant member ...READ MORE

Feb 11, 2022 in Java by Soham
• 9,700 points
764 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
764 views
0 votes
2 answers

When to use static methods

Java main() method is always static, so that compiler ...READ MORE

Dec 29, 2020 in Java by Reshma
762 views
0 votes
2 answers

Unfortunately MyApp has stopped. How do I solve this?

The common solution for solving App has ...READ MORE

Mar 6, 2019 in Java by AllisonE
• 180 points
762 views
0 votes
1 answer

How to get the IP address of the machine using Java?

One approach is to use NetworkInterface.getNetworkInterfaces() to get all ...READ MORE

Jun 25, 2018 in Java by sharth
• 3,370 points
762 views
0 votes
2 answers

Is there a destructor in Java?

try (BufferedReader br = new BufferedReader(new FileReader(path))) ...READ MORE

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

How to iterate in a HashMap in Java?

Iterating using Iterator. Using Generics: Map<Integer, Integer> map = ...READ MORE

Aug 28, 2019 in Java by Sirajul
• 59,230 points
759 views