Featured Posts

<< >>

jQuery Interview Questions

With rich internet applications (RIA) being deployed everywhere including enterprises, the related UI frameworks to build these applications are also in demand. Every framework provides something which is fresh in the market. These UI frameworks are javascript based, have support for Ajax, have cross browser support and are extensible. So when you are being screened [...]

DZoneDeliciousLinkedInRedditTechnorati FavoritesStumbleUponShare

Hibernate Configuration Basics

Configuration cfgn = new Configuration(); cfgn.addResource(“school/student.hbm.xml”); cfgn.setProperties(System.getProperties()); SessionFactory sfactory = cfgn.buildSessionFactory(); • The code snippet shows the programmatic way of creating a hibernate configuration. The mapping file – .hbm.xml file is usually created for each class and placed in its root directory. The path shown above is relative to the class path. • Hibernate can [...]

DZoneDeliciousLinkedInRedditTechnorati FavoritesStumbleUponShare

jQuery Interview Questions

With rich internet applications (RIA) being deployed everywhere including enterprises, the related UI frameworks to build these applications are also in demand. Every framework provides something which is fresh in the market.

These UI frameworks are javascript based, have support for Ajax, have cross browser support and are extensible. So when you are being screened for a requirement in the organization, the interviewer will try to judge you on various aspects of an application. Here in this article, I am listing few jQuery Interview Questions which are helpful to all developers and UI developers in particular.

1) What do you need to do in order to use jQuery in your project?
Ans: We need to import the jQuery minified js and css files

2) What is the difference between normal and minimal version of .js files that are shipped with jQuery bundle?
Ans: The minified version is useful in production system because it saves the bandwidth and decreases page loading speed.

3) Can one download and change the jQuery base code and use it? Did you every feel like changing the code base for something that was missing in the bundle? Under what scenarios will you consider modifying the jQuery code base?
Ans: This should ideally never be required and we shall post the issue to jQuery library to the developer community.

4) Which version of jQuery have you worked on. What steps will you take to migrate your web application to the latest version of jQuery?
Ans: There are different versions for jQuery Mobile and jQuery normal libraries and discuss the version you have been using.

5) What all features of jQuery have you used in your web projects?
Ans: jQuery offers a lot of features like Accordian, Sliding menu, File upload etc.

6) Would you prefer using a feature available in jQuery than writing the same functionality using custom javascript and CSS?
Ans: It is better to use the same feature using jQuery than writing custom css and js.

7) What all browser related issues you have faced with jQuery?
Ans: Browser compatibility of jQuery plugins is an issue and needs lot of time and effort to fix.

8 ) What is the difference between javascript’s onload function invoked from HTML body tag like and jQuery’s ready function?
Ans: We can have multiple onload handlers in jQuery but not with body tag.

9) On what parameters will you judge a jQuery plugin before using it in your application?
Ans:
1) Browser compatibility.
2) Performance.
3) Ease of use.

10) What all techniques have you been using in order to increase the performance of a web application developed using jQuery?
Ans: Try not add too many event handlers on load event. Use proper element selectors.

11) Given the option to decide on a Javascript framework for a JEE based web application, what other frameworks will you consider before making a choice?
Ans: There are many other food javascript frameworks including prototype, dojo and YUI.
Note: You may also want to browse through our dojo tutorial series.

12) What all jQuery plugins have you used? Explain them?

13) Can you write the code to send an Ajax request to a JSP page?
Ans: One can use $.POST() and $.GET() to issue Ajax requests in web applications.

14) Have you used overlay effect of jQuery? What configuration settings are available for creating the overlay effect?

15) Which jQuery editor do you use?
Ans: While there could be multiple plugins for IDE that add jQuery support but you shouldn’t fail to mention the big names like Aptana Studio IDE and less known jsdt-jquery.

16) What are the ways by which I can include jQuery in my web pages? Which one is the best?
Ans: We can download a out of the box development and production versions from jQuery website and use it in our applications. There is also an option to create a custom build where we can leave out unnecessary widgets and hence reduce the size of our JS file. If the web application is going to be hosted on the internet then we can refer to Content Delivery Networks (CDN) like Google code to make the browser download the script from Google servers and use it.

