Wednesday, July 31, 2013

JQuery Selectors Examples to find elements in DOM - ID, Class, Element, Descendent, Child, Multiple and Pseudo Selector

JQuery selectors are like CSS Selectors, which allows you to find or select element from DOM tree. When a HTML pages loaded in browser like Chrome, Firefox or Internet Explorer, browser creates a tree like structure known as Document Object Model or DOM. JavaScript and jQuery allows you to play with this DOM i.e. selecting elements from DOM, traversing through DOM, going from one element to another, selecting list of elements from DOM, adding or removing elements from DOM etc. In order to apply most of jQuery function, available in jQuery object, we first need to select HTML elements or tags, on which we want to apply those function, jQuery selector allows you to choose those elements. There are many JQuery selectors e.g. ID selector, class selector or element selector, which provides capability to choose only elements you need. In this JQuery tutorial, we will take a look at these JQuery selector, and simple example to learn how to use them. As I have said before, jQuery is immensely powerful and helpful library for client side scripting, it makes using JavaScript easy with Java like methods. jQuery not only reduces code but also help to mitigate browser incompatibility.

Monday, July 29, 2013

2 Books to Prepare Oracle Java Certification Exams - OCA and OCP Java SE 7 OCPJP 7

There was time, when Sun Certification was very hot and programmer feel proud on being Sun Certified Java professional(SCJP). After Oracle took over Sun in early 2010, it changed names of all the examination from SCJP to OCPJP or OCJP, and now OCA and OCP for Java SE 7. I see there is lot of confusion among certification now days, but essentially they are of the same level at previous SCJP. Since Java gets new language feature with every new release, subsequently a new certification title is introduced. I am not agreed with upgrading your Java certification with every release, it doesn't make much sense to me, but many programmer prefer to get certified and keep it updated. By the way many Java programmers also ask me, whether doing Java certification benefits in Job search or in long term Java programming role, In short, Yes, they do. You can read my response on my post does Java Certification adds value on your career. This post is not about debating Java certification, but about preparing for them. I received lot of emails from my readers, when I wrote my post Top 5 Java Programming books, and they asked me for suggestion on how to excel on OCPJP, books and resource to prepare etc. In this post, we will see couple of good books to prepare for OCA (Oracle Certified Associate) and OCP (Oracle Certified Professional) for Java SE 7 exam. In short you can call it OCPJP 7. Apart from book, you should also use of the exam simulator, preferably from Whizlabs, which I have personally used and liked it. Whizlabs has two exam simulators for Java SE 7 exam,  OCAJP 7 exam simulator and OCPJP 7 simulator, they will help you to get familiar with exam patterns and types of questions asked in actual exam.

2 Good Books for OCPJP 7 Java Certification

Following are couple of books for Java SE 7 Certification exams. These books are pretty much standard and everyone follows them, they are also updated to cover exact syllabus of OCA or OCP Java SE 7 exams.

1) OCA and OCP Java SE 7 Programmer I & II Study Guide (Exams 1Z0-803 & 1Z0-804) (Certification Press)
This book is revised and updated version of Kathy Sieara and Bert Bates best seller SCJP Sun Certified Programmer for Java 6 Exam 310-065. Since things has change, book needs to be updated as well. Books from this author for Java certification is pretty much like text book for OCPJP, as everyone advised about them and almost every one who pass Oracle Java certification follows them. One thing, which is worth noting, If you are not already SCJP or OCJP certified professional and becoming Oracle certified professional first time, then you need to pass two exams to become Oracle Certified Java Professional 7, instead of one. There are two certifications as of now :


Oracle Certified Java Associate 7 ( OCA ) or Java SE 7 Programmer I
Certification Code : 1Z0 - 803
Certification Cost : $300

Oracle Certified Java Professional 7 ( OCP ) or Java SE 7 Programmer II
Certification Code : 1Z0 - 804
Certification Cost  : $50

Thankfully this book covers both exams. As you can see in there title as OCA/OCP Java SE 7 Programmer I & II Study Guide (Exams 1Z0-803 & 1Z0-804). If you just want to prepare with one book, this is the one. As per my experience combination of one book + couple of mock tests from Whizlabs and other simulators can be really handy, and it’s much better than preparing through multiple books.


