170 Answered Questions for the topic Java


How do I parse command line arguments in Java?

What is a good way of parsing command line arguments in Java?


How can I convert my Java program to an .exe file?

If I have a Java source file (\\*.java) or a class file (\\*.class), how can I convert it to a .exe file?I also need an installer for my program.


Geometry library for Java?

Is there any geometry library available for Java? I'm looking for solution to get an intersection point(s) between two geometry objects.


How to get the path of a running JAR file?

My code runs inside a JAR file, say foo.jar, and I need to know, in the code, in which folder the running foo.jar is.So, if foo.jar is in `C:\\FOO\\`, I want to get that path no matter what my... more


Can enums be subclassed to add new elements?

I want to take an existing enum and add more elements to it as follows: enum A {a,b,c} enum B extends A {d} // B is {a,b,c,d} Is this possible in Java?


Is there anything like .NET's NotImplementedException in Java?

Is there anything like .NET's `NotImplementedException` in Java?


In Java, what are the boolean "order of operations"?

Let's take a simple example of an object `Cat`. I want to be sure the "not null" `cat` is either orange or grey. if(cat != null && cat.getColor() == "orange" || cat.getColor() == "grey")... more


Getting a File's MD5 Checksum in Java?

I am looking to use Java to get the MD5 checksum of a file. I was really surprised but I haven't been able to find anything that shows how to get the MD5 checksum of a file.How is it done?


How to solve OutOfMemoryError when building a PDF System Design Description for a "big" Simulink Model?

Introduction I get an `OutOfMemoryError` when building a `System Design Description` in `PDF` and `Word` format. Steps resulting in Exception I have already increased the heap space to the maximum... more


Run a single test method with maven?

I know you can run all the tests in a certain class using: mvn test -Dtest=classnameBut I want to run an individual method and -Dtest=classname.methodname doesn't seem to work.


Change date format in a Java string?

I've a `String` representing a date. String date_s = "2011-01-18 00:00:00.0"; I'd like to convert it to a `Date` and output it in `YYYY-MM-DD` format > 2011-01-18 How can I achieve this?


When would you use the Builder Pattern?

What are some *common*, *real world examples* of using the Builder Pattern? What does it buy you? Why not just use a Factory Pattern?


Why is the Java main method static?

The method signature of a Java `main()` method is: public static void main(String[] args) { ... } Is there a reason for this method to be static?


Safely casting long to int in Java?

What's the most idiomatic way in Java to verify that a cast from `long` to `int` does not lose any information? This is my current implementation: public static int safeLongToInt(long l) { int... more


Any 3D geometry algorithms library in Java?

I need a library, that could perform some geometry operations with objects in 3D, like: - Find min distance between 2 triangles - Intersect two polygons - Intersect to objects and exctract... more


How do I get a platform-dependent new line character?

How do I get a platform-dependent newline in Java? I can’t use `"\ "` everywhere.


Java - escape string to prevent SQL injection?

I'm trying to put some anti sql injection in place in java and am finding it very difficult to work with the the "replaceAll" string function. Ultimately I need a function that will convert any... more


Creating a triangle with for loops?

I don't seem to be able to find the answer to this- I need to draw a simple triangle using for loops. * *** ***** ******* ********* I can make a half triangle, but I don't... more


What does the Java assert keyword do, and when should it be used?

What are some **real life examples** to understand the key role of assertions?


java.util.Date vs java.sql.Date?

`java.util.Date` vs `java.sql.Date`: when to use which and why?


How do I pass in a polynomial function in java?

For a programming project in Calculus we were instructed to code a program that models the Simpson's 1/3 and 3/8 rule. We are supposed to take in a polynomial(i.e. 5x^2+7x+10) but I am struggling... more


When do you use Java's @Override annotation and why?

What are the best practices for using Java's `@Override` annotation and why? It seems like it would be overkill to mark every single overridden method with the `@Override` annotation. Are there... more


In Java XOR with three true inputs returns true. Why?

The following code System.out.println("1 0 0: " + (true ^ false ^ false)); System.out.println("1 0 1: " + (true ^ false ^ true)); System.out.println("1 1 0: " + (true ^ true ^ false)); ... more


3D Sphere OpenGL?

I would like to create a Sphere, actually a globe. But i can't seem to find any helpful information about how to handle the vertices and indices to a sphere, how to set them up. Could any of you... more


How do I remove repeated elements from ArrayList?

I have an `ArrayList`, and I want to remove repeated strings from it. How can I do this?

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.