|
|
||
Andreas Schaefer's BlogJanuary 2005 ArchivesCertification or Indoctrination? Depends on You!Posted by schaefa on January 21, 2005 at 02:38 PM | Permalink | Comments (3)John Reynold's Blog discusses the question if the Java exams are helping you to learn Java or help the provider to indoctrinate their (marketing) philosophy. For me looking back on having passed the Microsoft Certified Software Engineer, some Microsoft beta exams as well as the Java Programmer and Developer exam I can say: It depends solely on you! I learned and passed the MCSE's 6 tests in 4 weeks and gained a waste knowledge about Windows, Networking and the web. All the exams helped me to gain a foundation of knowledge helping me today to solve many problems I could not do without. The advantage I gained through these tests did not come from the tests itself but from the chance to deal with the subject matter, to learn the stuff in depth and to consolidate the knowledge. This means that things I learned through the MCSE still helps me today developing Java programs. Many topics in Java, J2EE, web services etc are not knew and you can digest them easier if you know similar concepts or precursors of these technologies. What I am trying to say is the important point is that you learn for an exam and not that you pass the exam. This also means that you can learn without an exam but the exam is a nice test to see if you somewhat mastered the topic. Another way to test your knowledge is to participate in an open-source project and so I stopped taking any exams since I started to work for open-source projects. I met many developers that took the exam only to improve their resume. This maybe a good side effect of such an exam but I think this is short sighted and does not help any developer on the long run. At the end software engineers should learn every day to improve their knowledge and to secure their future. No company in this world can take away what you have learned even they fire you. Learn and have fun – Andy How to do Conditional Compilation with JavaPosted by schaefa on January 20, 2005 at 04:50 PM | Permalink | Comments (18)These instructions are a way to do conditional compilation with Java like the C/C++ #ifdef. In Java there is no preprocessor and so we need to work around this missing feature. This work around is using Ant's copy and filter feature to create the source with the different code in it. In this example I wanted to accomplish the following:
1. Add into your Java classes a start tag (like //[ifdef]) and an end tag (like //[enddef]) around the code in question. To include code for version 1: //[ifdef] import java.sql.ParameterMetaData; //[enddef]or
//[ifdef]
public byte[] getBytes(String parameterName)
throws SQLException {
...
}
//[enddef]
The // at the beginning of the tag ensures that this is still valid Java source code.To exclude code:
/* //[endef]
public byte[] getBytes(String parameterName) {
...
}
//[ifdef] */
2. To swap the used code for version 2 the start and end tag just have to be set to /* respectively */. In this case the included code is excluded and the excluded code in included. 3. Add a copy-n-filter task in your Ant build script. There the source coded will be copied away and the filter tags are replace with the actual value. For version 1 the start / end tag will vanish and for version 2 they will be substituted with /* and */. Attention: the source code is copied into two different root directory one for version 1 and the other for version 2. Because Ant tries to avoid copies if the file does not have changed this can lead to having the wrong version of code in your target directory. This is an Ant script snippet:
<copy todir="${src.dir}/${version}">
<fileset dir="${src.dir}/java">
<include name="**/*.java"/>
</fileset>
<filterset begintoken="//[" endtoken="]">
<filter token="ifdef" value="${ifdef.token}"/>
<filter token="enddef" value="${enddef.token}"/>
</filterset>
</copy>
4. Set the start / end tag token. Note that the start / end tag token are set at the end to their default value only when not already set.
<condition property="ifdef.token" value="/*">
<equals arg1="${compile.to.version.1}" arg2="false"/>
</condition>
<condition property="enddef.token" value="*/">
<equals arg1="${compile.to.version.1}" arg2="false"/>
</condition>
<!-- If not set already make sure that they are defined but empty -->
<property name="ifdef.token" value=""/>
<property name="enddef.token" value=""/>
If the Ant script is started without compile.to.version.1 set to false it will compile the code to version 1. If the parameter is set to false it will compile to version 2. This can be accomplished this way:
ant -Dcompile.to.version.1=false build 5. Make sure that you compile from the right directory:
<javac ...
>
<src path="${src.dir}/${version}"/>
</javac>
I hope this will help you in the future – Andy | ||
|
|