I have a project that contains a single module, and some dependencies. I’d like to create a jar, in a separate directory, that contains the compiled module. In addition, I’d like to have the dependencies present beside my module. No matter how I twist IntelliJ’s “build jar” proce…
Java Object Method Stack Frame Parameters
So in java, say you have a non-static method ‘bar()’ in an class ‘Foo’. Say then that you call this method like so: Now the stack frame for the call includes the integer parameter, as well as a ‘this’ parameter to be used as an internal reference to the object. What other i…
How can I get the current stack trace in Java?
How do I get the current stack trace in Java, like how in .NET you can do Environment.StackTrace? I found Thread.dumpStack() but it is not what I want – I want to get the stack trace back, not print it out. Answer You can use Thread.currentThread().getStackTrace(). That returns an array of StackTraceEle…
Can I pass parameters by reference in Java?
I’d like semantics similar to C#’s ref keyword. Answer Java is confusing because everything is passed by value. However for a parameter of reference type (i.e. not a parameter of primitive type) it is the reference itself which is passed by value, hence it appears to be pass-by-reference (and peop…
How to read a single char from the console in Java (as the user types it)?
Is there an easy way to read a single char from the console as the user is typing it in Java? Is it possible? I’ve tried with these methods but they all wait for the user to press enter key: I’m starting to think that System.in is not aware of the user input until enter is pressed. Answer What you
What is the Iterable interface used for?
I am a beginner and I cannot understand the real effect of the Iterable interface.
Java Timer
I’m trying to use a timer to schedule a recurring event in an application. However, I want to be able to adjust the period at which the event fires in real time (according to the users input). For example: I then start a new instance of this class and call its set period function. However, when I do tha…
.class vs .java
What’s the difference between a .class file and a .java file? I am trying to get my applet to work but currently I can only run it in Eclipse, I can’t yet embed in HTML. Thanks **Edit: How to compile with JVM then? Answer A .class file is a compiled .java file. .java is all text and is human reada…
Initialization of an ArrayList in one line
I wanted to create a list of options for testing purposes. At first, I did this: Then, I refactored the code as follows: Is there a better way to do this? Answer Actually, probably the “best” way to initialize the ArrayList is the method you wrote, as it does not need to create a new List in any w…
“Invalid signature file” when attempting to run a .jar
My java program is packaged in a jar file and makes use of an external jar library, bouncy castle. My code compiles fine, but running the jar leads to the following error: Exception in thread “main” java.lang.SecurityException: Invalid signature file digest for Manifest main attributes I’ve …