OCA Java SE 7 Programmer I Study Guide (Exam 1Z0-803) (Oracle Press)
This is another Java book, which can be handy to prepare first part of OCJP 7  or Oracle Certified Java Professional 7 exam. Since this book  is from Oracle press, you can expect them to follow syllabus and cover things which will be subject of examination. By the way book is currently available on Amazon kindle as well and you can buy it here from Amazon.



2) A Programmer's Guide to OCP Java SE 7 Certification: A Comprehensive Primer (4th Edition)
When I prepared for SCJP, long time back, I followed one book + many exams patterns. Though I followed Java Certification book from Khalid Mughal, It  seems this book will cover, what needed for Java SE 7 exam. By the way, this book is still in press and expected to release on November 2013, that's why I put it at the bottom. Khalid Mughal books were quite popular earlier, but seems Kathy Sieara books has been more popular now days. Nevertheless, I expect it to be a good book, given author’s previous record.




Oracle Certified Professional Java SE 7 Programmer Exams 1Z0-804 and 1Z0-805: A Comprehensive OCPJP 7 Certification Guide By S G Ganesh and Tushar Sharma
This is another worth noting book to prepare OCPJP 7 exam. This is the only book available for OCPJP 7 currently in the market, so if you are going to give exam in near time, you only left with this book. I haven't read this book completely but good thing is that it covers all topics and contains 2 mock exams, which gives feel of real exams. The quality of questions in pre-test is also good but better than many online materials. Ganesh and Sharma book is only option right now for giving OCA or OCP Java SE 7 exam.



Lots of things has been changed from original SCJP exams to this OCJP 7 exam, including two exams, but I believe fundamental pattern of exam will remain same. Since there are lot of material available FREE of cost on internet, preparation is not that difficult, but you need to get syllabus right. I also suggest to take relevant mock exams from Whizlabs  e.g. OCAJP 7 Exam Simulator and  OCPJP 7 simulator contains lots of questions with actual difficulty level. You can also try other simulators, those are really good, they help you to be familiar with exam patterns and types of question asked on actual exam. I have used them in pass and really impressed with quality. Not only giving there test but also learning from there explanation and finding reason, why certain choice is good and others are not.


Java Certification Books for SCJP 6

Some of my readers also ask me books for doing SCJP 6, or better known as OCJP 6 or Oracle Certified Associate, Java SE 5/SE 6. Since Java 1.6 is still used a lot in Investment banks and other software companies, there is no harm in doing SCJP 6. Though if you ask me personally, I would probably recommend doing Java Certification for 1.7 version. Anyway, if you are still pursuing SCJP 6, then following books can help you to prepare well.


SCJP Sun Certified Programmer for Java 6 Exam 310-065 By Katherine Sierra and Bert Bates
This is the most respected Java Certification books and lot of programmers has already used this book to clear SCJP 6 with brilliant score. It is highly popular from older days of Sun Certification and one of the most recommended books during SCJP 5. It covers complete topics, presents lots of subtle details and brings on several confusing, interesting Java questions.  If you can, read this book two times before setting up for SCJP, it's worth it. Though I prefer to read multiple books to get view from different authors, as some author connects to me more than others, but if you are running short of time and have a goal to become Oracle Certified Java programmer within few months, I think following only one book is enough, provided it cover everything. In short, if you already finalized examination date or purchase exam voucher with limited validity then start with SCJP Sun Certified Programmer for Java 6 Exam.


OCP Java SE 6 Programmer Practice Exams
This SCJP book is also from same authors but it only contains mock question and practice exams. It's a good supplement to earlier book and together the form best study material for SCJP 6. Apart from these two book, you can also read Java language specification, as it's from Oracle itself and it also provides lots of useful information with good examples. If your goal is to score more than 90% marks then you can also try Java Certification simulators from Whizlabs and Enthuware. I have personally used Whizlabs exam simulators for SCJP and found it very useful. There quality of question, pattern are very close to real exam and most wonderful thing about there product is detailed explanation of each question and options. You will not only learn about why a particular option is correct but also why other options are not correct.

Friday, July 26, 2013

How to bypass Websense Internet Filter at Office, School to view/access Programming and Technical blogs

Recently one of my reader emailed me that he can not access any .blogspot or .wordpress domain from his office, because websense is blocking them as personal blogs category. Since we techies, often relied on personal technical experience, tips shared by fellow developers for our work, this feels really annoying, but same time it's difficult to convince websense guys or local websense security team to not put such restriction. I was thinking about alternative and done some research on internet, which tells me that you can bypass websense filter at school or office by using proxy sites, but this idea doesn’t seems good to me, as they may contain some unwanted piece of crap, which is not good for anyone's computer. Also, if you are working for a decent size company, there is good chance that those proxy sites will also be blocked by websense. This leaves no option at all to access any technical or programming blog, hosted on free domain like .blogspot or .wordpress domain. That’s why some blogger prefer to have there own domain name than relying on blogger or WordPress.

