Tuesday, July 23, 2013

Web: Faulty HTML, JS, and CSS code, hurts your page Performance, Quality and Debugging.

HTML page is the core

Yes, it is the core of every web project. Therefore, it is very important to code your HTML page properly since it forms the foundation for everything else. Because it is the core of every web page, so without a solid foundation, the stuff you build upon it will easily break.

All web browsers are very forgiving and will often render a page correctly even if the HTML is slightly faulty, and your page finally will render, but you should get your attention for such behavior. I do, however, recommend that you make sure the HTML is coded properly, for a number of reasons:

  • Performance
    Correct HTML code renders faster than incorrect HTML.

    How it comes? Okay let us see, if your code done properly, the browser will interpret the HTML in strict mode, in which it assumes that you know what you are doing. Incorrectly done, and it will switch to quirks mode, in which it is a lot more forgiving in its interpretation of the code.

    This means that you can get away with sloppy code, but since the browser has to guess what you mean, the page takes longer to render.

  • Quality
    Naturally, you want to look professional, and you just don’t look good with HTML that doesn’t validate. Invalid code is the sign of a developer who doesn’t know what he’s doing.

  • Debugging

    In addition, if you don’t have the HTML right, strange errors may occur in your CSS or JavaScript that are really hard to find.

    Both the CSS and a lot of the JavaScript code relies on the HTML being correct, so to make it easier for yourself, make sure that your HTML is correct by validating it frequently.

    This will save you a lot of time and grief.

How do you know that you have a correct HTML code?

It is a simple answer, fortunately W3C (World Wide Web Consortium) provides a tool which validate your code, whether it is a live page by providing its URL, or resides on your computer by uploading the file or past the code.

You will find this validator at W3C markup validation service.

Also your browsers are bundled with validation and inspection tools such as developer tools, alongside a bunch of extensions you can add to your browser for validation process.

Some of Firefox browser tools:

  1. Page Validator: https://addons.mozilla.org/en-US/firefox/addon/2250
  2. Html Validator: https://addons.mozilla.org/en-US/firefox/addon/249
  3. Web Developer Toolbar: https://addons.mozilla.org/en-US/firefox/addon/60

With these tools at your disposal, you are more than ready to get started.

Thursday, July 18, 2013

Oracle: Feel the fun of Oracle Weblogic & JDeveloper 12c on Mac OS X

