JUnit Tutorial (2) – Annotations

This article contains JUnit annotations and examples for showing how to use them. Annotations enables us to use any method names without following any conventions. Actually, it has becomes a very popular way for a lot of projects, framework, etc. You may ask questions like: How to skip a test case in Junit? How to … Read more

Java Calculate Square Root Without Using Library Method

If we want to calculate square root, we can use Math.sqrt() method. It is simple. Now do you know how to write such a method by yourself? Here is the equation you need. The first sqrt number should be the input number / 2. Using the equation, we can come up with a Java Square … Read more

JUnit Tutorial (1) – Use JUnit under Eclipse

Introduction and Installation JUnit is the defacto standard for unit testing. JUnit is part of Eclipse Java Development Tools (JDT). So, we can either install JDT via Software Updates site, or download and install Eclipse IDE for Java Developers. Using JUnit in Eclipse Environment 1. Create a project and create a class. This should contains the method you want … Read more

Why do we need software testing?

Why do we need to test our program? When people talk about the importance of software testing, common examples they give frequently are military software, aircraft, etc. That is not concrete enough to understand why we need to test our software. Here I provide an example from daily programming work. You don’t need to work … Read more

Java Method to Shuffle an Array

How to shuffle an array in Java? There are two approaches to shuffle an int array(randomizes the order of the elements in an array), one is to use the Collections.shuffle() method, the other is to manipulate array elements. Approach 1: Shuffle elements in an array This is flexible, and easy to be changed to fit … Read more

Eclipse JDT Tutorial – Dynamic load Java projects to workspace

In previous post, I have shown how to use Java Model to create a new project, access an existing project, and dynamically import/load an existing project directory into workspace. The real question is if we want to parse a large number of projects(e.g. 1000) and those projects do not have .project file under it’s directory. … Read more

Add JDBC Database Connection to an Eclipse Plug-in

When you add JDBC database connection to an Eclipse plug-in, you may get the following error message: Error message(partial): java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410) at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107) at java.lang.ClassLoader.loadClass(Unknown Source) You may check again and again if the JDBC library has already added to the build path. That will not work, because JDBC … Read more

Eclipse JDT tutorial – Java Search Engine – A Simple Working Example

This article belongs to Eclipse JDT Tutorial Series. JDT Java Search Engine provides a function to quick search Java projects in the workspace for Java elements, such as method references, field declarations, implementors of an interface, etc. There are mainly 4 steps involved with a search: Create a search pattern Create a search scope Define … Read more

Eclipse JDT tutorial – Java Model – Concept and Design

This article belongs to Eclipse JDT Tutorial Series. What is Java Model? The Java model is the set of classes that model the objects associated with creating, editing, and building a Java program. It is defined in org.eclipse.jdt.core package. Accordingly, non-API classes are defined in package org.eclipse.jdt.internal.core. You will see their relation in next section. … Read more

Eclipse RCP Tutorial: Commonly-used Eclipse Workbench Extension Points

1. What is a Workbench? The following diagram is from eclipse official site. In brief, when you open your eclipse, what you see is a workbench. It consists of a menu bar, a tool bar, a page which is composed by one or more views/editors. 2. Commonly Used Extension Points The following are commonly or … Read more