Wednesday, July 24, 2013

File Upload Example in Java using Servlet, JSP and Apache Commons FileUpload - Tutorial

Uploading File to server using Servlet and JSP is a common task in Java web application. Before coding your Servlet or JSP to handle file upload request, you need to know little bit about File upload support in HTML and HTTP protocol. If you want your user to choose files from file system and upload to server than you need to use <input type="file"/>. This will enable to choose any file form file system and upload to server. Next thing is that form method should be HTTP POST with enctype as multipart/form-data, which makes file data available in parts inside request body. Now in order to read those file parts and create a File inside Servlet can be done by using ServletOutputStream. It's better to use Apache commons FileUpload, an open source library. Apache FileUpload handles all low details of parsing HTTP request which confirm to RFC 1867 or "Form based File upload in HTML”, when you set form method post and content type as "multipart/form-data".

Tuesday, July 23, 2013

How to create Thread Pools using Java 1.5 Executor Framework - Example Tutorial

Java 1.5 introduced Thread pool in Java in form of Executor framework, which allows Java programmer to decouple submission of task to execution of task. If you are doing server side programming in Java than Thread pool is an important concept to maintain scalability, robustness and stability of system. For those, who are not familiar with thread pool in Java or concept of thread pool here is one liner, Thread pool in Java is pool of worker threads, which is ready to perform any task given to them, mostly in form of implementation of Runnable or Callable interface. Since Java supports multithreading in programming language itself, it allows multiple thread to run concurrently and perform parallel processing of task. In this article we will learn following things about thread pool in Java :
  1. What is Thread pool in Java?
  2. Why do we need Thread pool in Java ?
  3. What is Executor framework in Java 5?
  4. How to create fixed size thread pool using Executor framework in Java?
  5. Benefits of using Thread Pool in Java?

Thursday, July 18, 2013

How to Configure HTTPS (SSL) in Tomcat 6 and 7 Java Web Server

Setting SSL (Secure Socket Layer) in Tomcat is often a requirement, especially while developing  secure web application, which requires access over https protocol. Since Tomcat web server doesn't provide SSL settings by default, you need to know how to configure SSL in tomcat, and even worse it varies between different tomcat versions. for Example SSL setup which works on tomcat 6, doesn't work as it is in tomcat 7. In this article we will see, how to configure tomcat for https in both tomcat 6 and 7. For those programmers who are not very familiar with SSL and https here is a quick overview of SSL, certificates and https, and I suggest reading that article to get better understanding of How SSL works and How websites are accessed security over internet.

Wednesday, July 17, 2013

10 Things Every Java Programmer Should Know about String

String in Java is very special class and most frequently used class as well. There are lot many things to learn about String in Java than any other class, and having a good knowledge of different String functionalities makes you to use it properly. Given heavy use of Java String in almost any kind of project, it become even more important to know subtle detail about String. Though I have shared lot of String related article already here in Javarevisited, this is an effort to bring some of String feature together. In this tutorial we will see some important points about Java String, which is worth remembering. You can also refer my earlier post 10 advanced Java String questions to know more about String. Though I tried to cover lot of things, there are definitely few things, which I might have missed; please let me know if you have any question or doubt on java.lang.String functionality and I will try to address them here.

Monday, July 15, 2013

Difference between linked list and array data structure in Java Programming

Array and linked list are two fundamental data structure in programming world. Almost all programs use Array in some form or other, which makes it increasingly important to learn array and linked list. Difference between linked list and array data structure is also a popular data structure question, frequently asked in various programming job interview. This makes it even more important to learn and understand difference between an array and a linked list. Well there are lot of difference between these two starting from how they store data, to how you retrieve data from them. Main difference comes from the fact that array elements are stored in contiguous memory location, which makes it easy to retrieve them in quick time, while linked list elements are scattered through out memory, where one element knows address of other, it makes it hard to retrieve element from linked list in quick time. Some of the differences which we saw in ArrayList vs LinkedList also applicable at data structure level, because ArrayList is backed by array and LinkedList is internally backed by double linked list in Java. In this tutorial, we will learn differences between these two fundamental data structure in more details. Once you know the difference, you can make a concise choice of which data structure suits your need better. Since both of them offers distinctive advantage over others, in terms of speed and flexibility, You can make an informed choice based upon your need.