Oracle fusion middleware 12c stack is now completed and ready for use and supports cloud platform technology stack. The story Begins by releasing Oracle Weblogic 12c last year 2012, then followed by Oracle database 12c this year 2013, and by this month of July the development IDE JDeveloper 12c ( has been released.

WebLogic 12.1.2 is now available. Moreover, is also bundled with the new JDeveloper 12c. WebLogic 12.1.2 comes in two flavors one of size 179MB zip distribution offers Java EE 6 Full Profile development and includes WebLogic Server and Coherence. The generic installer also includes WebLogic Server and Coherence and is patchable via OPatch.

There are two interesting supported components available in WebLogic 12.1.2 out of the box, that already part of JEE 7, one of them is the Websockets protocol support, and the other is JSON Binding via EclipseLink 2.4.2 MOXy's JSON-binding.

JDeveloper 12c comes with a big bunch of enhancements and technology support, one of interesting components is the support for Java EE and Web Development as the following:

  • Java EE 6 Support: JDeveloper wizards and editors have been updated to work with Java EE 6 specifications, including EJB 3.1, Servlet 3.0, CDI, JPA 2.0, EL 2.2, and more.
  • EJB 3.1 Support: JDeveloper provides support for new EJB 3.1 features including:
    • Singleton Session Bean
    • Simplified No Interface Client View
    • Asynchronous Session Bean Invocations
  • TopLink/JPA 2.0:
    • TopLink supports the following JPA 2.0 features:
    • JPA 2.0 project type and JPA 2.0 persistence unit properties
    • Delimited and derived identifiers
    • Mixed access
    • Unidirectional one-to-many mappings
    • Validation mode
    • Element collection
    • Embeddable mapping
  • HTML5, MathML and CSS3 Support: Updated editors for working with latest HTML5 and CSS3 content.
  • CSS editor: Added ability to invoke Quick doc feature for CSS properties and skinning keys, and other editor improvements.
  • JSP to Facelets conversion: User may optionally choose to convert a project's JSP/JSPX content to Facelets.

For more about all new features of JDeveloper 12c, visit what's new in JDeveloper 12c.

The new abbreviation that sticks to the version 12c (is c for Cloud),and it means that the JDeveloper is an enabled Cloud development IDE.

One of the most interesting features of the JDeveloper 12c that worthwhile is its installer, it is very easy to install and runs on mac OS X operating system rather than its previous 11g versions series, avoiding much of boilerplate system configurations to just install it.

So let's see how we can install it on Mac OS, but first let us get the required software to complete the installation process successfully.

Pre-requests software:

  1. Java Development kit 7 update 25+ or less, it is a critical piece of software that allows the installer to pass the prerequisites successfully. It could be downloaded from here.
  2. Download the JDeveloper 12c Generic installer the works on all platforms (it is a jar package).

That's all; let's now go through the installation process.

Installation process
  1. First open your terminal, and type the following command:

    You should make sure that your java version is version 7 pointed out in your system class path, if version is different, you should make your system class path includes the java 7 version.

    If everything is okay then you will see output like the following:

  2. From the same terminal, change your directory to your JDeveloper downloaded jar file, for example I have downloaded the jar file inside a folder named “Oracle JDeveloper 12c ( (Build 6668)” on my mac desktop. To begin installing the JDeveloper issue the following commands:

    Then followed by:

    If everything is going okay then you should see the following output:

    Then the following screen will popped up, and the installation process begins. Choose your inventory, which will, includes your JDeveloper system preferences folder, and OS group permission. I have changed it from stuff to be everyone, and clicked Ok button.(This screen will appear only on mac OS, but if you are using windows OS, the wizard will pop up for the installation and the process will begin from the next step):

  3. On the next screens “Oracle JDeveloper studio installer”, it includes five wizard steps, click next on each of them till finishing the installation, and seeing the following screen:

  4. Click next and the summary page comes with all installation log, including three options as in the following figure, for me I have choose the first option.

  5. Click finish and JDeveloper will start with new splash screen as the following:

  6. After splash screen finished preparing JDeveloper components, the main IDE should open with a new and neat look and feel:

  7. From Tools menu item, click check for update menu, you can make your new JDeveloper 12c, most updated with required components, one of recommended components is jUnit component.

  8. After finished the updates, we need to create a default domain of Weblogic 12.1.2 bundled server, from run menu click "Start server instance":

  9. The Weblogic configuration dialog will appears to provide password, and other configurations:

  10. Click Ok button and the JDeveloper log, will contains all creation and running conversation entries, wait till you find your log ends with the following entries:

Hence, we are here, than we have finished the installation process of JDeveloper 12c, and created a Weblogic 12c domain, so you can rock and give your hand the touch of JEE6 on the new release.

Happy coding :)

Wednesday, July 17, 2013

Mac: Mac OS X Screen capturing shortcuts, without using any application

As I am writing blog posts, articles, books and any kind of documents that requires a screen shots on Mac OS, you will find a tool to do that by default packaged with Mac, Greb and preview tools.

Screenshots can be taken by using the Grab application included with OS X. It is located at /Applications/Utilities/Grab.

Preview can also be used to take screenshots, by using the "Take Screen Shot" submenu in the File menu.

Instead of using the applications above, for the sake of productivity, Mac OS X provides a keyboard shortcuts to control the screen shot taking instead of programs, and they are as the following:
  1. Command-Shift-3:
    Take a screenshot of the screen, and save it as a file on the desktop

  2. Command-Shift-4:
    then select an area: Take a screenshot of an area and save it as a file on the desktop

  3. Command-Shift-4:
    then space, then click a window: Take a screenshot of a window and save it as a file on the desktop

  4. Command-Control-Shift-3:
    Take a screenshot of the screen, and save it to the clipboard

  5. Command-Control-Shift-4:
    then select an area: Take a screenshot of an area and save it to the clipboard

  6. Command-Control-Shift-4:
    then space, then click a window: Take a screenshot of a window and save it to the clipboard

  7. In Leopard and later,
    the following keys can be held down while selecting an area (via Command-Shift-4 or Command-Control-Shift-4):

    1. Space, to lock the size of the selected region and instead move it when the mouse moves
    2. Shift, to resize only one edge of the selected region
    3. Option, to resize the selected region with its center as the anchor point

Monday, July 8, 2013

Java SE 7: Refactoring your legacy java.io.File Code to elegant java.nio.file (NIO.2)

In my previous article, I have introduced all of the new functionalities, features and APIs, which are shipped with Java SE 7 release, and here we will see how to migrate or re-write your old IO to new NIO.2 code.

In my daily projects I am developing, I am depending extensively on I/O usage for exchanging files among my systems for integration, and there are a lot of boilerplate code, validations, exceptions checking and security related issues. Therefor I have decided to refactor my code especially critical one to Java SE 7 NIO.2 APIs.

In this article, I will show you a quick guide on how to refactor and map your legacy IO (Input/Output) code, which is prior to Java SE 7 ( java.io.File class was the only mechanism used for file I/O), to the new java.nio.file APIs which comes with rich and tremendous functionalities as part of Java SE 7 and above.

The Java 7 file I/O API JSR 203, has been completely re-architected in the Java SE 7 release; and because of that, you cannot swap one method for another method.

To use the rich functionality offered by the java.nio.file package, the easiest solution is to use the File.toPath method. If the previous statement is not sufficient for your needs, you must rewrite your file I/O code.

Before we dive into the mapping of the functionalities from legacy IO to the new one from Java 7 NIO, I have question to ask.

Why should I migrate from old IO to new NIO.2?

If you have developed more than a few applications based on java.io.File, then you should be familiar with not only its methods, but also its methods’ drawbacks.

For example, many of these methods do not throw exceptions when they fail, there is no real support for symbolic links, metadata access is inefficient, file renaming across platforms is inconsistent, and some methods do not scale, enhanced security and so on.

Let us begin the refactoring process:

The first milestone of refactoring java.io.File code may be considered the conversion of File objects into java.nio.file.Path objects through the java.io.File.toPath() method:

After conversion, you can exploit the Path features.

However, while this is the easiest solution, it may not always satisfy your needs.

Sometimes you will need to rewrite your file I/O code and align code to java.nio.file classes, and for this, you can use the one-by-one correspondence between the two APIs.

The following Table shows this correspondence; this table will make your code transition from Java 5 or 6 to Java 7 much easier:

Javadoc Description



Class name correspondence



Tests this abstract pathname for equality with the given object



Compares two abstract pathnames lexicographically



Returns the absolute pathname string of this abstract pathname



Returns the absolute form of this abstract pathname



Returns the canonical pathname string of this abstract pathname




Returns the canonical form of this abstract pathname




Constructs a file: URI that represents this abstract pathname



Tests whether the file denoted by this abstract pathname is a normal file


Files.isRegularFile(Path, LinkOption ...)

Tests whether the file denoted by this abstract pathname is a directory


Files.isDirectory(Path, LinkOption...)

Tests whether the file named by this abstract pathname is a hidden file



Tests whether the application can read the file denoted by this abstract pathname



Tests whether the application can modify the file denoted by this abstract pathname



Tests whether the application can execute the file denoted by this abstract pathname



Tests whether the file or directory denoted by this abstract pathname exists


Files.exists(Path, LinkOption...)

Files.notExists(Path, LinkOption ...)

Creates the directory named by this abstract pathname



FileAttribute<?> ...)

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories



