28 March, 2013

Mission Accomplished!!!

   Today I've passed "Oracle Certified Professional Java EE Business Component Developer" exam with score 90%. I used the most standard suite of OCPJBCD materials:
   This should be enough, but you can also read some other books eg. "EJB 3 in Action" or "Enterprise JavaBeans 3.1" and remeber to visit Big Moose Saloon

Finally another OCPJBCD question, which I sadly screwed up:

A Singleton bean can expose which of the following client views?
  1. An asynchronous message destination
  2. Web Service view
  3. Message Driven
  4. EJB 2.x Remote home
  5. EJB 3.x local business
  6. JPA Entity view
Do you know? The correct answer is 2,5.

27 March, 2013

Source code syntax highlighting

   Alex Gorbatchev JavaScript Syntax Highlighter JavaScript Library initialization:
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'></script>
<script language='javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>  

This code must be added to <head> section of Blogger's template . Now we can easily use it with <pre> tag:
<pre class="brush: java">
// Comment
public class SomeClass {
    public void someMethod() {
        System.out.println("Hello World");
    }
}
</pre>

Asynchronous methods executed not via Container

   I’m preparing to OCPJBCD currently, so I will start my blogging with topic related to this exam. It is about using asynchronous methods.
package pl.mariusz.marciniak.bean;

import javax.annotation.Resource;
import javax.ejb.Asynchronous;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;

@Stateless
public class AsynchMethodBeanTest {
 
 @Resource
 SessionContext beanContext;
 
 @Asynchronous
 public void asynchMethod() {
  try {
   Thread.sleep(1000);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
 }
 
 public void invokeMethod() {
  long time = System.currentTimeMillis();
  asynchMethod();
  System.out.println("Execution time :"+(System.currentTimeMillis()-time));
  
 }
}

Do you know what will be the output, if we execute invokeMethod method?
...
...
...

The answer can be "Execution time :1001". For sure it will be value not lower than 1000. It is because execution is out of the container, so it is not asynchronous in fact. How we can change it? We can replace invokeMethod with one below.
public void invokeMethod() {
  long time = System.currentTimeMillis();
  beanContext.getBusinessObject(AsynchMethodBeanTest.class).asynchMethod();
  System.out.println("Execution time :"+(System.currentTimeMillis()-time));
 }
Now it took 2 ms on my machine. Hope you like it.

3,2,1... launch

So here I'm, starting my brand new blog. A little bit late, but I hope to find more time in future to post regulary. This blog will be mainly about programming in Java, as it is strictly related to my job and hobbies.

For the BIG START, in a coding style, I will say Hello World. This will be to easy to do in Java, so here is  Brainfuck version :)


++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.