…little Java stuff worth to write down… (because every time I use it I have already forgotten the details…)

  1. Java little stuff
  2. IntelliJ Stuff for a lost Eclipse User
  3. Java Stream stuff
  4. JPA Stuff
  5. Serializer- and Marshaller-Stuff
  6. Java XPath Stuff
  7. Testing Stuff
  8. Framework-Blueprints
  9. Installer
    1. Java auf macOS
  10. WebApp with dirty JavaScript Frontend
    1. Quick and dirty Json-Load:
    2. Quick and dirty Intercooler-Stuff:
    3. Quarkus Backend

Java little stuff

the String:

String.format("(%f, %f)", x,y); 
String.format("Upload total: %.2f Stunden%n", minuten / 60.0); 

String.format("Zone: id: %s, usage: %s, geometry: %s", id, usage, polyLine.toString()); 

shebang support

#!/usr/bin/java --source 11
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hallo Java shebang");

find files

File directory = new File("rschumm/");

Optional<Path> foundFile = Files.find(
        (path, basicFileAttributes) -> path.toFile().getName().matches("blabla.*.yml")

quick File as String:

String s = Files.lines(Paths.get("")).collect(Collectors.joining()); 

very quick and dirty templating find- and replace

String template = Files.lines(Paths.get("../nfs/pv-nfs.yml")).collect(Collectors.joining("\n")); 
String out = template.replaceAll("0001", ""+i).replaceAll("general", "general/"+i); 	
Files.write(Paths.get("pv"+i+".yml"), out.getBytes(), StandardOpenOption.CREATE); 

Arrays Stuff:

Coordinate[] coordinates = new Coordinate[] {
    new Coordinate(1.0 , 1.0), 
    new Coordinate(1.0 , 100.0), 
    new Coordinate(100.0 , 100.0), 
    new Coordinate(100.0 , 1.0), 
    new Coordinate(1.0 , 1.0), 		                                            

//List to Array: 
tat.labels.toArray(new String[0])

//Array toString: 

Generics Stuff:

Room and Segement extends Space

List<Room> rooms = ...
List<Segment> segments = ...

// List<Room> is not instance of List<Space>, but List<? extends Space<?>>

public void doSomethingWithSpaces(List<? extends Space<?>> spaces) { ... 

the thing with resources:


…sometimes withoug getClassLoader(), sometimes with full path src/main/test/resources/..., e.g.

IntelliJ Stuff for a lost Eclipse User

no, there is no Workspace. Every Project is in a new Window.

JavaDoc hover: press ctrl-q, ctrl-j,alt-space
there is no context-menu for Type Hierarchy: press ctrl-h to open the Hierarchy View
the magic is ⌘-1 / cmd-1 is now ⎇-⮐ / alt-enter

Java Stream stuff

Collect To List:

List<Stuff> stuffInCar = -> car.contains(d)).collect(Collectors.toList()); 
List<Stuff> stuffInCar =; 
... .toArray(int[]::new); 
... .toArray(String[]::new)

Mapping stuff:

List<Room> roomsWithin =; 
// ==> terminating map; 

nested collection Mapping:

public static List<Eintrag> extractEinträge(List<Tag> tage){
        .flatMap(tag -> 
                .map(t -> new Eintrag(t, tag.extractDatum()))

Collect to Array:

Coordinate[] coordinates = -> new Coordinate(p.x , p.y)).toArray(Coordinate[]::new);

Nice formatted List of Strings Representations:

public static String eintrageToString(Stream<Tag> tage) {
    return extractEintrage(tage)
    .collect(Collectors.joining("\n* ", "* ", "")); 

JPA Stuff

public List<String> labels;

Serializer- and Marshaller-Stuff

Jackson Json Object Mapper:

public static void writeJson(File f, MyModel i)
    throws JsonGenerationException, JsonMappingException, IOException {
  ObjectMapper mapper = new ObjectMapper();
  mapper.writeValue(f, i);

public static MyModel readJson(File f) throws JsonParseException, JsonMappingException, IOException {
  ObjectMapper mapper = new ObjectMapper();
  // TODO validate to Schema 
  return mapper.readValue(f, MyModel.class); 

// for yaml file that contains a List of Objects (no wrapper object): 

private final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

public List<Tag> readYaml() throws IOException {
  List<Tag> tage = mapper.readValue(file, new TypeReference<List<Tag>>(){} );
  return tage; 

JAXB Marshaller:

public void marshall(File file) throws Exception {
  JAXBContext context = JAXBContext.newInstance(MyModel.class);
    Marshaller mar= context.createMarshaller();
    mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    mar.marshal(getMyModel(), file); 

JAXB Schema Class Generator

    <!-- <outputDirectory>${basedir}/src/main/java</outputDirectory> -->

JAXB Dependencies


<!-- JAXB needs javax.activation module (jdk9) -->

Java XPath Stuff


n.B. Model must conform to JavaBeans etc. - public variables will not work.

Room room6136 = (Room) JXPathContext.newContext(project).getValue("site/buildings/storeys/rooms[@name='6136']"); 

Testing Stuff


import static org.hamcrest.Matchers.*; 

assertThat(blabla.getDescription().getValue(), containsString("6136"));


Rest-Client UniRest - super easy Rest-Client
Rest-assured used by Quarkus
Database Migration flyway
Spark Java WebApp Framework
HTML Parser jsoup
Json Parsing: Jackson or Gson cf hier Yaml Parsing: Jackson, cf Studrepos Example
git access: cf ebenda.


I recommend Zulu

Java auf macOS

die JDK sind hier:



tar xf openjdk-14.0.2_osx-x64_bin.tar.gz
sudo mv jdk-14.0.2.jdk /Library/Java/JavaVirtualMachines/

Auf unbekannte magische Weise nimmt macOS automatisch die neuste Version.

WebApp with dirty JavaScript Frontend

Quick and dirty Json-Load:

 <script src=""



function load(){
    url: '/hallo/logbuch',
    type: 'GET',
    success: function (response) {
        var trHTML = '';
        $.each(response, function (i, item) {
            trHTML += '<tr><th scope="row">' + + '</th><td>' + item.text + '</td></tr>';



Quick and dirty Intercooler-Stuff:

<script src=""></script>


    <div class="input-group">
      <input type="text" class="form-control" placeholder="Nachricht an Rémy" aria-label="Input group example" aria-describedby="btnGroupAddon" name="textinput">
      <button type="submit" class="btn btn-primary btn-default" ic-post-to="/hallo/sali" ic-target="#nachricht" ic-on-success="load();">
        Click Me!

Quarkus Backend

public String saliPost(@FormParam("textinput") String name) {
    Message message = new Message();
    message.text = name; =;
    return service.sagHallo(name);

writing out with OutputStream of type StreamingOutput:

public Response dummy() throws IOException {
  Project dummyProject = new DummyProjectBuilder().dummyIfcProject; 
  IfcModel ifcModel = StepMarshaller.mapFromInternal(dummyProject); 
  StreamingOutput streamingOutput = output -> ifcModel.writeStepFile(output);
  return Response.ok(streamingOutput, "application/x-step").header("content-disposition","attachment; filename = dummy.ifc").build(); 

zurück zum Seitenanfang