[ Published in IT on 20 February 2013 ]
Before I begin please go to Java documentation and have Locale class reference opened. I know how we human beings hate going through javadoc generated content, but trust me it's not that complicated and it might serve you :)
Locale class:
- is a class that holds the data about the región and the language
- NumberFormat class can format currency, percentage, numbers if we pass it Locale instance
- DateFormat can later change the format of Date, the language according to data set in Locale etc.
Read more: Locale class explained (ResourceBundle, NumberFormat...)
[ Published in IT on 15 February 2013 ]
Deploying a HelloWorld to GAE is a piece of cake. Deploying a real - Maven based Jersey RESTful service developed in Eclipse - is totally different. When I say totally I mean: incomprehensively difficult, lack of documentation, losing 2 days in different tutorials that lead to nowhere - totally. For a Google service, at least.
I really didn't plan towrite this tutorial, but I got so frustrated while I was trying to start with GAE that I've decided to share it with U and have it as my own reference later. I will explain how to create a Maven project in Eclipse and deploy it to Google Engine. I am building a Jersey based RESTful web application, but whichever type of web application Maven can generate will do…
Read more: Deploying a Maven project (Jersey) to Google Application Engine (GAE)
[ Published in IT on 19 January 2013 ]
This tutorial explains how to send an ObjectMessage message from a Producer to ActiveMQ queue engine (Broker) in order to be consumed by
a Consumer/s. Producer and Consumer can be: inside the same program, different java programs and even on different machines. For this tutorial I've decided to create two java applications MQproducer and MQconsumer and run them on the same machine
ActiveMQ is installed on. Of course, you can have all three components distributed over different machines if you'd like.
When building highly scalable and distributed applications with high load, sooner or later, you'll bump into one
problem: the need of distributing processor and time consuming tasks over diffrent machines, applications etc.
ActiveMQ is a Job/Task/Message queue engine that enables
you to delegate the execution of complex and costly tasks to other applications or modules on the same or a different machine. ActiveMQ is based on JMS APIs which enable direct communication between two distributed java components/programs. Normally, JMS messages go directly from point/program A to point B, but in case of ActiveMQ all messages are sent from point A to ActiveMQ server and queued there so that they can be consumed later by the program B. If you've ever worked with Gearman then you'll find ActiveMQ quite similar to it. Big difference, though, is that ActiveMQ is an implementation of JMS and as such is java oriented.
Read more: ActiveMQ ObjectMessage tutorial
[ Published in IT on 02 January 2013 ]
This post is a tutorial how to build a simplest RESTful web service (the famous HelloWorld) in Java using Jersey and Maven as the build tool. I'll be building it in Eclipse, but will comment also how to do it in NetBeans
Since RESTful web services are rapidly pushing out the old and heavy-weight SOAP/WSDL based ones; Java, just like other technologies, provides a native support for building RESTful web services. This API is called Jax-RS.
I am not gonna explain what REST is,
or argue what REST isn't. I'll leave that to someone else...
Jersey is an implementation of previously mentionedJax-RS specification and it's darn simple and auto-magical and I believe a true winner when you want to build a web service on Tomcat / GlassFish / JBoss or any other Java web server/container without using a huge framework such as SpringMVC or Struts just to achieve this.
Read more: RESTful web services in Java using Jersey (using Maven's Jersey archetype)
[ Published in IT on 18 December 2012 ]
In this post you'll find out what are your options when it comes to changing the url on the client side without causing the browser
to refresh. You'll also find out how to enable indexing of AJAX generated html content and in the end of the post... Let me just say that the third part is a surprise...
So, URL is read only. You can't manipulate the URL with Java Script without causing a new request. You guessed it, security reasons.
Take for example an url www.domain.com?var=true. If you manipulate the window.location in JS (I do it in dev. tools console) like:
window.location = "www.domain.com?var=false"
the browser will automatically make a new request and all internal state of the current application (JS variables, closures...) gets lost.
There is a solution to this problem and as you will see (if you pay attention) it's excesively used all around the web...
Read more: History API, rewriting URL without reloading and indexing ajax content
[ Published in IT on 08 December 2012 ]
This post belongs to a series of posts Oracle Certified Professional Java SE Programmer (formerly the Sun Certified Java Programmer) Certificate
In the part one of Thread synchronization I showed how synchronization of couple of threads works using the synchronization on the object these threads share.
It was simply a question of which thread entered its synchronization block first. So the first one in was obtaining the lock and the rest were
waiting on the monitor of that object to enter when the lock gets released (automatically by exiting the sync block).
Java gives us the opportunity to control more when we want our threads to wait and when we want them to wake up. Java provides us with 2 methods: wait() and notifyAll() inherited from java.lang.Object class and therefore available in all objects in java.
Read more: Thread synchronization using wait() and notifyAll()
[ Published in IT on 06 December 2012 ]
This post belongs to a series of posts Oracle Certified Professional Java SE Programmer (formerly the Sun Certified Java Programmer) Certificate
In simple multithreaded programs where threads don't depend on the work of each other there is no need to
synchronize threads. In that environment each and every thread can start whenever, can pause whenever, can access objects
whenever and can die whenever (A lot when evers ;) ). More often than not, in multithreaded environment, this is not the case...
This post will try to explain how to synchronize few threads working on/with the same object in order to optimize the performance in multithreaded environment.
For those preparing the SJCP exam this will be really valuable info because questions on Threads in general are very often in the exam...
Read more: Thread synchronization
[ Published in IT on 04 December 2012 ]
If you've never heard of httpOnly flag in the set-cookie response header then this post might be interesting for you. You know that one of XSS attacks will inject a java script that will get the domain's cookie and send it to the evil geek. All (ok, 99%) of modern browsers understand an extra flag httpOnly that can be set in the set-cookie: directive. This flag tells browser that Java Script cannot interact with the cookie meaning this cookie should be read only by the server...
Read more: Session cookie security: httpOnly
[ Published in IT on 26 November 2012 ]
Imagine, you have 2 web applications (app1 & app2) that are deployed on the same Tomcat server behind the domain www.example.com:
www.example.com/app1/index.do and
www.example.com/app2/index.do
Under the hood we have:
/opt/apache-topmcat-xx/webapps/app1/
/opt/apache-topmcat-xx/webapps/app2/
When a user asks for some resource that doesn't exist (a struts action, a servlet, an image...) the server will respond with status code 404 and will return the ugly default page informing the user that the page he/she has asked for wasn't found.
Of course, you want (and should) change the default 404 Not Found page with a custom one. If your domain isn't redirecting implicitly to one of the two contexts then there are two different scenarios when a server will return the 404 page:
- Context specific 404 (user asks for a non-existing resource inside the /app1)
- Root 404: (user asks for a application that doesn't exist /app100)
Read more: Custom 404 on Tomcat
[ Published in IT on 20 November 2012 ]
Hosting PHP inside Virtuoso Universal Server seems to be a great idea if you are using Virtuoso as your semantic data storage for your web application. I didn't have a chance to test it thoroughly as a web server but I got it up and running and since it wasn't such a strait forward task for me I'll give some tips for the problems I had run into.
Read more: Virtuoso Universal Server, hosting php
[ Published in IT on 20 November 2012 ]
If you have ever tried to design an interface for an application, web page or something similar you've probbably noticed that it is not such an easy task to do. Once you were done you've probabbly showed your masterpiese to your friends, family members and got some feedback such as: "I don't get it, where's the back button", "How do you put product into cart?", "How can I access my profile page?" and other discouraging questions.
Basically, something you considered intuitive and meaningful wasn't as intuitive to the others. Does this mean that you are a bad designer? Yes, it might mean exactly that or it could just mean that you lack the experience and/or some good reading! Check the web site ui-patterns.com where you have a collection of different design interface problems, solutions and discussions and see which things that are obvious for you are not so obvious for your users.
NOTE: For more reading on the subject just google: UI design, UI usability and information architecture....
If you are really interested into the subject of user interface design and usability you can also check a great book written by Steve Krug called Don't Make Me Think: A Common Sense Approach to Web Usability.
[ Published in IT on 20 November 2012 ]
So, you've been working with MySql, PostgreSql or anyOtherSql in almost every project you've developed so far. You've been using INSERT, SELECT, COUNT, HAVE IN syntax, but have you ever written a query that does OUTTER JOIN of two tables or maybe even INNER ONE??? Well, the former one you've probably used without even knowing that what you were doing was an INNER JOIN on tables you define.
SELECT statement together with WHERE(conditions) clause is a synonym for INNER JOIN so you might have a clue what might be going on behind the scene. I personally, have used LEFT and RIGHT joins only during my studies and that's probably why I've always found it more natural to write robust and un-readable :) nested queries in order to get the result. That same nested query that no one could read could be solved with one, for example, LEFT INNER. Why did I do that??? well honestly... never really took time to understand those JOINS (:shame:)
I came across an article called A Visual explanation of SQL joins written 4 years ago that explains SQL joins by using simple graphics. If someone had explained me this subject this way my queries would have never taken more than 4 lines of code :p
Read the mentioned article and you'll freak out when you see how simple this was all along :D
[ Published in IT on 20 November 2012 ]
XML is everywhere today. Web services, REST, Ajax are just the top of the iceberg when it comes to "technologies" using it. It is a language independent standard used, among many others uses, for communication over distributed machines (read: over internet). Since XML is just a simple text it is easilly transferred over HTTP protocol because of ease of its serialization. The concept is very simple but yet powerfull.
Since XML has been a standard for sometime now, every modern programming language has XML parser(s)
libraries included. PHP, for example, has few that come with standard PHP installation. IPhone has few
included in the SDK and Java has God knows how many options... Some are really complex and powerfull while others are more simple to use but with limited functionality.
PHP and Simple XML
In most cases SimpleXML parser should be enough for most of your XML parsing related tasks. You can read in detail about how it works, what are its limitations and so on here.
There is one thing that isn't so obvious when it comes to using this parser: ERRORS!
Read more: XML errors in PHP's SimpleXML parser
[ Published in IT on 17 November 2012 ]
The other day I was listening music on grooveshark.com and I saw a really cool background behind the search input. The background was about some waves that wer moving so I got intrigued. The animation wasn't build using flash. It was pure HTML/JS/CSS stack. I got curious and I started playing with html, js, css to create something similar: DEMO
I also wrote a tutorial that covers creating PNG's in Photoshop, writing xHTML, CSS and pure java script code...
Read more: CSS transitions and animation with java script
[ Published in IT on 17 November 2012 ]
I have no idea if you've heard the term Semantic Web (SW from now on) before but be assured that you gonna be hearing it very often in the future. I'll give a short introduction about what it is and what could this technology bring to all of us tomorrow and as a motivation for you to start considering it as something serious and probably very important for the future of the WWW
I'll just mention two things: the men behind this is Tim Berners-Lee - the inventor of the WWW and it also seems that Google and Yahoo are taking this technology very seriously.
Read more: Semantic Web - the web of data
[ Published in IT on 17 November 2012 ]
This post is about one of the posibble reasons you're getting: Expected ; error in internet explorer...
I just spent half an hour debugging an user interface of a portal I'm working on. Debugging for Internet Explorer of course!!! I always develop in chrome and firefox because they are defacto standard and with firebug and chrome's dev tools development became a pleasure...
Of course, as many of us, I forget to check every new line of code that I add in IE so when I finally decide to check it I don't have the slightiest idea what might be causing the error :S
IE develper tool is definitely a step forward, but it is still a light year from firebug or chrome's dev tool... It simply doesn't help a lot when it comes to locating the bugs...
My IE console kept saying "expected ;" as an error... The indicated file line was totally wrong so I had to go commeting function by function until I found out what was causing it... It was my comment:
\\@todo Bla Bla Bla
Since I've never used IE conditional comments as hacks for IE I've totally forgot that my DoxGen like comments are not allowed in IE...
Beware, DON'T USE @ sign in your comments....
But, one thong worht noting is that if you use the block comment /* */ then it doesn't fail:
\*
* The following block comment is allowed in IE and it won't cause troubles
* @return is as string bla bla
*/