Skip to content

Tag: java

How to copy an entire content from a directory to another in Java?

This is what I have. It copies everything just fine. But among the contents there are some folders. The folders are copied but the folder’s contents are not. Answer Recursion. Here is a method the uses rescursion to delete a system of folders: Didn’t test the code, but it should work. Basically, i…

fixed point arithmetics in java with fast performance

I need to represent some numbers in Java with perfect precision and fixed number of decimal points after decimal point; after that decimal point, I don’t care. (More concretely – money and percentages.) I used Java’s own BigDecimal now, but I found out, that it’s really slow and it sta…

How to run TestNG from command line

How exactly do I run a .java TestNG project from a command line? I have read through the TestNG documentation, and tried the following to no avail: … with the following testng.xml file in my project: The error I get is this: Obviously, I am not referencing TestNG correctly in my command line. Does anyon…

VisualVM launcher error

I’m trying to use the Eclipse VisualVM launcher. It seems pretty nice, except that it seems to spawn an instance if VisualVM too late to do any profiling of my application. My application finishes execution before the profiler is even initialized; once it starts up, an error window pops up, saying: cann…

Call java class method from jar (not main)

Is this possible to call a specific method (other than main) of a class in a jar file from command line? Answer If you are talking about running Java code from the command-line, then no. You can specify a class name, but not which method to call, that always has to be public static void main(String[] argv). W…

Save an integer in two digit format in a variable in Java

How can I store an integer in two digit format in Java? Like can I set and print it as 01? Also, not only printing, if I say int b=a;, b should also print its value as 01. Answer I think this is what you’re looking for: Or, more briefly: An int just stores a quantity, and 01 and 1