RPM builder quick steps

Step 1, install rpm tools
[sourcecode]yum install rpmdevtools rpmlint[/sourcecode]

Step 2, set up working directory
[sourcecode]rpmdev-setuptree[/sourcecode]

Step 3, create and edit the spec file
[sourcecode]
cd rpmbuild/SPECS
rpmdev-newspec
[/sourcecode]

Miscellaneous commands:

show environment variables
[sourcecode]rpm –showrc[/sourcecode]
show specific variable
[sourcecode]rpm –eval %_usr[/sourcecode]

Procedures to simulate RPM building with Mock
– Build source rpm
[sourcecode]
rpmbuild -bs SPECS/myproject.spec
[/sourcecode]

– Mock the build, i.e., testing the build in an isolated building environment simulating a specific platform (Redhat or Fedora etc.)
[sourcecode]
mock -r platform_name SRPMS/myproject.src.rpm
[/sourcecode]

– If it’s a multiple-project task, mock install the first project first, and then mock build the 2nd, i.e.,
[sourcecode]
mock -r platform_name –install /mock_path/myproject.rpm
mock -r platform_name SRPMS/myproject2.src.rpm
[/sourcecode]

Change Java environment in CentOS

See this blog

To install/ register a JVM use the following
/usr/sbin/alternatives --install "/usr/bin/java" "java" "/usr/java/default/bin/java" 2
/usr/sbin/alternatives --install "/usr/bin/javac" "javac" "/usr/java/default/bin/javac" 2

And to configure systemwide changes use
/usr/sbin/alternatives --configure java
/usr/sbin/alternatives --configure javac

Singlton vs Static class/method

Based on Wikipedia: “Note the distinction between a simple static instance of a class and a singleton: although a singleton can be implemented as a static instance, it can also be lazily constructed, requiring no memory or resources until needed. Another notable difference is that static member classes cannot implement an interface, unless that interface is simply a marker. So if the class has to realize a contract expressed by an interface, it really has to be a singleton.”

Compare Java, C++ and PHP class features

Java, C++ and PHP all support similar OOP concepts like class/object. Sometimes it can be frustrating, however, for programmers to apply similar OOP thinking into different languages. The reason is that there are some subtle differences between them in terms of OOP design, besides obvious language syntax difference. By doing the apple-to-apple comparison, one can remember those features much better. Here I am starting to compile the list of OOP features that are different between Java, C++ and PHP. Hopefully this list can be more comprehensive as time goes by.

1. Class method

1.1 Method overloading
Java and C++ class can have multiple methods sharing the same name but with different parameter signatures, i.e., method overloading. Unfortunately, PHP can’t.

A consequence is that Java and C++ throws error when calling a class method without matching its parameter signature, while PHP will just take it happily without warning. Such loose behavior of PHP can surprise Java programmers. For example, the following PHP code runs just fine.

class MyTest
{
  public function display($id)
  {
    return $id;
  }
}
$t = new MyTest();
echo $t->display("hello", "world");

1.2 Default parameter
PHP, C++ support default parameter values in method, while Java doesn’t. Java programmers may want to use the Builder Design Pattern instead.

1.3 Static method
While Java can call a static class method using either a class name or an object instance, PHP and C++ have to use the official class name ONLY.
Another minor syntactic difference is that, Java use “.” while PHP and C++ use “::” as the delimiter.