Archive
Java Design Patterns
See https://java-design-patterns.com/ .
It also has a description of principles and a collection of code snippets.
Java 9 got a REPL
Java 9 came out a few days ago and it includes a REPL. This is a well-known thing among interpreted languages (e.g. Python), but it’s not very common in the case of compiled languages.
$ jshell | Welcome to JShell -- Version 9 | For an introduction type: /help intro jshell> int a = 3 a ==> 3 jshell> int b = 2 b ==> 2 jshell> a + b $3 ==> 5 jshell> $3 $3 ==> 5 jshell>
Here is a more detailed blog post about jshell.
Note
jshell stands for Java Shell, and not for JavaScript Hell!
Java profiling
YourKit is a great Java profiling tool. It is a commercial software but you can get a free 15-day evaluation license key for a fully functional version of the profiler.
The past week I was working on a Java project and the software was very slow. Using YourKit I could easily find the bottleneck. It turned out that 94% of the time was spent in a function that I implemented in a naive way. Choosing a better algorithm the software got much faster. A profiler is really useful…
For Java I use Eclipse. YourKit integrates in Eclipse perfectly through an Eclipse plugin.
Python profiling
Here is an excellent post about Python profiling.
Jerly: A Java implementation of Earley’s efficient parsing algorithm
I found an old project of mine called Jerly. I wrote it in 2004-2005. I tried it in 2017 and it still works fine :) You can find it on GitHub.
Jerly is a Java implementation of Earley’s efficient parsing algorithm for lambda-free context-free grammars. To put it in a nutshell, it tells you if a word can be generated with a set of rules or not.
A nice JUnit tutorial
I started to use Java again (I haven’t touched it for 5 years…) and I found a very nice JUnit tutorial. Here it is: http://www.vogella.com/tutorials/JUnit/article.html .
Links
Force XMind to use Java 7
“XMind is the world’s coolest mind mapping software, the best way to brainstorm, the most efficient solution for saving your time, and powering your company.” (source)
Maybe it’s not the best but I like it :) And it has a free version, which is perfect for my needs.
Problem
I prefer to use the official Java version that I download directly from Oracle. However, I noticed that XMind tends to use some older versions of Java (OpenJDK, etc.). How to tell XMind which Java to use?
After starting XMind, you can verify which Java it uses. Go to: Help -> About XMind, and click on the button Installation Details. Finally choose the tab Configuration. Here find the line “-vm” and check its value in the next line. This is the virtual machine XMind has found.
Solution
Edit xmind.ini and add this line to the top:
-vm /opt/java/bin/java
In my case “/opt/java/bin/java -version” produces the following output:
java version "1.7.0_21" Java(TM) SE Runtime Environment (build 1.7.0_21-b11) Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
BeautifulSoup for Java = jsoup
BeautifulSoup is an HTML parser library for Python.
If you want to use a similar library in Java, try jsoup. Cookbook here.
Start vuze with Java 7
Problem
I installed Oracle Java 7 to /opt/java. When I start vuze and check Help -> About, it says it is still using Java 6. Hmm…
Solution
Edit the vuze launch script:
JAVA_PROGRAM_DIR="/opt/java/bin/" # Add the trailing slash!
Don’t use Java in a nuclear facility
From the license of Java, Section 3:
“… You acknowledge that Licensed Software is not designed or intended for use in the design, construction, operation or maintenance of any nuclear facility. …”
Found here.
Update (20130318)
It seems the original text has changed. The new version says: “You agree that neither the Software nor any direct product thereof will be exported, directly, or indirectly, in violation of these laws, or will be used for any purpose prohibited by these laws including, without limitation, nuclear, chemical, or biological weapons proliferation.”
Hmm, I preferred the old one :(
Install the Java Cryptography Extension (JCE)
In order to install the Java JCE, follow these steps:
- The first obstacle is how to download JCE :) Where the hell is it? Visit the Java HQ and click on Java SE Downloads in the top right hand corner. Scroll down to the bottom and there it is; perfectly hidden so that no one can find it. The file is called
jce_policy-6.zipand it’s only 9 KB. - Extract the downloaded ZIP. You’ll have two JAR files:
local_policy.jarandUS_export_policy.jar. - Locate your Java installation and enter the “jre” directory. In my case its path is
/opt/jdk1.6.0_24/jre. I will refer to this directory asJRE. - Enter
$JRE/lib/securityand make a backup of the fileslocal_policy.jarandUS_export_policy.jar. Then replace them with the ones from the JCE ZIP file.
You must be logged in to post a comment.