The first Training at JAOO 2010 was held by Martin Odersky in Scala. Scala is truly an interesting new programming language, it runs on top of the JVM, but brings so much new programming technique that is not possible with the existing Java language.
It was a truly refreshing talk, but also a sadly realization that the evolution of the Java language has really slowed down since the release of Java 5. The difference between Java 6 and Java 5 is mostly a faster JVM, that is not bad, but on the functional side of new language technique is quite depressing to see such a short list of new feature. And it is not getting better. A couple of days ago a checked out the Oracle web page of new programmatic feature in Java 7 one can see the list is short.
http://www.oracle.com/technetwork/java/7-138633.html
And what is happening the other main stream programming corner at Microsoft? Well they have not been lazy. On could right fairly argue that C# has been become a more advance language than Java. So with this in mind, I'm really looking forward to participate the Training. So what did Martin talk about. Well, the Scala language is really huge, so the talk for 4 hours, did not covered all parts, but one thing is sure. Looking at Scala is almost like learning a new language. For you out there, that have not started looking at Scala I only got one question for you:
Do you want to program Java 6 or 10? See the complete video of Martin Odersky. http://www.scala-lang.org/node/1305
"If I were to pick a language to use today other than Java, it would be Scala"
by James Gosling, creator of Java
http://www.adam-bien.com/roller/abien/entry/java_net_javaone_which_programming
"I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I’d probably have never created Groovy."
by James Strachan, creator of Groovy
http://macstrac.blogspot.com/2009/04/scala-as-long-term-replacement-for.html
"Scala, it must be stated, is the current heir apparent to the Java throne. No other language on the JVM seems as capable of being a "replacement for Java" as Scala, and the momentum behind Scala is now unquestionable. While Scala is not a dynamic language, it has many of the characteristics of popular dynamic languages, through its rich and flexible type system, its sparse and clean syntax, and its marriage of functional and object paradigms."
Charles Nutter, creator of JRuby
http://blog.headius.com/2009/04/future-part-one.html
I'm dedicated agile security architect/system architect/developer with specialty of open source framework.
October 3, 2010
August 5, 2010
Opening New Window in Ubuntu 10.04 Does Not Get Focused
I had a really annoying problem after installing Ubuntu 10.04 which I found a solution to today. The problem was whenever I was opening a new window that new opened window was not focused. Quite annoying! The solution is following:
- System → Preferences → CompizConfig Settings Manager
- Select General in the right hand window.
- Select General Options.
- Select the Focus & Raise Behaviour tab.
- Change Focus Prevention Level to Off.
July 5, 2010
Your First Cup of Coffee
A friend of mine asked me to provide a simple getting started guide for a first time Java programmer and it so happened it were other people that also wanted the same thing, so all of you out there here it comes, a simple learning by example guide in Java.
The example is a simple Web application that do simple Create, Retrieve, Update and Delete (CRUD) operation against a MySQL database.
Before starting writing you need to install the following on your system.
That's it! That took 3 minutes on a modest Internet connection. Are you still stuck on downloading the files on your Windows machine? And thereafter looking forward to reboot you system after each installation?
The Eclipse Ubuntu installation bundle is sadly quite old and therefore it is better to download the zip file manually and extracted it anywhere of you liking and run eclipse.exe (eclipse) in the eclipse folder.
Now lets create your database. Start the MySQL Query Browser and right click in the Schemata dockable window and then select Create Schema.... Enter simpledb.
Now double click on the newly created schema and then right click again to create a new table.
From here you can take several paths, either create a new project with maven archetype 'simple-webapp' (http://www.sonatype.com/books/mvnex-book/reference/web-sect-creating-project.html) or you can install the m2eclipse plugin (http://m2eclipse.sonatype.org/installing-m2eclipse.html) and create your project from Eclipse. Here, I will hopefully, choose the easiest way and do it manually, since we only will be needing two source files, where one will be empty – web.xml and index.jsp.
Now create you Maven Project Object Model file pom.xml in first-coffee/pom.xml
Now create your first-coffee/src/main/webapp/WEB-INF/web.xml
And finally your dynamic web page (first-coffee/src/main/webapp/index.jsp), where all your work be done.
To test your application, simply start the Maven built in web server, from your first-coffee directory.
Now open your web browser and enter the address http://localhost:8080/first-coffee/.
If you want to continue to further evolve this simple example, you can leave the jetty server running and simply refresh you web server, after saving your changes.
The example is a simple Web application that do simple Create, Retrieve, Update and Delete (CRUD) operation against a MySQL database.
Before starting writing you need to install the following on your system.
- Java 1.6 SE (http://java.sun.com/javase/downloads/index.jsp)
- MySQL Server and Query Browser (http://dev.mysql.com/downloads/)
- Maven2 (http://maven.apache.org/download.html)
- Eclipse EE 3.5.2 (http://eclipse.org/downloads/)
$ sudo apt-get install sun-java6-jdk mysql-server mysql-query-browser maven2
That's it! That took 3 minutes on a modest Internet connection. Are you still stuck on downloading the files on your Windows machine? And thereafter looking forward to reboot you system after each installation?
The Eclipse Ubuntu installation bundle is sadly quite old and therefore it is better to download the zip file manually and extracted it anywhere of you liking and run eclipse.exe (eclipse) in the eclipse folder.
Now lets create your database. Start the MySQL Query Browser and right click in the Schemata dockable window and then select Create Schema.... Enter simpledb.
Now double click on the newly created schema and then right click again to create a new table.
From here you can take several paths, either create a new project with maven archetype 'simple-webapp' (http://www.sonatype.com/books/mvnex-book/reference/web-sect-creating-project.html) or you can install the m2eclipse plugin (http://m2eclipse.sonatype.org/installing-m2eclipse.html) and create your project from Eclipse. Here, I will hopefully, choose the easiest way and do it manually, since we only will be needing two source files, where one will be empty – web.xml and index.jsp.
$ cd [your local workspace directory]
$ mkdir -p first-coffee/src/main/webapp/WEB-INF
Now create you Maven Project Object Model file pom.xml in first-coffee/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelversion>4.0.0</modelVersion>
<groupid>se.msc.example</groupId>
<artifactid>first-coffee</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>first-coffee Maven Webapp</name>
<url>http://www.msc.se/example</url>
<dependencies>
<!-- mysql jdbc driver -->
<dependency>
<groupid>mysql</groupId>
<artifactid>mysql-connector-java</artifactId>
<version>5.1.13</version>
</dependency>
<!-- test support -->
<dependency>
<groupid>junit</groupId>
<artifactid>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalname>first-coffee</finalName>
<pluginmanagement>
<plugins>
<!-- to compile with JDK 1.6 -->
<plugin>
<groupid>org.apache.maven.plugins</groupId>
<artifactid>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- built-in web server 'mvn jetty:run' -->
<plugin>
<groupid>org.mortbay.jetty</groupId>
<artifactid>maven-jetty-plugin</artifactId>
<configuration>
<scanintervalseconds>1</scanIntervalSeconds>
<stopkey>foo</stopKey>
<stopport>9999</stopPort>
</configuration>
</plugin>
</plugins>
</build>
</project>
Now create your first-coffee/src/main/webapp/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
</web-app>
And finally your dynamic web page (first-coffee/src/main/webapp/index.jsp), where all your work be done.
<%@ page import="java.sql.*" %>
<html>
<body>
<%
// Step 1: Load the JDBC driver.
Class.forName("com.mysql.jdbc.Driver");
// Step 2: Establish the connection to the database.
String url = "jdbc:mysql://localhost:3306/simpledb";
Connection conn = DriverManager.getConnection(url, "root", "root");
// Step 3: Do possible posted logic - Create, Update or Delete
if ("Create".equals(request.getParameter("submitCreate"))) {
String name = request.getParameter("Name");
Statement statement = conn.createStatement();
statement.executeUpdate("INSERT INTO Person (Name) VALUES ('" + name + "')");
} else if ("Update".equals(request.getParameter("submitUpdate"))) {
String personId = request.getParameter("PersonId");
String name = request.getParameter("Name");
Statement statement = conn.createStatement();
statement.executeUpdate("UPDATE Person SET Name='" + name + "' WHERE PersonId=" + personId);
} else if ("Delete".equals(request.getParameter("submitDelete"))) {
String personId = request.getParameter("PersonId");
Statement statement = conn.createStatement();
statement.executeUpdate("DELETE FROM Person WHERE PersonId=" + personId);
}
%>
<table border="1">
<tr>
<th>PersonId</th>
<th>Name</th>
<th>Action</th>
</tr>
<%
// Step 4: Load all content from table
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT PersonId, Name FROM Person");
while (rs.next()) {
%>
<!-- Here we display the content of the DB table. -->
<form action="index.jsp" method="get">
<input type="hidden" name="PersonId" value='<%=rs.getString("PersonId")%>' />
<tr>
<td><%=rs.getString("PersonId")%></td>
<td><input type="text" name="Name" value="<%=rs.getString("Name")%>" /></td>
<td>
<!-- Provide simple Update and Delete Action for each DB table row. -->
<input type="submit" name="submitUpdate" value="Update" />
<input type="submit" name="submitDelete" value="Delete" />
</td>
</tr>
</form><%
}
%>
<!-- Provide an empty row for creating new DB table row. -->
<form action="index.jsp" method="get">
<tr>
<td> </td>
<td><input type="text" name="Name" /></td>
<td><input type="submit" name="submitCreate" value="Create" /></td>
</tr>
</form></table></body>
</html>
To test your application, simply start the Maven built in web server, from your first-coffee directory.
$ mvn jetty:run
Now open your web browser and enter the address http://localhost:8080/first-coffee/.
If you want to continue to further evolve this simple example, you can leave the jetty server running and simply refresh you web server, after saving your changes.
July 1, 2010
Getting Started with Apache Camel and Prepare for Apache ServiceMix Deployment
Apache Camel is dream framework for any developers that is confronting with any type of integration task. What makes Apache Camel so great is:
The next best thing is that Apache Camel is a POJO based solution, which means that it can be deployed and ran in any deployment environment:
When talking of deployment and integration the most common question is. What about ESB? And this is also when Apache Camel shines. Apache Camel is fully supported by Apache Camel parent project Apache ServiceMix, that supports the industry standard Java Business Integration standard. The JBI specification has been criticized about being a slow way of developing integration software and in many aspect that is true, but with Apache Camel as core developing framework that is no longer true.
The reason to select an ESB platform to deploy your integration software is:
But one thing, that in my opinion, the Apache Camel homepage lack is good starting example of showing the above strength. So lets get started with NOT writing a production code example, but instead lets write a JUnit test case that you can debug, then you can continue of writing your production code.
In the below example I will also take into account that one day, you might want or NOT take the next step and move your Apache Camel code into a full blown ESB environment.
Lets first look at your Maven pom.xml.
To read more about all configuration options for the above endpoints, see http://camel.apache.org/components.html
An Apache Camel route can also be configured in a XML file, which is the natural choice since you want things to configurable and not static defined in a Java class, but more about in my next blog.
- Testability. It is design from the beginning to be a framework that going to support Test Driven Development. With this follows a fast development cycle, since all code can be debugged and executed from a simple JUnit test case.
- Solves the two foremost problem that an integrator faces:
- Seamless protocol crossing, i.e. no coding for fetching data from e.g. HTTP and forwarding it to JMS.
- Default implementation of Enterprise Integration Pattern (http://www.eaipatterns.com/toc.html) that is easy to extend and configure. If you are not familiar with EIP, I recommend you to take the time and read the EIP homepage or if you do not want to miss a thing read the complete book written by Hophe and Woolf (http://www.amazon.com/Enterprise-Integration-Patterns-Designing-Deploying/dp/0321200683).
The next best thing is that Apache Camel is a POJO based solution, which means that it can be deployed and ran in any deployment environment:
- Standalone Java Application
- Web Container
- J2EE Container
When talking of deployment and integration the most common question is. What about ESB? And this is also when Apache Camel shines. Apache Camel is fully supported by Apache Camel parent project Apache ServiceMix, that supports the industry standard Java Business Integration standard. The JBI specification has been criticized about being a slow way of developing integration software and in many aspect that is true, but with Apache Camel as core developing framework that is no longer true.
The reason to select an ESB platform to deploy your integration software is:
- Management. The ESB platform is specially design to manage integration programs.
- Redundancy and Scalability. A good ESB platform is specifically design to handle these issues when the load and uptime requirements increases.
But one thing, that in my opinion, the Apache Camel homepage lack is good starting example of showing the above strength. So lets get started with NOT writing a production code example, but instead lets write a JUnit test case that you can debug, then you can continue of writing your production code.
In the below example I will also take into account that one day, you might want or NOT take the next step and move your Apache Camel code into a full blown ESB environment.
Lets first look at your Maven pom.xml.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.msc.example</groupId>
<artifactId>camel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<!-- <packaging>jbi-service-unit</packaging> -->
<name>MSC Example :: Camel</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<servicemix-version>4.2.0</servicemix-version>
<!--
servicemix 4.2.0 ships with 'servicemix-camel', thats support camel
2.2.0
-->
<camel-version>2.2.0</camel-version>
<!--
'servicemix-camel' has a deviating version compared with 'camel-core'
-->
<servicemix-camel-version>2010.01</servicemix-camel-version>
<!-- supported version for tooling in servicemix 4.2.0 -->
<servicemix-jbi-plugin-version>4.3</servicemix-jbi-plugin-version>
</properties>
<build>
<pluginManagement>
<plugins>
<!-- to compile with JDK 1.6 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!--
Use version
$M2_HOME/lib/maven-<version>-uber.jar/org/apache/maven/project/pom-4.0.0.xml
-->
<configuration>
<source>1.6</source>
<target>1.6</target>
<!-- Plugin ignores default value 'project.build.sourceEncoding' -->
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<!--
Use version
$M2_HOME/lib/maven-<version>-uber.jar/org/apache/maven/project/pom-4.0.0.xml
-->
<configuration>
<archive>
<manifest>
<!-- To include versionnumber in MANIFEST.MF -->
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!--
creates the JBI deployment unit <plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>jbi-maven-plugin</artifactId>
<version>${servicemix-jbi-plugin-version}</version>
<extensions>true</extensions> </plugin>
-->
</plugins>
</build>
<dependencies>
<!-- servicemix camel core -->
<dependency>
<groupId>org.apache.servicemix</groupId>
<artifactId>servicemix-camel</artifactId>
<version>${servicemix-camel-version}</version>
<scope>provided</scope>
</dependency>
<!-- optional camel components -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<version>${camel-version}</version>
</dependency>
<!-- test support -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- version inherited from 'camel-core' -->
<version>3.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel-version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
package se.msc.example.camel;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
public class MyFirstCamelTest extends ContextTestSupport {
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("direct:start").to("file:///tmp?fileName=foo.txt").to("mock:result");
// another example, without mocking start endpoint
// from("http://camel.apache.org/http.html").to("file:///tmp?fileName=foo.txt").to("mock:result");
}
};
}
public void test_OK() throws Exception {
MockEndpoint result = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
result.expectedMessageCount(1);
// send somtething from 'direct:start'
String ls = System.getProperty("line.separator");
String txt = "Dummy Body åäö";
template.sendBody("direct:start", txt + ls + txt + ls + txt + ls);
// execute and assert above 'result.expectedMessageCount(1);'
result.assertIsSatisfied();
}
}
To read more about all configuration options for the above endpoints, see http://camel.apache.org/components.html
An Apache Camel route can also be configured in a XML file, which is the natural choice since you want things to configurable and not static defined in a Java class, but more about in my next blog.
June 28, 2010
Problem Running Eclipse on Ubuntu 10.04 (Lucid Lynx)
I have been using Ubuntu for some time and it is really a great OS, but it is amazing why it is always Eclipse that brings the most headache when upgrading Ubuntu. For a couple a days ago I upgraded to Ubuntu 10.04, and everything works smoothly until I started Eclipse 3.5 SR1, with bug fixes I have previously described.
http://magnus-k-karlsson.blogspot.com/2009/11/problem-running-eclipse-in-ubuntu-910.html
This time the solution was to upgrade to Eclipse 3.5 SR 2 (Galileo), without the above bug fix. But thereafter m2eclipse gave me some problem, but now it seams to work after reinstalling m2eclipse and following the guideline in
http://m2eclipse.sonatype.org/installing-m2eclipse.html
“Note about 0.9.8 Workspace Incompatibility: If you are using m2eclipse 0.10.0 with a workspace that contains projects created under m2eclipse 0.9.8, you must remove the workspaceState.ser file. The workspaceState.ser file is located within the workspace directory in $workspacedir/.metadata/.plugins/org.maven.ide.eclipse/workspaceState.ser. If you remove this file, m2eclipse 0.10.0 will regenerate it as needed.”
http://magnus-k-karlsson.blogspot.com/2009/11/problem-running-eclipse-in-ubuntu-910.html
This time the solution was to upgrade to Eclipse 3.5 SR 2 (Galileo), without the above bug fix. But thereafter m2eclipse gave me some problem, but now it seams to work after reinstalling m2eclipse and following the guideline in
http://m2eclipse.sonatype.org/installing-m2eclipse.html
“Note about 0.9.8 Workspace Incompatibility: If you are using m2eclipse 0.10.0 with a workspace that contains projects created under m2eclipse 0.9.8, you must remove the workspaceState.ser file. The workspaceState.ser file is located within the workspace directory in $workspacedir/.metadata/.plugins/org.maven.ide.eclipse/workspaceState.ser. If you remove this file, m2eclipse 0.10.0 will regenerate it as needed.”
June 25, 2010
Getting Starting with Google Web Toolkit, GWT, Development
To get started first install appropriate plug-in for your IDE, in this article we will use Eclipse, but there are other great plug-in for other IDE as well.
Eclipse GWT plugin
http://code.google.com/eclipse/docs/download.html
One of the biggest difference between GWT 1.* and 2.* is the ability to debug and run your GWT application without the need to render/compile it. Now you can directly run/debug your GWT Java code without the time consuming compile step. But to do this you first need to install a plug-in to your web browser.
GWT Development Mode plugin for Firefox, IE and Safari
http://groups.google.com/group/google-web-toolkit/msg/51c5a09630ac61dc
After restarting Eclipse and your Web browser you are now ready to start developing. Begin with creating a new project and select Google → Web Application Project.
Enter project details. In this article we will not create a Google App Engine Application, which is a platform for writing cloud application for the Google cloud platform. To read more about Google App Engine, visit http://code.google.com/appengine/.
After finishing creating your project. Lets fire it up and start debug the complete GWT project. The GWT team has already configured a default debug goal. So simple press the debug icon in the Eclipse toolbar.
Now is a URL presented in the Eclipse Console output View. Right click on that URL and select Copy. Paste the URL in your web browser.
Now lets set a breakpoint in your application and the enter a name in your browser and click submit. And now you are debugging your first GWT application.
Eclipse GWT plugin
http://code.google.com/eclipse/docs/download.html
One of the biggest difference between GWT 1.* and 2.* is the ability to debug and run your GWT application without the need to render/compile it. Now you can directly run/debug your GWT Java code without the time consuming compile step. But to do this you first need to install a plug-in to your web browser.
GWT Development Mode plugin for Firefox, IE and Safari
http://groups.google.com/group/google-web-toolkit/msg/51c5a09630ac61dc
After restarting Eclipse and your Web browser you are now ready to start developing. Begin with creating a new project and select Google → Web Application Project.
Enter project details. In this article we will not create a Google App Engine Application, which is a platform for writing cloud application for the Google cloud platform. To read more about Google App Engine, visit http://code.google.com/appengine/.
After finishing creating your project. Lets fire it up and start debug the complete GWT project. The GWT team has already configured a default debug goal. So simple press the debug icon in the Eclipse toolbar.
Now is a URL presented in the Eclipse Console output View. Right click on that URL and select Copy. Paste the URL in your web browser.
Now lets set a breakpoint in your application and the enter a name in your browser and click submit. And now you are debugging your first GWT application.
April 18, 2010
Administrating JBoss MBean From the Command Line Using twiddle
In production environment you usually monitor and administrate the JBoss Application Server through ssh and command line and this is adequate when starting, stopping and reading logs, but when you want to inspect, see status and change MBean values, the command line alternative is quite limited and since the MBean architecture is central in JBoss one really wants to use the JMX-console. The JMX-console is not the most user friendly tool, but has improved with JBoss 5 and the Web Console.
But there is an alternative if you want (or must) stick with the command line alternative – twiddle. The twiddle tool is not new and has been around since JBoss 4.3. And here follows a short walk through by examples.
To print out help information use:
Here you see the most imported commands: info, get, invoke and setattrs.
To get attribute and operation info:
To get attribute value:
To invoke an operation:
But there is an alternative if you want (or must) stick with the command line alternative – twiddle. The twiddle tool is not new and has been around since JBoss 4.3. And here follows a short walk through by examples.
To print out help information use:
$ ./twiddle.sh -h
Here you see the most imported commands: info, get, invoke and setattrs.
To get attribute and operation info:
$ ./twiddle.sh info jboss:service=JNDIView
To get attribute value:
$ ./twiddle.sh get jboss:service=JNDIView StateString
To invoke an operation:
$ ./twiddle.sh invoke jboss:service=JNDIView list true
Subscribe to:
Posts (Atom)





