java

  • http://www.graalvm.org/

  • http://august.nagro.us/small-java.html

  • Java Properties: Part 2

    Load a properties file from current directory. Properties properties = new Properties(); properties.load(new FileReader(new File(„.“).getCanonicalPath() + File.separator + „java.properties“)); Write a start script #! /bin/bash scriptdir=“$( cd „$( dirname „${BASH_SOURCE[0]}“ )“ && pwd )“ cd $scriptdir java -jar MyExecutable.jar cd – Now you can start your configurable java program from any location, e.g. by linking…

  • Java Properties: Part 1

    Printing printProperties(System.getProperties()); private static void printProperties(Properties properties) { new TreeSet<>(properties.keySet()).forEach((k) -> { System.out.println(k + “ : “ + properties.get(k)); }); }  

  • Converting XML to JSON

    You can use standard tools for it 1. Use the tool xjc from your jdk to generate Java classes from schema Since Java 9 you must explicitly add JAXB as module with –add-modules java.se.ee See: How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9 Since Java 11 you have to download xjc in an extra step…

  • This shows you how to 1. Read in an XML file to a DOM 2. Filter out a set of Nodes with XPath 3. Perform a certain action on each of the extracted Nodes. We will call the code with the following statement processFilteredXml(xmlIn, xpathExpr,(node) -> {/*Do something…*/;}); In our case we want to print…

  • Managing Java SDKs

    And here it is. A management tool for Java SDKs. https://sdkman.io/

  • Motivation Processing of huge XML files can become cumbersome if your hardware is limited. „Parsing a sample 20 MB XML document[1] containing Wikipedia document abstracts into a DOM tree using the Xerces library roughly consumes about 100 MB of RAM. Other document model implementations[2] such as Saxon’s TinyTree are more memory efficient; parsing the same…

  • Recently I introduced a solution for URL encoding in Java . public static String encode(String url) { try { URL u = new URL(url); URI uri = new URI(u.getProtocol(), u.getUserInfo(), IDN.toASCII(u.getHost()), u.getPort(), u.getPath(), u.getQuery(), u.getRef()); String correctEncodedURL = uri.toASCIIString(); return correctEncodedURL; } catch (Exception e) { throw new RuntimeException(e); } }   Now I like…

  • URL encoding in Java.

    Here is, how I encode URLs in Java. Split URL into structural parts. Use java.net.URL for it. Encode each part properly Use IDN.toASCII(putDomainNameHere) to Punycode encode the host name! Use java.net.URI.toASCIIString() to percent-encode, NFC encoded unicode – (better would be NFKC!). For more info see: How to encode properly this URL URL url= new URL(„http://search.barnesandnoble.com/booksearch/first…