Wednesday, 29 January 2014

1Z0-807 Java EE 6 Enterprise Architect Certified Master Exam

follow-up of [2]

Pfew! Made it! Woohoo! I had answered 73% of questions correctly, and I needed 71%. I should've studied more.

It is Multiple-Choice, and some of the wrong possible answers are really quite close to correct.

Then again, who has to answer a Architectural Question in their business careers in less than 2.5 minutes on average, really?

On to the next step, the Assignment!!

The exam

Most of the exam questions were regarding business use cases.

The exam questions can be broadly separated into three distinct categories:
use cases
of imaginary companies seeking to change/re-evaluate (a part of) their current outdated infrastructure in some fashion
questions on design patterns
when to use them, what their characteristics are, etc. *)
questions on JEE technologies
when would you apply which technologies, given some Non-Functional Requirements (NFR)

*) Seems the books "Core J2EE Patterns", "Real World Java EE Patterns: Rethinking Best Practices" and "Design Patterns: Elements of Reusable Object-Oriented Software" really did help, and were fascinating reads in and of themselves.

References

[1] 1Z0-807 Java EE 6 Enterprise Architect Certified Master Exam
http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0-807
[2] Architect Enterprise Applications with Java EE - Course
http://randomthoughtsonjavaprogramming.blogspot.nl/2013/09/architect-enterprise-applications-with.html

Tuesday, 21 January 2014

Simple Logging

Had a Dickens of a time, getting logging to work. I thought it would be as simple as assigning a ConsoleHandler to my logger.

Turns out that there's a Loglevel on the ConsoleHandler as well, and it is set to INFO level messages by default.

Just setting the log level on the Logger itself to Level.ALL is just not enough.

The example here is sufficient for the most basic logging of simple one-class Hello-world applications.

Of course, you can always use System.out.println statements instead for simple one-class applications, but I think it's a bad habit to get into.


Configuration


Logging configuration can be done by means of a properties file.[1][2]

The properties file can be added during the startup as VM parameters, for example -Djava.util.logging.config.file=/home/mrbear/NetBeansProjects/jtail/logging.properties.

If no properties file is provided, the default is "lib/logging.properties" in the JRE directory.[2] The default file will only show INFO messages.

The following example will show all logging all of the time.

For information on programmable logging (Class-based), see the references.

The Global Logger

To make logging even in simple cases, as easy as possible, the global logger was introduced and in Java 7 it is easily referenced.
System.out.println("x=" + x);
Can therefore be replaced by:
Logger.getGlobal().finest("x=" + x);
Unfortunately, you still have to set the LogLevel appropriately, similarly as displayed in the first code example above.

Update 2015/03/26: added the Global logger info.

References

[1] Java Logging - Configuration
http://tutorials.jenkov.com/java-logging/configuration.html
[2] LogManager - Javadoc
http://docs.oracle.com/javase/7/docs/api/java/util/logging/LogManager.html

Tuesday, 14 January 2014

Installing JDK in Fedora Core

Seems to work fine. I am writing it down here, because I do not do it often, and I keep forgetting the steps.

Installing java


I have switched over to using openjdk. It seems to be pretty stable and standard in Fedora Core.

The openjdk-7-jre package contains just the Java Runtime Environment
yum install java-1.7.0-openjdk
The actual Java Development Kit can be installed as below.
yum install java-1.8.0-openjdk-devel
Call me weird, but I find it confusing to name both packages "openjdk", but then, that's the name of the thing.

Switching javac

If I try "alternatives --config javac", I get.


There are 2 programs which provide 'javac'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.x86_64/bin/javac
 + 2           /usr/lib/jvm/java-1.8.0-openjdk.x86_64/bin/javac

Enter to keep the current selection[+], or type selection number: 

Switching java


If I try "alternatives --config java", I get.


There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java

Enter to keep the current selection[+], or type selection number: 

I need to install the Oracle JDK, that is as simple as downloading the rpm and installing it with "rpm i jdk-7u13-linux-x64.rpm".

Then, I am required to set a symbolic link using the 'alternatives --install' commandline. See [1] for more information on that.

Then, I can set the default using "alternatives --config java" again.

[root@localhost Downloads]#  alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.5.0-gcj/bin/java
*+ 3           /usr/java/jre1.7.0_45/bin/java

Enter to keep the current selection[+], or type selection number: 
Updated 22 April 2014: added OpenJDK, removed specifics regarding Oracle

References

[1] Installing Sun Oracle Java JDK on Fedora, Centos, Redhat and RHel
http://www.if-not-true-then-false.com/2010/install-sun-oracle-java-jdk-jre-7-on-fedora-centos-red-hat-rhel/
Java - FedoraProject
http://fedoraproject.org/wiki/Java
OpenJDK
http://openjdk.java.net/install/


Tuesday, 7 January 2014

Model-View-Controller

I have always had a problem understanding the Model-View-Controller pattern. Perhaps because I always thought the Controller should be in between the Model and the View. In reality, there are flows between all the different components.

Date and Time


One of the things that in my mind would be a perfect example is Date and Time. The reason that I think it is an excellent example, is the way the Model part is exceedingly simple, and the View part is exceedingly complex. The Model part is nothing more or less than a Long indicating the number of milliseconds since Jan 1, 1970 GMT. The View part is split up into years, months, days, hours, minutes, seconds, milliseconds, timezone, daylight savings time, leap years, and God knows what else. While the Model part is simple and convenient for a computer, the View part is complex, but required if you want your date/time to be meaningful to your users.


References


Wikipedia: Model-View-Controller
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller