Java

Java (not to be confused with JavaScript or JScript or JS) is a general-purpose object-oriented programming language designed to be used in conjunction with the Java Virtual Machine (JVM). "Java platform" is the name for a computing system that has installed tools for developing and running Java programs. Use this tag for questions referring to the Java programming language or Java platform tools.

56 votes
30 answers
2K views
Difference between StringBuilder and StringBuffer

What is the main difference between StringBuffer and StringBuilder? Is there any performance issues when decid

avatar
Santiago
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
1.3K views
Why use getters and setters/accessors?

What's the advantage of using getters and setters - that only get and set - instead of simply using publi

avatar
Shantay
0 1 0 9
asked 07 September, 2021
64 votes
30 answers
836 views
How can I avoid Java code in JSP files, using JSP 2?

I'm new to Java EE and I know that something like the following three lines <%= x+1 %> <%= reque

avatar
Solomon
0 1 0 9
asked 07 September, 2021
51 votes
30 answers
704 views
Sort a Map<Key, Value> by values

I am relatively new to Java, and often find that I need to sort a Map<Key, Value> on the values. Since

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
51 votes
30 answers
1.1K views
How to split a string in Java

I have a string, "004-034556", that I want to split into two strings: string1="004"; string2="034556"; That

avatar
Brianne
0 1 0 9
asked 07 September, 2021
54 votes
15 answers
2.8K views
Why does this code using random strings print "hello world"?

The following print statement would print "hello world". Could anyone explain this? System.out.println(random

avatar
Carmelina
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
2.2K views
How to generate a random alpha-numeric string

I've been looking for a simple Java algorithm to generate a pseudo-random alpha-numeric string. In my si

avatar
Arline
0 1 0 9
asked 07 September, 2021
66 votes
25 answers
567 views
Does Java support default parameter values?

I came across some Java code that had the following structure: public MyParameterizedFunction(String param1,

avatar
Keila
0 1 0 9
asked 07 September, 2021
57 votes
27 answers
1.4K views
Java inner class and static nested class

What is the main difference between an inner class and a static nested class in Java? Does design / implementa

avatar
Stacia
0 1 0 9
asked 07 September, 2021
49 votes
14 answers
1.7K views
Comparing Java enum members: == or equals()?

I know that Java enums are compiled to classes with private constructors and a bunch of public static members.

avatar
Margo
0 1 0 9
asked 07 September, 2021
49 votes
30 answers
2.8K views
How do I break out of nested loops in Java?

I've got a nested loop construct like this: for (Type type : types) { for (Type t : types2) {

avatar
Don
0 1 0 9
asked 07 September, 2021
66 votes
11 answers
910 views
How to use java.net.URLConnection to fire and handle HTTP requests

Use of java.net.URLConnection is asked about pretty often here, and the Oracle tutorial is too concise about i

avatar
Vi
0 1 0 9
asked 07 September, 2021
62 votes
23 answers
410 views
What is a JavaBean exactly?

I understood, I think, that a "Bean" is a Java class with properties and getters/setters. As much as I underst

avatar
Serina
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
1.6K views
How do you assert that a certain exception is thrown in JUnit 4 tests?

How can I use JUnit4 idiomatically to test that some code throws an exception? While I can certainly do somet

avatar
Hallie
0 1 0 9
asked 07 September, 2021
59 votes
30 answers
1.1K views
What&apos;s the simplest way to print a Java array?

In Java, arrays don't override toString(), so if you try to print one directly, you get the className + &

avatar
Jeff
0 1 0 9
asked 07 September, 2021
48 votes
30 answers
2.7K views
How to get an enum value from a string value in Java

Say I have an enum which is just public enum Blah { A, B, C, D } and I would like to find the enum value

avatar
Vi
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
1.8K views
"implements Runnable" vs "extends Thread" in Java

From what time I've spent with threads in Java, I've found these two ways to write threads: With imp

avatar
Thurman
0 1 0 9
asked 07 September, 2021
65 votes
28 answers
2.1K views
How do I declare and initialize an array in Java?

How do I declare and initialize an array in Java?

avatar
Wilfredo
0 1 0 9
asked 07 September, 2021
54 votes
29 answers
2.6K views
What&apos;s the difference between @Component, @Repository & @Service annotations in Spring?

Can @Component, @Repository and @Service annotations be used interchangeably in Spring or do they provide any

avatar
Tana
0 1 0 9
asked 07 September, 2021
53 votes
22 answers
1.2K views
What is reflection and why is it useful?

What is reflection, and why is it useful? I'm particularly interested in Java, but I assume the principle

avatar
Shanita
0 1 0 9
asked 07 September, 2021