FileAttribute<?> ...)

Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist


Files.createFile(Path, FileAttribute<?> ...)

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname




Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter




Files.newDirectoryStream(Path, DirectoryStream.Filter<? super Path>)

Files.newDirectoryStream(Path, String)

The length of the file denoted by this abstract pathname



Deletes the file or directory denoted by this abstract pathname




Renames the file denoted by this abstract pathname


Files.move(Path, Path, CopyOption)

Sets the owner or everybody’s execute permission for this abstract pathname

File.setExecutable(boolean, boolean)

Files.setAttribute(Path, String, Object, LinkOption...)

Sets the owner or everybody’s read permission for this abstract pathname

File.setReadable(boolean, boolean)

Files.setAttribute(Path, String, Object, LinkOption...)

Marks the file or directory named by this abstract pathname so that only read operations are allowed


Files.setAttribute(Path, String, Object, LinkOption...)

Sets the owner or everybody’s write permission for this abstract pathname

File.setWritable(boolean, boolean)

Files.setAttribute(Path, String, Object, LinkOption...)

Returns the time that the file denoted by this

abstract pathname was last modified


Files.getLastModifiedTime(Path path, LinkOption... options)

Sets the last-modified time of the file or directory named by this abstract pathname


Files.setLastModifiedTime(Path, FileTime)

Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name

File.createTempFile(String, String)

Files.createTempFile(String prefix, String suffix, FileAttribute<?>... attrs)

Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name

File.createTempFile(String, String, File)

Files.createTempFile(Path dir, String prefix, String suffix, FileAttribute<?>... attrs)

Returns the size of the partition named by this abstract pathname



Returns the number of unallocated bytes in the partition named by this abstract path name



Returns the number of bytes available to this

virtual machine on the partition named by this abstract pathname



Lists the available file system roots



Random access file



Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates


Replaced by the DELETE_ON_CLOSE option

Combines two paths

new File(parent,"new_file")


Happy conversion, refactoring, mapping, and migrating IO from earlier JDKs to new JDK7 NIO2 :)

  1. JDK7: Part 1- The power of java 7 NIO.2(JSR 203)(important concepts).
  2. File I/O(Featuring NIO.2).
  3. Package java.nio.file.
  4. Package java.io.
  5. File class.

JavaZone 2013: Javapocalypse, "Without Java you can't live :)"

"It's supposed to write once, run everywhere. But it's more like write once, ruin everything..."