Java Design Pattern: Observer

In brief, Observer Pattern = publisher + subscriber. Observer pattern has been used in GUI action listener. Swing GUI example shows how action listener works like an observer. The following is a typical example about head hunter. There are two roles in this diagram – HeadHunter and JobSeeker. Job seekers subscribe to a head hunter, … Read more

An example of C++ dot vs. arrow usage

vs. Overall, dot(.) is for object itself, arrow(->) is for pointer. A good example worth a thousand words. The following example should be a good one. #include <iostream>   using namespace std;   class Car { public: int number;   void Create() { cout << "Car created, number is: " << number << "\n" ; … Read more

Eclipse JDT tutorial: Parse a Java method by using ASTParser

This tutorial belongs to Eclipse JDT Tutorial Series. ASTParser can use its setKind() method to set source to be parsed as a compilation unit, single expression, a sequence of statements, or a sequence of class body declarations. parser.setKind(ASTParser.K_COMPILATION_UNIT);parser.setKind(ASTParser.K_COMPILATION_UNIT); Any of those four can not handle a single independent method. This is not pleasant. Following the … Read more

Eclipse JDT Tutorials

JDT is supported by 3 pillars: Java Model, Search Engine, and AST. It is a handy tool for manipulating Java source code. However, the handy tool comes with a steep learning curve even for an experienced Java developer and there are just not enough proper code examples. This page summarizes the code examples for using … Read more

A complete standalone example of ASTParser

This example belongs to Eclipse JDT Tutorial Series. Normally, Eclipse JDT is used in a plug-in environment. This is the normal situation in which we deal with each project in the workspace. However, if we want to parse a large amount of java file, this approach may not be good, since it is not easy … Read more