Friday, October 30, 2015

How to use embedded Java DB (Derby) in maven project

For now, Java DB is actually just Apache Derby with a different name.  In the following of the article, we will call it Derby. It  comes with JDK installation. ( Although what's normally used in maven project is not the same binary install in local JDK directory) Using embedded Java DB means...

Tuesday, October 27, 2015

How to use Java parallel Fork/Join framework - Hello world example

Since Java 7, fork/join framework has be introduced in to Java API. The main difference between fork/join and other multi-threading mechanism like executor or thread pools is that: traditional multithreading focuses on "let every task has the chance to run simultaneously", fork/join framework focuses...

In practical the most used thread methods before thread.start()

The java.lang.Thread class is the core of the low level multi-threading in Java. Almost every java developer know start a new thread is very simple. first, create a instance from Thread or subclass of Thread, then call start() method of that instance. WALA, the new thread is in runnable state and ready to run. In a nontrivial project, very possibly there are some other methods need to be invoked after...

Monday, October 19, 2015

Understand Java primitives wrapper class comparison

Java has a wrapper class for every primitive types, Such as  Integer to int, Boolean to boolean, Short to short, Character to char and etc. Also we all know that when compare two java objects,  "a==b" only  check if a and b refer to the same objects, while "a.equals(b)" normally can compare the real value that instance a and b really presents. That is true. So in short, always use equals()...

Friday, October 9, 2015

Use Java regular expression for multiline string

There are 2  points worth to point out when using Java regular expression to parse multi-line string. The period "." doesn NOT match line break, unless you set extra flag to your pattern instance. The "^" and "$" mean different in single(default) and multi line mode. 1. period "." does not match line break Usually the period "." is used to match any thing, but by default it doesn’t match...

Case-insensitive regular expression in Java

The java.util.regex.Pattern has several flags which are very helpful.  One of them is CASE_INSENSITIVE Just add this flag when creating pattern instance.  Everything else follows normal regex usage. Here is a hello world level demo for case-insensitive regular expression in Java.package com.shengwang.demo;import java.util.regex.Matcher;import java.util.regex.Pattern;public class RegexCaseInsensitive...

The basic regular expression API in Java

The basic regular expression in Java involved 2 classes, java.util.regex.Pattern and  java.util.regex.Matcher. The most basic usage has 3 steps. Create a pattern instance Create a matcher instance from pattern instance. The String  under test is set in this step Check match result using methods from matcher The following demo code is a hello world level example on how to use Java regular...
Powered by Blogger.

About The Author

My Photo
Has been a senior software developer, project manager for 10+ years. Dedicate himself to Alcatel-Lucent and China Telecom for delivering software solutions.