Compile and Run Java in Command Line with External Jars

The following example shows how to compile and run Java program in command line mode with external jars. It is developed under Linux. 1. Compile & Run Java Program Without External Jar Let’s create a simple hello world program “”. public class helloworld{ public static void main(String[] args){ System.out.println("Hello!"); } }public class helloworld{ public static … Read more

How to Deploy Spring Project to Live Server

Assuming you have created a dynamic web project under Eclipse, and you have tested your project, now you want to deploy the Spring project to a live server. The project runs on Tomcat and it interacts with MySQL database. How to correctly deploy your project? To deploy the project, you need to build a .war … Read more

How to install Latex on Ubuntu 14.04LTS

You may often get error messages like “missing subfigure.sty”, “missing url.sty”, or missing other .sty files. The problem is caused by missing packages. This post outlines the steps to correctly install latex on Ubuntu latest version 14.04LTS. It should also work for most previous other versions. 1. Install Latex on Ubuntu In the terminal, type … Read more

Install Tomcat 7 for Eclipse

As a web project runs on an HTTP server, a new server should be setup to hold the web project. Download Tomcat 7.0 here. Download the core Zip version, and unzip it to a directory (remember this directory). In your eclipse, create a new Server. Select the directory where you unzipped the tomcat. Run the … Read more

LeetCode – Generate Parentheses (Java)

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: “((()))”, “(()())”, “(())()”, “()(())”, “()()()” Java Solution 1 – DFS This solution is simple and clear. In the dfs() method, left stands for the remaining number of (, right stands … Read more

Convert Stream to Array in Java 8

To convert a Stream to an array, there is an overloaded version of toArray() method for Stream objects. The toArray(IntFunction<A[]> generator) method returns an array containing the elements of this stream, using the provided generator function to allocate the returned array. String[] stringArr = { "a", "b", "c", "d" }; Stream<String> stream = Stream.of(stringArr); String[] … Read more

Java Serialization

What is Serialization? In Java, object serialization means representing an object as a sequence of bytes. The bytes includes the object’s data and information. A serialized object can be written into a file/database, and read from the file/database and deserialized. The bytes that represent the object and its data can be used to recreate the … Read more

Spring HelloWorld Example Using Eclipse and Maven

This article illustrates how to do a Spring Hello World by using Eclipse and Maven. You should install eclipse and maven plugin first. 1. Set up a Maven Project Create a Maven project by using the Wizard. GroupId identifies the project uniquely across all projects, so we need to enforce a naming schema. ArtifactId is … Read more

Enhanced For-loop vs. forEach() in Java 8

Assuming you have the following list: List<String> list = Arrays.asList("a", "b", "c", "d", "e", "f");List<String> list = Arrays.asList("a", "b", "c", "d", "e", "f"); if you want to do something by using each element in a collection, there are two ways: 1) list.forEach(s -> System.out.println(s));list.forEach(s -> System.out.println(s)); 2) for(String s: list){ System.out.println(s); }for(String s: list){ System.out.println(s); … Read more

Deep Understanding of ArrayList.iterator()

iterator often cause problems, because developers often do not know how it works. The following code is from source code of ArrayList. One common problem is throwing java.util.ConcurrentModificationException. This exception is actually throw in the remove method. remove() has to be called after next(). if remove() is called before next(), the size of arraylist changes, … Read more

Java Varargs Examples

1. What is Varargs in Java? Varargs (variable arguments) is a feature introduced in Java 1.5. It allows a method take an arbitrary number of values as arguments. public static void main(String[] args) { print("a"); print("a", "b"); print("a", "b", "c"); }   public static void print(String … s){ for(String a: s) System.out.println(a); }public static void … Read more

Install Pandas Without Root Access

If you want to install Pandas on Linux (Ubuntu, Redhat, etc.), but you don’t have root access, the installation may take a while. This is just record how I did it. After trying various kinds of different ways, I finally use one command to install it. Download Anaconda: Change the download .sh file to … Read more