I’m writing a program in scala which call: I want to check if “svn” is available from the commandline (ie. it is reachable in the PATH). How can I do this ? PS: My program is designed to be run on windows Answer Here’s a Java 8 solution: Replace anyMatch(…) with filter(…).f…
Why does Java have transient fields?
Why does Java have transient fields? Answer The transient keyword in Java is used to indicate that a field should not be part of the serialization (which means saved, like to a file) process. From the Java Language Specification, Java SE 7 Edition, Section 8.3.1.3. transient Fields: Variables may be marked tr…
How to import an existing X.509 certificate and private key in Java keystore to use in SSL?
I have this in an ActiveMQ config: I have a pair of X.509 cert and a key file. How do I import those two in order to use them in SSL and SSL+stomp connectors? All examples I could google always generate the key themselves, but I already have a key. I have tried but this only imports the certificate and
Eclipse open console apps in separate window
Is there a way to configure eclipse to open console apps in a new window rather than it’s own console when you run/debug them? I’m debugging a client/server application and I’d like to see the output of both apps at once and not have to switch between the tabs… Answer In eclipse, you c…
What are Reified Generics? How do they solve Type Erasure problems and why can’t they be added without major changes?
I’ve read Neal Gafter’s blog on the subject and am still unclear on a number of points. Why is it not possible to create implementations of the Collections API that preserve type information given the current state of Java, the JVM and existing collections API? Couldn’t these replace the exi…
Higher-kinded generics in Java
Suppose I have the following class: Now I want to introduce a generic argument, abstracting over the use of Expr: But Eclipse doesn’t like this: The type F is not generic; it cannot be parametrized with arguments <Fix<F>> Is this possible at all or have I overlooked something that causes thi…
Regex for tree structures?
Are there regular expression equivalents for searching and modifying tree structures? Concise mini-languages (like perl regex) are what I am looking for. Here is an example that might clarify what I am looking for. An operation that would be possible on the above tree is “move subtree at node 2.1 into t…
Where is allocated variable reference, in stack or in the heap?
I have a question What happend when I declare a variable inside a method, for example. void myMethod() { Ship myShip = new Ship(); } Where is allocated myShip reference, in stack or in the heap ? I think in stack but I’m confused because I was reading in J2ME Game Programming book “Java classes ar…
What is the Java equivalent of C’s printf %g format specifier?
I tried using Formatter.format, but that seems to leave the mantissa on numbers with 0 mantissa, whereas the C version does not. Is there an equivalent of C’s %g format specifier in Java, and if not, is there a way to fake it? My intention is to preserve the mantissa exactly like C’s for compatibi…
How do I copy an object in Java?
Consider the code below: So, I want to copy the dum to dumtwo and change dum without affecting the dumtwo. But the code above is not doing that. When I change something in dum, the same change is happening in dumtwo also. I guess, when I say dumtwo = dum, Java copies the reference only. So, is there any way