Most voted questions in Java

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 can I solve java.lang.NoClassDefFoundError in Java?

NoClassDefFoundError means that the class is present ...READ MORE

Sep 11, 2018 in Java by Sushmita
• 6,910 points
33,440 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,857 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
955 views
0 votes
1 answer

How to retrieve current stack trace?

Yes, in Java we do have a ...READ MORE

May 17, 2018 in Java by code.reaper12
• 3,500 points
1,639 views
0 votes
1 answer

Replacing a String with a character

Yes, you are missing out on a ...READ MORE

May 17, 2018 in Java by geek.erkami
• 2,680 points
469 views
0 votes
2 answers

I'm getting following error, while i'm running code in windows xp service pack 3 with JDK 6 version.

Till you send the code, I would ...READ MORE

May 16, 2018 in Java by Meci Matt
• 9,460 points
2,322 views
0 votes
1 answer

How can I get Key from their respective Values

public class NewClass1 { ...READ MORE

May 16, 2018 in Java by Parth
• 4,630 points
515 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
965 views
0 votes
1 answer

How to split Strings by space in Java ?

You can use split() method. str = "Hello ...READ MORE

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

How to set a timer in Java?

To work on timer in java, you ...READ MORE

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

Formatting Double Value in Java

An alternative is to use String.format: double[] arr = ...READ MORE

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

How to read and write on an excel files?

Follow these steps: Write: public class User { ...READ MORE

May 15, 2018 in Java by Rishabh
• 3,620 points
1,310 views
0 votes
2 answers

How do i create generic array in Java

as first tip you cannot assign value ...READ MORE

Feb 13, 2020 in Java by sama
16,950 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
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,753 views
0 votes
1 answer

What is Java Enterprise Edition ?

Is Java EE just a specification? What ...READ MORE

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

How to get the number of digits in an int?

You can find out the length of ...READ MORE

May 14, 2018 in Java by Akrati
• 3,190 points
760 views
0 votes
2 answers

How to convert byte array to String and STring to byte array?

The best possible way of conversion between byte[] and String is to ...READ MORE

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

What is the concept of Immutability for strings in Java ? Why are strings immutable ?

According to Effective Java, chapter 4, page 73, ...READ MORE

May 11, 2018 in Java by Rishabh
• 3,620 points
1,366 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,164 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
794 views
0 votes
1 answer

Can Abstract Class have a Constructor?

Yes, an abstract class can have a ...READ MORE

May 11, 2018 in Java by sharth
• 3,370 points
947 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
799 views
0 votes
1 answer

How to connect Java program to the MySQL database?

You can connect your Java code with ...READ MORE

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

Comparable vs Comparator in Java

I think you are not alone who is ...READ MORE

May 11, 2018 in Java by code.reaper12
• 3,500 points
884 views
0 votes
2 answers

Fetch list of in-between dates using Java

java.time Package The new java.time.package in Java 8 incorporates ...READ MORE

Aug 21, 2019 in Java by Sirajul
• 59,230 points
5,445 views
0 votes
1 answer

How do I join 2 lists

This is not a simpler method, but ...READ MORE

May 11, 2018 in Java by sharth
• 3,370 points
548 views
0 votes
2 answers

Get all the permutations of a string in Java

You could use recursion to do this.  Try ...READ MORE

Aug 21, 2019 in Java by Sirajul
• 59,230 points
1,959 views
0 votes
1 answer

Play MP3 files usng Java API

I don't believe the java AudioStream class ...READ MORE

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

Exception found while using Thread.sleep() and wait() in Java

A simpler way to wait is to ...READ MORE

Aug 13, 2018 in Java by samarth295
• 2,220 points
8,812 views
0 votes
2 answers

When to use LinkedList and ArrayList in Java?

ArrayList is what you want. LinkedList is almost always a ...READ MORE

Dec 11, 2018 in Java by Sushmita
• 6,910 points
885 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

Converting String and Float Data-types

Using Java’s Float class. float f = Float.parseFloat("25"); String s = ...READ MORE

May 9, 2018 in Java by developer_1
• 3,320 points
610 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
1 answer

What does Java option -Xmx stand for?

-Xmxn: It specifies the maximum size, in bytes, ...READ MORE

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

Why the main() method in Java is always static?

As you might know, static here is ...READ MORE

May 9, 2018 in Java by geek.erkami
• 2,680 points
1,927 views
0 votes
1 answer

Need for finalize() in Java

finalize() is a method called by the ...READ MORE

May 9, 2018 in Java by code.reaper12
• 3,500 points
540 views
0 votes
1 answer

Implement Tree(Datastructure) in Java

I wrote a small "TreeMap" class based ...READ MORE

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

Perform "Switch-case" on String in Java

Switches based on integers can be optimized ...READ MORE

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

In which class is the "length" property of array defined ?

It's defined in the Java language specification: The members ...READ MORE

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

Convert String type to byte[] in Java

Try using String.getBytes(). It returns a byte[] ...READ MORE

May 8, 2018 in Java by Rishabh
• 3,620 points
605 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,144 views
0 votes
1 answer

How to read text files from the Classpath in Java?

InputStream in = this.getClass().getClassLoader().getResourceAsStream("TextFile.txt"); InputStream in = this.getClass().getResourceAsStream("/TextFile.txt"); package ...READ MORE

May 8, 2018 in Java by Akrati
• 3,190 points
2,621 views
0 votes
1 answer

How can we get file extension in Java?

To get the file extension, we can ...READ MORE

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

Difference between String.equals() and ==

Though both are used for comparison, but the ...READ MORE

May 7, 2018 in Java by geek.erkami
• 2,680 points
689 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,332 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
894 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,987 views