17) What is a selector?How many type of selectors are available?
Ans: The selectors are used to select a single or group of elements before performing an operation on them. The following are the selectors available in jQuery:

1) Select elements by tag name — $(div)
2) Select elements by ID — $(#xyzid”)
3) Select elements by class — $(“.xyzclass”)

Out of the above, the most efficient is selecting element by ID as it translates to native Javascript call document.getElementById(“xyzid”);

18) How would you animate elements in jQuery?
Ans: There is animate function available in jQuery API which can be used to perform animations as shown in the following code example:

The syntax of animate function is: $(selector).animate({params}, [duration], [easing], [callback])

param defines the CSS properties on which you want to apply the animation.
duration specify how long the animation will run. It can be one of following
values : whether the animattion is slow, fast or normal
easing : is the string which specify the function for the transition.
callback is the function which we want to run once the animation effect is complete.

Example:
$(‘# clickToAnimate’).click(function() {
$(‘#book’).animate({
opacity: 0.30,
left: ‘+=20′,
height: ‘toggle’
}, 3000, function() {
// run after the animation complete.
});
});

19) How would You disable or enable a form element?
Ans: Elements can be disabled by using the following code samples:
$(‘#sampleid’).attr(‘disabled’, true);
$(“#sampleid”).attr(‘disabled’, ‘disabled’);

20) How would you check or uncheck a checkbox input or radio button?
Ans: Elements can be checked/unchecked by using the following code samples:

check

DZoneDeliciousLinkedInRedditTechnorati FavoritesStumbleUponShare

Hibernate Configuration Basics

Configuration cfgn = new Configuration();
cfgn.addResource(“school/student.hbm.xml”);
cfgn.setProperties(System.getProperties());
SessionFactory sfactory = cfgn.buildSessionFactory();

• The code snippet shows the programmatic way of creating a hibernate configuration. The mapping file – .hbm.xml file is usually created for each class and placed in its root directory. The path shown above is relative to the class path.
• Hibernate can also be configured using the .properties file which must be placed directly in the class path.
• Another option is to create a hibernate.cfg.xml file which must be placed in the class path.

After creating the configuration, various other settings need to be taken care of like the JDBC connection details, context management, SQL dialect etc. one or more of the following methods can be used for the same.

• Place elements in the configuration file – cfg.xml
• Create a file hibernate.properties. This must also be in the classpath
• Pass an instance of java.util.Properties to Configuration.setProperties()
• Hibernate can also be configured using the .properties file which must be placed directly in the class path.
• Another option is to create a hibernate.cfg.xml file which must be placed in the class path.
How does it Work?

Creation of any Java based application involves storing data into a database object such as a table and retrieving it later for one or more purposes. Hibernate comes in handy by mapping the Java objects also known as “Persistent classes” to the database tables.

To explain how this mapping works, let’s consider a sample Student Class.
Each instance of this class represents any individual student.
Each student will be identified by various properties (attributes) like name, roll number, Department etc.
On the other hand consider an oracle database with a Student table.
Each row in this table represents any individual student.
The student table has various columns like name, roll number, department etc.

So to generalise the mapping in its simplest format, we can say that -
• Each Java Class will be mapped to a table in the database.
• Each Instance of such class represents a row in the respective table.
• Each attribute of such Instance represents a column in the respective table for the corresponding row.

Sample Java Class – Student

package school;
public class Student {

private Long roll_id;
private String name;
private String dept;

private Student() { } // No argument Constructor

public Student(String name) {this.name = name; }
public Student(String name, String dept) {
this.name = name;
this.dept = dept;
}

// getter – setter methods for attributes

public Long getRoll_id() { return roll_id;}
public void setRoll_id(Long roll_id) {this.roll_id = roll_id; }
public String getName() { return name;}
public void setName(String name) { this.name = name;}
public String getDept() { return dept;}
public void setDept(string dept) {this.dept = dept;} }

The most important attribute in this Student class is the roll_Id because this will be our primary key in the student table.
Please note that this student class does not implement any hibernate specific Interfaces; hence it can be used in any context like any other java class.

To allow this class to be made persistent so that it is usable by the hibernate framework, we need to provide a hibernate mapping XML.This file will be saved with a .hbm.xml extension.
Sample Mapping Document






table = “student” />

Note:
element is being used to generate a sequence (primary key of type long in this case)
element maps the Student class to the Student table
element identifies the primary key and maps roll_id of the Student class to “Roll_No” column of the student table.
element is used to map each attribute of the Student object to its corresponding column in the Student table.
is an element used to specify the data type for columns. This is to ensure that the type of database column and that of the java object property are relative.
Create a new Student

Session session = getSessionFactory().openSession();
Transaction trans = session.beginTransaction();
Student student = new Student(“Alex”);
session.save(student);
trans.commit();
session.close();

This code snippet results in execution of something similar to this SQL –
Insert into Student (ROLL_NO, NAME, DEPT) values (1, ‘Alex’, null)

Update an existing Student details

Session session = getSessionFactory().openSession();
Transaction trans = session.beginTransaction();
Student student = (Student) session.load (Student.class, new long(1));
Student.setDept(“Chemistry”);
session.saveorUpdate(student);
trans.commit();
session.close();

Deleting an existing Student Detail

Session session = getSessionFactory().openSession();
Transaction trans = session.beginTransaction();
Student student = (Student) session.load (Student.class, new long(1));
session.delete(student);
trans.commit();
session.close();

Hibernate is by far the most popular Object Relational Mapping (ORM) solution provided especially in the case of Java. Its beauty lies in its ease of use as compared to writing code for SQL/JDBC and its simplicity when paired against the all powerful EJB.

DZoneDeliciousLinkedInRedditTechnorati FavoritesStumbleUponShare

New Features in JSF 2.0

With many new features, JSF 2.0 is an evolution from 1.2, but it’s also a step forward—for example, in
terms of PDL, where Facelets is preferred to JSP. New features of JSF 2.0 include the following:

• An alternative viewing technology to JSP based on Facelets

• Easier navigation between pages with implicit and conditional navigation

• JSF has been using POST HTTP requests intensively; this new release brings back GET requests as a first-class citizen (allowing users to bookmark pages)
• A new resource-handling mechanism (for images, CSS, JavaScript files, and so on)

• Additional scopes (view scope, flash and component scope)

• Easy development with annotations for managed beans, renderers, converters,validators, and so on.

• Reducing XML configuration by exploiting annotations and configuration by exception (faces-config.xml is optional)

• Ajax support

• Better error handling (provides information such as line numbers and not just a stack trace)

• Easy component development

DZoneDeliciousLinkedInRedditTechnorati FavoritesStumbleUponShare

Book Review : KnockoutJS Starter

The folks at Packt asked me to review one of their book on KnockOut Js If you are interested in buying it (a judgment you may reserve until after you have read the review)
“http://www.packtpub.com/knockoutjs-starter/book” this is link you can go.

Eric Barnard is a Software Engineer in Champaign-Urbana, Illinois. You can find his blog at http://www.ericbarnard.com

The Packt model is an interesting one. They are an online publishing house who approach subject matter experts and offer them an advance and a good commission for writing a book for them. They have approached me a couple of times but I have turned them down on both occasions simply due to a lack of time. Given the movement towards e-readers and related devices I believe it is a business model most publishers will eventually adopt.
Overview and Structure of the Book

The first thing you will probably notice is the size of the document. This is no brief summary of the new features. This is small book of over 40 pages covering to learn a new java script librart with a full index in the back. The structure of the book is:

Business overview
Step 1 – Defining a namespace
Step 2 – Creating our Model
Step 3 – Creating a View for our Model
Step 4 – Creating a ViewModel to manage our Models
Step 5 – Working with Observable Arrays
Step 6 – Adding and removing Models from an Observable Array
Step 7 – Editing properties of a Model
Step 8 – Setting up a Master-Details view
Step 9 – Applying bindings

• There are some key features as well like MVVM model and other important features of KnockOut JS

I like this structure as it parallels the steps one would take in setting up a KnockOut JS. To add a bit of a flow to the book, they also put it in the examples,real life scenarios.

What is missing is – This book is not covering the detailed code description.Although it have how to install this library.Creating a demo application.How to start creating site, MVVM library.

Its more a starter book.This book focuses on giving the reader a firm understanding of the core concepts of Knockout, such as MVVM and data binding,
and works through real-life app development scenarios. All core components of Knockout’s amazing library are covered in detail, and strategies are outlined for getting the best use of time when developing with Knockout .

Knockout – A JavaScript library
Knockout, at its core, is a simple JavaScript file that can be included in a website or a web application to add JavaScript functionality, and provides the ability to enhance a user’s experience. By default, Knockout does nothing to your website or web application until you specifically write code to utilize it. It is important to understand the difference between Knockout and many other JavaScript “frameworks” or “libraries” as some frameworks actually change how a website or web application works when included.

The difference between this library and other java script library is as below :

Subscribables - It give an edge of catching subscriber and receiver event.A Subscribable is simply an object that has three methods and an array of Subscriptions.

Observables -The Knockout Observable is one of the first objects that leverages the Subscribable functionality, and is one of the most simple, yet powerful pieces of the Knockout library.

Observable Arrays – There are multiple value of observable .

Computed Observables-Computed Observables are arguably the most powerful feature of Knockout. You may have noticed that creating a ViewModel with nothing but Observables and Observable Arrays is a huge step up from plain JavaScript, but it would be really nice to have other properties on your
ViewModel that simply depended upon other Observables and Observable Arrays and updated themselves when their dependencies change.

Utilities -Knockout is full of many useful utilities that you can use in your application development.You can find these by exploring the
ko.utils namespace.One of utility is extend.

Data-bind statements – Knockout was designed to make binding JavaScript objects and HTML extremely easy. The API that is given to us to use is through the HTML5 compliant data-bind statement.

Applying bindings – This is key feature of knockOut JS.Book describer it very well with example.Many examples show the applyBindings function being called with a ViewModel object being passed in as the only argument, but you can also specify a DOM node as the second argument.
When passing a DOM node as the second argument, Knockout only binds your ViewModel to that node and its children.

Conclusions
This book is not a comprehensive guide to the learn knockout JS. Rather, it is It presents a Starter guide to learn and work on KnockOut JS. It descrive MVVM model with detailed description.Worth of reading.

DZoneDeliciousLinkedInRedditTechnorati FavoritesStumbleUponShare

Minimizing the memory leak in your java j2ee application

Java’s memory managmement (i.e Garbage collectionGarbage collection -how it works) prevents lost references and dangling references but it is still possibilities to create memory leaks in other ways. If the application run with memory leaks for long duration ,you will get the error java.lang.OutOfMemoryError.
In java ,typically the memory leak occur when an object of a longer lifecycle has references to the objects of a short life cycle. This prevents the
object with short life cycle being garbage collected. The developer must remember to remove the references to the short lived object from the long-lived objects.Objects with same life cycle do not cause any problem because the garbage collector is smart enough to deal with the circular references.
-> Java collection class like HashTable, ArrayList etc maintain references to other objects.So having a long life cycle ArrayList pointing to many . . short-lifecyle objects can cause memory leaks.
-> Commonly used singleton Design pattern can cause memory leaks.Singleton typically have a long lifecycle. If a singleton has an arrayList or a HashTable then there is potential for memory leaks.
-> Java Programming language includes a finalize method that allows an object to free system resources ,in other words to clean up after itself. However using finalize doesn’t guarantee that a class will clean up resources expediently. A better approach for cleaning up resources involves the finally method and an explicit close statement.so freeing up the valuable resources in the finalize method or try {} block instead of finally() block can cause memory leaks.

DZoneDeliciousLinkedInRedditTechnorati FavoritesStumbleUponShare