java ยท reference

Java Cool Tricks And Tips

This is a blog post where I’ll be collecting some cool Java tricks I keep forgetting about.


Enable http client / web services dumping


Download artifact manually

mvn -s ../Projects/rh/workspace/settings.xml org.apache.maven.plugins:maven-dependency-plugin:2.1:get  -DrepoUrl=    

Full debug

mvn -X

Sort pom

alias sortpom='mvn -Dsort.nrOfIndentSpace=4 -Dsort.sortPlugins=groupId,artifactId -Dsort.sortDependencies=scope,artifactId -Dsort.sortProperties=true

Maven clean up after failed download

delete files


Crashdump disassembly

Copy paste hex bytes of assembly code into this script:

echo $'.text\n' >1.s; echo "48 8b 17 74 ..." | tr ' ' "\n" | while read f; do echo ".byte 0x"$f; done >> 1.s

then run:

as 1.s
objdump --adjust-vma=0x000000006da0307a -d a.out


Concurrent map with lazy initialised values

Map<String, Long> lazyMap = new ConcurrentHashMap<>();

// get/init function
Long getCachedValue(String key) {
    lazyMap.computeIfAbsent(key, Util::someCreateMethodForKeyReturningLong);

Concurrent map with counters

Map<String, Long> counterMap = new ConcurrentHashMap<>();

// update function
void update(String key) {
    counterMap.merge(key, 1L, Long::sum);
comments powered by Disqus