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.

63 votes
5 answers
1.6K views
Why does Java switch on contiguous ints appear to run faster with added cases?

I am working on some Java code which needs to be highly optimized as it will run in hot functions that are inv

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
57 votes
1 answers
2.7K views
Rounding BigDecimal to *always* have two decimal places

I'm trying to round BigDecimal values up, to two decimal places. I'm using BigDecimal rounded = va

avatar
Rufus
0 1 0 9
asked 07 September, 2021
55 votes
25 answers
2.3K views
How to evaluate a math expression given in string form?

I'm trying to write a Java routine to evaluate math expressions from String values like: "5+3" "10-40" "(

avatar
Stacia
0 1 0 9
asked 07 September, 2021
66 votes
16 answers
1.9K views
How to round up the result of integer division?

I'm thinking in particular of how to display pagination controls, when using a language such as C# or Jav

avatar
Hilario
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
937 views
Fastest way to determine if an integer's square root is an integer

I'm looking for the fastest way to determine if a long value is a perfect square (i.e. its square root is

avatar
Margo
0 1 0 9
asked 07 September, 2021
62 votes
6 answers
2.2K views
How to set the DPI of Java Swing apps on Windows/Linux?

If you have an monitor with a DPI over 150 (such as Macbook Pro), you may also find the problem: the font on t

avatar
Fabian
0 1 0 9
asked 07 September, 2021
52 votes
10 answers
892 views
Why aren't Java Collections remove methods generic?

Why isn't Collection.remove(Object o) generic? Seems like Collection<E> could have boolean remov

avatar
Percy
0 1 0 9
asked 07 September, 2021
63 votes
7 answers
3K views
Convert Enumeration to a Set/List

Is there some one-liner bridge method to dump a given Enumeration to java.util.List or java.util.Set? Somethin

avatar
Omar
0 1 0 9
asked 07 September, 2021
56 votes
9 answers
1.2K views
Difference between SPI and API?

What is the difference between Service Provider Interface (SPI) and Application Programming Interface (API)? M

avatar
Nidia
0 1 0 9
asked 07 September, 2021
75 votes
10 answers
592 views
Compilation failed to complete:Program type already present

When compiling my project I get the following error message: Program type already present: com.google.androi

avatar
Thurman
0 1 0 9
asked 07 September, 2021
60 votes
8 answers
2.5K views
How to read XML using XPath in Java

I want to read XML data using XPath in Java, so for the information I have gathered I am not able to parse XML

avatar
Omar
0 1 0 9
asked 07 September, 2021
53 votes
30 answers
1.3K views
How to pretty print XML from Java?

I have a Java String that contains XML, with no line feeds or indentations. I would like to turn it into a Str

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
61 votes
9 answers
2.4K views
java.util.Date to XMLGregorianCalendar

Isn't there a convenient way of getting from a java.util.Date to a XMLGregorianCalendar?

avatar
Royal
0 1 0 9
asked 07 September, 2021
57 votes
2 answers
2.4K views
Jython, use only a method from Python from Java?

When reading and using this article it assumes that we have a full object definition with class and mapping (p

avatar
Robt
0 1 0 9
asked 07 September, 2021
59 votes
2 answers
1.1K views
Redux: How do I get Jython to use Python modules stored in Lib within its own jar file when running in Hadoop?

I'm attempting to use Jython for an implementation within Hadoop 1.2.1. I have seen strikingly little ab

avatar
Xavier
0 1 0 9
asked 07 September, 2021
52 votes
2 answers
2.2K views
Why does this Jython loop fail after a single run?

I've got the following code: public static String getVersion() { PythonInterpreter interpreter = ne

avatar
Clarice
0 1 0 9
asked 07 September, 2021
57 votes
4 answers
1.1K views
jython multithreading

I started studying python a couple of month ago, then I found Jython. Do threads work properly in Jython, sin

avatar
Royal
0 1 0 9
asked 07 September, 2021
54 votes
5 answers
1.5K views
Using NumPy and Cpython with Jython

I must use a commercial Java library, and would like to do it from Python. Jython is robust and I am fine with

avatar
Nereida
0 1 0 9
asked 07 September, 2021
59 votes
4 answers
2.8K views
Jython and python modules

I've just started using the PythonInterpreter from within my Java classes, and it works great! However, i

avatar
Sachiko
0 1 0 9
asked 07 September, 2021
57 votes
6 answers
2.9K views
How can I call scikit-learn classifiers from Java?

I have a classifier that I trained using Python's scikit-learn. How can I use the classifier from a Java

avatar
Joseph
0 1 0 9
asked 07 September, 2021