What is passed into args [] [duplicate] - java

This question already has answers here:
What is the "String args[]" parameter in the main method?
(18 answers)
Closed 6 years ago.
What information is actually passed into the program if I pass a file using the command line?
Would this be the file name, or would it be the contents of the file?

In Java, unlike in C/C++, the file name is not the first argument.
Only the arguments are in args[].

Related

What does '...' mean in method parameter javadoc? [duplicate]

This question already has answers here:
What is the ellipsis (...) for in this method signature?
(5 answers)
What do 3 dots next to a parameter type mean in Java?
(9 answers)
Closed 5 years ago.
I'm looking at the Files class in java 7, and I see this method
copy(InputStream, Path, CopyOptions...)
How do I read "CopyOptions...". What's the ... mean?

Why is there ... in a java function? [duplicate]

This question already has answers here:
What do 3 dots next to a parameter type mean in Java?
(9 answers)
Closed 7 years ago.
I'm following a java tutorial named "Java Swing first programs" and I noticed something that troubles me. At one point, there's a function written like this:
private void createLayout(JComponent... arg)
I was wandering why there was a ... and what those it do?
The tutorial: http://zetcode.com/tutorials/javaswingtutorial/firstprograms/
See the documentation for Java varargs.

difference between printf and println in java? [duplicate]

This question already has answers here:
Is there a good reason to use "printf" instead of "print" in java?
(4 answers)
Closed 8 years ago.
Just came to know that java does has a method named printf, then what is the difference between printf & println?
System.out.println(); is efficient for simply printing a line of text. If the line of text needs to be formatted (ex: alignment (left-justified, etc.), etc.), then System.out.printf(); would be used.
Check out this link for more information.

How to get the name of the containing function [duplicate]

This question already has answers here:
Getting the name of the currently executing method
(23 answers)
Closed 8 years ago.
In C++, you can use __FUNCTION_NAME__ to get the name of the function that contains __FUNCTION_NAME__.
Is there an equivalent in Java? It could, in Java, be possible to do something with this and reflection. Is there something simpler though?
Thread.currentThread().getStackTrace()
will usually contain the method you’re calling it from but there are pitfalls
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/StackTraceElement.html
Thread.currentThread().getStackTrace()[ste.length - 1 - depth].getMethodName();
depth = 0 (zero) will give current method
also
System.out.println((new Throwable()).getStackTrace()[0].toString());
Sample output:
com.junk.Junk3.main(Junk3.java:12)

java calculate pathname difference [duplicate]

This question already has answers here:
How to construct a relative path in Java from two absolute paths (or URLs)?
(23 answers)
Closed 6 years ago.
Is there an open source library that, given ...
/a/b/c
/a/b/c/d/e
would return ../..
or for that matter given
/a/b/c/d
/a/b/c/e
would return ../d
?
If you don't mind passing by converting your Strings into URI then this latter one has the method relativize which should do exactly what you want, take a look here.

Categories

Resources