Wednesday, July 10, 2013

When to make a method static in Java

Making a method static in Java is an important decision . Though, static keyword is one of the fundamental concepts, many times programmers gets confused to make a particular method static or not. In Java programming, main motivation for making a method static is convenience. You can call a static method without creating any object, just by using it's class name. So if you need a method, which you want to call directly by class name, make that method static. Utility classes e.g. java.lang.Math or StringUtils, are good examples of classes, which uses static methods. Before making a method static, you should look into limitation of static methods as well, as you can not override static method in Java. By keeping these properties in mind, we can make few rules, which will help to decide when to make a method static in Java and when to use them. In this Java article, we will learn more about benefits and limitation of making a method static, and also see couple of examples of static methods from JDK to learn when and how to use static method in Java.

Monday, July 8, 2013

Top 5 JQuery books for Beginners and Web developers - Best of lot

jQuery is a open source JavaScript library, which has completely changed the way, client side web development was done using HTML, CSS and JavaScript. With growing popularity of jQuery, it become imperative for web developers to learn and take advantage of jQuery and books are one of the best way to learn jQuery. In this article, I am going to share you top 5 jQuery books from my personal collection, which I have looked and researched before purchasing my first book on jQuery, Head First JQuery. Since I like to follow one book at a time, I didn't bother to look into another must read book, JQuery in Action, until I have finished former. After finishing my first book on jQuery, I am quite comfortable with jQuery magic, which means doing things like DOM Selection, traversal, DOM manipulation based on CSS selector, animation and cool effects, and responding to use actions (event handling) in couple of lines. In short jQuery is powerful, yet easy to understand, very succinct and a must have skill for web programmers and web developers in there resume. I personally believe that you at least to read couple of jQuery books to not only gain confidence, but also to be familiar with subtle details of jQuery library itself. Though nothing beats documentation, as they are the one, which is most up-to-date, but following a book with simple examples is totally different learning experience, especially if you are beginners and not an expert of HTML, CSS and JavaScript.

Thursday, July 4, 2013

How SSL, HTTPS and Certificates works in Java web applications

Basic knowledge of SSL, HTTPS and Certificates are must for any Java programmer, especially who is working in financial and security sensitive applications, which are accessed over internet. In this article, I am giving you an overview of these three key concept and How SSL, HTTPS and certificates work together, to provide secure communication between client and server. Security is major concern while developing web application, which is accessible using HTTP protocol. Since HTTP protocol transfer data in plain text format, its not safe for transferring sensitive information like username, password, social security number (SSN) or credit card details for online shopping. HTTP protocol, also doesn't guarantee that a website, you are communicating is the one who claims i.e. if URL redirection is enable than instead of genuine website you may be routed to malicious websites and HTTP can't prevent or alert you.

Tuesday, July 2, 2013

Role based Access control using Spring Security and MVC, Mapping LDAP Groups to Authorities for Authorization

Authentication and Authorization is integral part of any Java enterprise or web application. Since most of the company uses LDAP Active directory for authentication, authorization and Role based access control (RBAC), it's good to know How to implement Role based access control using Spring MVC and Spring Security. This is the second part of my articles on using Spring Security for authentication and authorization in Spring MVC based Java application. In last part, we have learned about doing LDAP authentication against Windows active directory, and in this Spring Security tutorial, we will learn How to map LDAP groups to authorities for implementing Role based access control or authorization. If you are developing an application, whose access is controled by adding user to a particular LDAP group, then you need a mechanism to load those LDAP group after successful authentication. Spring Secuirty uses GrantedAuthority class for holding all roles for a particular user. Based upon these roles, a particular user can perform certain functionality in your application. For example, a read only user can only see data, but a user with ADMIN role, can add or remove data from your application. After implementing Role based access control, you are free of user management task, those will be taken care by respective team which manages LDAP groups and access, usually Windows support teams. In this article, we will all the steps required to map LDAP groups to granted authorities in Spring Security. If you love to read books, than you may want to check Spring Security 3.1 By Robert Winch,Peter Mularien, a great book, which teaches all good features of Spring security including LDAP authentication and authorization in great details. If you are developing secure enterprise application in Java and considering spring security, this is the one of the best and must read book on Spring Security.