Most voted questions in Java

0 votes
1 answer

How can a war file be deployed in Tomcat 7?

You can access your application from: http://localhost:8080/sample Deploying ...READ MORE

Apr 20, 2018 in Java by sophia
• 1,400 points
1,922 views
0 votes
1 answer

How do I create a Java string from the contents of a file?

If you're looking for an alternative that ...READ MORE

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

Following error is occurring "Can't start Eclipse - Java was started but returned exit code=13"

There are combinations of Operating System, JDK ...READ MORE

Apr 19, 2018 in Java by Rishabh
• 3,620 points
2,737 views
0 votes
3 answers

Convert date object to a String

We parse the full date to time ...READ MORE

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

How can I add new elements to an Array in Java

String[] source = new String[] { "a", ...READ MORE

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

How can we define global variables in java?

To define Global Variable you can make ...READ MORE

Dec 15, 2020 in Java by Gitika
• 65,910 points
115,547 views
0 votes
1 answer

How to fix the error failed to load the JNI shared Library?

You need these three things : 64-bit OS 64-bit ...READ MORE

Apr 19, 2018 in Java by sophia
• 1,400 points
2,266 views
0 votes
3 answers

How to parse JSON in Java

import org.json.*; JSONObject obj = new JSONObject(" .... ...READ MORE

Aug 20, 2018 in Java by Daisy
• 8,120 points
3,733 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,242 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
774 views
0 votes
1 answer

Sorted array is being processed faster than unsorted array. Why is it so ?

What is Branch Prediction? Consider a railroad junction: Image by ...READ MORE

Apr 18, 2018 in Java by Rishabh
• 3,620 points
951 views
0 votes
3 answers

How to check whether a file exists or not in Java?

Using nio we can check whether file ...READ MORE

Aug 14, 2018 in Java by Sushmita
• 6,910 points
3,588 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,581 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,126 views
0 votes
1 answer

Is it possible to run a java program from command line on windows?How?

  Let's say your file is in C:\myprogram\ Run ...READ MORE

Apr 18, 2018 in Java by sophia
• 1,400 points
2,383 views
0 votes
3 answers

How to sort an array in java?

import java.util.Arrays; public class Sort { ...READ MORE

Aug 24, 2018 in Java by Parth
• 4,630 points
883 views
0 votes
2 answers

How do I read and convert an InputStream object to string type?

You can also use Java Standard Library ...READ MORE

Jul 17, 2018 in Java by Sushmita
• 6,910 points
16,732 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,195 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
814 views
0 votes
1 answer

I am learning looping statements. Can you tell me how 'for-each' works in Java?

While programming we often write code that ...READ MORE

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

How to print java array in the simplest way?

String[] arr = new String[] {"John", "Mary", ...READ MORE

Apr 17, 2018 in Java by sophia
• 1,400 points
653 views
0 votes
1 answer

How to take input from users?

Scanner Class is used to take input ...READ MORE

Apr 17, 2018 in Java by Akrati
• 3,190 points
581 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
837 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,851 views
0 votes
0 answers

Ho do I Iterate through a HashMap which contains duplicate values

What is the fastest and the best ...READ MORE

Apr 16, 2018 in Java by Daisy
• 8,120 points
673 views
0 votes
3 answers

Check if a String is numeric in Java

Java 8 Lambda Expression is used: String someString ...READ MORE

Sep 3, 2018 in Java by Daisy
• 8,120 points
3,388 views
0 votes
2 answers

How is hashmap different from hashtable?

HashMap and HashTable: 1) Hashtable and Hashmap implement ...READ MORE

Aug 1, 2018 in Java by samarth295
• 2,220 points
6,006 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
804 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,139 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,578 views
0 votes
4 answers

Remove extra spaces from string in java

import java.util.regex.Matcher; import java.util.regex.Pattern; String pattern="[\\s]"; String replace=""; part="name=john age=13 year=2001"; Pattern ...READ MORE

Sep 10, 2018 in Java by Parth
• 4,630 points
2,698 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,347 views
0 votes
1 answer

How do I fix a NullPointerException?

When you declare a reference variable (i.e. ...READ MORE

Apr 13, 2018 in Java by Parth
• 4,630 points
699 views
0 votes
2 answers

How do I get the current date and time using Java?

If you require a time stamp in ...READ MORE

Aug 23, 2019 in Java by Sirajul
• 59,230 points
2,390 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,191 views
0 votes
2 answers

How to round any number to n decimal places in Java?

new BigDecimal(String.valueOf(double)).setScale(yourScale, BigDecimal.ROUND_HALF_UP); will get you a BigDecimal. To ...READ MORE

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

What is the syntax to initialize an array?

Rather than learning un-Official websites learn from ...READ MORE

Aug 2, 2018 in Java by samarth295
• 2,220 points
709 views
0 votes
2 answers

How to create a 2-D array in java?

int[][] multi = new int[5][]; multi[0] = new ...READ MORE

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

Integer to String conversion in java

We can do this in 2 ways: String ...READ MORE

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

How to divide a string in two parts

String s="yourstring"; boolean flag = true; for(int i=0;i<s.length();i++) { ...READ MORE

Apr 13, 2018 in Java by Rishabh
• 3,620 points
928 views
0 votes
5 answers

How to compare Strings in Java?

String fooString1 = new String("foo"); String fooString2 = ...READ MORE

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

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

Aug 20, 2019 in Java by Sirajul
• 59,230 points
1,928 views
–1 vote
0 answers

Write a program that uses a while loop to read 10 integer numbers from file

Write a program that uses a while ...READ MORE

Apr 16, 2020 in Java by MIH
• 150 points
1,897 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
926 views