Trending questions in Java

0 votes
1 answer

How can we format float to n decimal places ?

You may pass the float value: String.format("%.2f", floatVal); READ MORE

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

How to read a Text File in Java?

You can use readAllLines and the join method to ...READ MORE

Jul 28, 2018 in Java by samarth295
• 2,220 points
2,178 views
0 votes
2 answers

How does '&&' (AND) and '||' (OR) statements work inside an IF condition ?

Short circuit here means that the second ...READ MORE

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

How can we compare dates in java?

public static String daysBetween(String day1, String day2) ...READ MORE

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

What is the native keyword in Java?

The native keyword is applied to a method to ...READ MORE

Jul 16, 2018 in Java by scarlett
• 1,290 points
516 views
0 votes
1 answer

What is casting variable in java?

Casting is, taking an Object of one ...READ MORE

Jul 17, 2018 in Java by scarlett
• 1,290 points
463 views
0 votes
1 answer

Bean Scopes in Java Spring

According to my knowledge, the Spring Framework ...READ MORE

Jul 4, 2018 in Java by geek.erkami
• 2,680 points
1,026 views
0 votes
1 answer

Injecting property value into Spring Bean using annotations

I think you can easily perform this ...READ MORE

May 29, 2018 in Java by code.reaper12
• 3,500 points
2,549 views
0 votes
1 answer

Programmatically closing a JFrame

If you want the GUI to behave ...READ MORE

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

How to perform Java 256 bit AES Password Based Encryption?

/* Derive the key, given password and ...READ MORE

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

Annotation wiring in Spring

By default, Annotation wiring is not turned ...READ MORE

Jul 4, 2018 in Java by code.reaper12
• 3,500 points
1,001 views
0 votes
2 answers

How to sort array in descending order

there are some traditional ways that you ...READ MORE

Jul 4, 2018 in Java by Priyaj
• 58,090 points
960 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
788 views
0 votes
2 answers

Generate an alpha-numeric string randomly

Java supplies a way of doing this ...READ MORE

Jul 18, 2018 in Java by Daisy
• 8,120 points
2,272 views
0 votes
2 answers

When and how to use Super() keyword in Java?

super() is used to call immediate parent. super() can be ...READ MORE

Jul 9, 2018 in Java by Sushmita
• 6,910 points
1,627 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
865 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
842 views
0 votes
1 answer

Sort a HashMap in Java

Convert hashmap to an ArrayList with a ...READ MORE

Jul 13, 2018 in Java by Daisy
• 8,120 points
520 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
864 views
0 votes
1 answer

What is an efficient way to implement a singleton pattern in Java?

Use an enum: public enum Foo { ...READ MORE

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

How can we use wait and notify in Java?

You can refer to this: synchronized (someObject) { ...READ MORE

Jul 12, 2018 in Java by sophia
• 1,400 points
494 views
0 votes
1 answer

What is the array initialization syntax when not in a declaration?

Probably you'd have to ask the Java ...READ MORE

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

Convert comma-separated String to ArrayList?

List<String> alist = Arrays.asList(str.split("\\s*,\\s*")); The above code splits ...READ MORE

May 17, 2018 in Java by sharth
• 3,370 points
2,856 views
0 votes
1 answer

What's the difference between SoftReference and WeakReference in Java?

Weak references A weak reference, simply put, is a ...READ MORE

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

java.lang.UnsupportedClassVersionError: Bad version number in .class file. How to solve this?

I've learned that error messages like this ...READ MORE

Jul 4, 2018 in Java by Annie
• 240 points
755 views
0 votes
0 answers

How to populate a ListView using an ArrayList?

I want to populate the data coming ...READ MORE

Jun 30, 2018 in Java by misc.edu04
• 1,450 points
975 views
0 votes
2 answers

How to call one constructor from another in Java?

public class Cons { public static Cons ...READ MORE

Jul 24, 2018 in Java by Akrati
• 3,190 points
1,347 views
0 votes
2 answers

Send HTTP request in Java

import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpResponse; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import java.io.IOException; import ...READ MORE

Aug 3, 2018 in Java by samarth295
• 2,220 points
1,529 views
+1 vote
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

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

How to resolve the java.net.ConnectException in Java?

If you are getting java.net.ConnectionException, it means ...READ MORE

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

Explain the functionality of Math.random() method.

You can use java.util.Random class. int myNumber = ...READ MORE

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

How may I programmatically determine operating system in Java?

Use the following program public class Osname {        public ...READ MORE

Jul 6, 2018 in Java by Priyaj
• 58,090 points
566 views
0 votes
1 answer

How to get the name of the currently executing method?

Thread.currentThread().getStackTrace() will usually contain the method you’re ...READ MORE

Jul 5, 2018 in Java by Daisy
• 8,120 points
642 views
0 votes
1 answer

Is there any way to write content of Java InputStream to an OutputStream?

org.apache.commons.io.IOUtils from Apache has a method called copy(InputStream,OutputStream).which does ...READ MORE

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

how to play sound in java?

 The following code will work fine. But I ...READ MORE

Jun 20, 2018 in Java by scarlett
• 1,290 points
1,286 views
0 votes
2 answers

Avoiding != null statements

public String getPostcode(Person person) { ...READ MORE

Aug 20, 2018 in Java by Daisy
• 8,120 points
531 views
0 votes
1 answer

How to get a platform-dependent new line character in Java?

If you are using Java 1.5 or ...READ MORE

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

How to pad an integer with zeros on the left in Java?

Use java.lang.String.format() method. String.format("%05d", number ...READ MORE

May 31, 2018 in Java by Daisy
• 8,120 points
2,110 views
0 votes
1 answer

Is it possible to create a memory leak with Java

Here's a good way to create a memory ...READ MORE

May 31, 2018 in Java by Parth
• 4,630 points
2,124 views
0 votes
2 answers

How can we remove an element from an array in Java?

You can use ArrayUtils class remove method which ...READ MORE

May 24, 2018 in Java by UshaK
2,419 views
0 votes
1 answer

NoClassDefFoundError in Java

Can’t tell you the exact reason as ...READ MORE

May 25, 2018 in Java by v.liyyah
• 1,300 points
2,316 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
841 views
0 votes
1 answer

Measure time elapsed in Java?

This is also a way to work ...READ MORE

Jul 4, 2018 in Java by scarlett
• 1,290 points
616 views
+1 vote
3 answers

How to convert a List to an Array in Java?

Either: Foo[] array = list.toArray(new Foo[list.size()]); or: Foo[] array = ...READ MORE

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

How to get the Generic type of class at run time?

public class GenericClass<T> { ...READ MORE

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

What is the difference between = and equals()?

The equals() method compares the "value" inside String instances ...READ MORE

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

How does omitting curly braces in Java program, effect the code ?

Using braces makes the code more maintainable ...READ MORE

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

How to reverse a string in java?

public static String reverse(String s) { ...READ MORE

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

In Java, how to find out the min/max values from array of primitive data types?

import java.util.Arrays; import java.util.Collections; import org.apache.commons.lang.ArrayUtils; public class MinMaxValue { ...READ MORE

Jun 12, 2018 in Java by Daisy
• 8,120 points
1,449 views
+1 vote
1 answer

What is the difference between JavaScript and Java

This quote rightly explains that 2 totally ...READ MORE

Jun 29, 2018 in Java by Daisy
• 8,120 points
605 views