Tuesday, February 25, 2014

(Most Frequently Asked) Java Interview Question - Differences between recent Java Versions


Features of Recent Java Versions

Java 5
– Major update. Generics, varargs, printf, @Override, new
“for” loop.

Java 6
– Minor update. Updates to collections, Swing, etc.

Java 7
– Minor update. Diamond operator, Strings in switch
statements, try-with-resources, updates to Swing
(especially new look and feel).

Java 8
– Major update. Lambdas for functional programming.
Streams for bulk operations. Final version early 2014.


Kindly add if missed any points here.

--
Bst Rgds,
Shakir
.
"Knowledge grows when it is shared"
“Assisting people who are in trouble, providing help to people who are needy and feeding those people who are hungry are acts of Worship.” 
Love Nature...
 Save a tree. Use Less Papers. Don't print this e-mail unless it's really necessary!!

PΓΌ Consider the environment. Think before you print.


Thursday, September 27, 2012

Java Interview Coaching for Free for Freshers

Hi,
 Kindly drop me an email on shakir.alate@gmail.com for Java Interview questions and preparation / guidance.

thanks and regards,
Shakir.

Monday, September 24, 2012

Difference between save and saveOrUpdate , get() and load() in Hibernate Questions [ frequently asked questions in Hibernate interview ]


Difference between save and saveOrUpdate in Hibernate
Save vs SaveOrUpdate vs Persist method in HibernateMain difference between save and saveOrUpdate method is that save() generates a new identifier and INSERT record into database while saveOrUpdate can either INSERT or UPDATE based upon existence of record. Clearly saveOrUpdate is more flexible in terms of use but it involves an extra processing to find out whether record already exists in table or not. In summary  save() method saves records into database by INSERT SQL query, Generates a new identifier and return the Serializable identifier back. On the other hand  saveOrUpdate() method either INSERT or UPDATE based upon existence of object in database. If persistence object already exists in database then UPDATE SQL will execute and if there is no corresponding object in database than INSERT will run.

Difference between get and load method


Hibernate Session  class provides two method to access object e.g. session.get() and session.load() both looked quite similar to each other but there are subtle difference between load and get method which can affect performance of application. Main difference between get() vs load method is that get() involves database hit if object doesn't exists in Session Cache and returns a fully initialized object which may involve several database call while load method can return proxy in place and only initialize the object or hit the database if any method other than getId() is called on persistent or entity object. This lazy initialization can save couple of database round-trip which result in better performance.

Read more: http://javarevisited.blogspot.com/2012/07/hibernate-get-and-load-difference-interview-question.html#ixzz27NFtCiSk


Here are few differences between get and load method in Hibernate.

1. Behavior when Object is not found in Session Cache
Apart from performance this is another difference between get and load which is worth remembering. get method of Hibernate Session class returns null if object is not found in cache as well as on database while load() method throws ObjectNotFoundException if object is not found on cache as well as on database but never return null.

2. Database hit
Get method always hit database while load() method may not always hit the database, depending upon which method is called.

3. Proxy
Get method never returns a proxy, it either returns null or fully initialized Object, while load() method may return proxy, which is the object with ID but without initializing other properties, which is lazily initialized. If you are just using returned object for creating relationship and only need Id then load() is the way to go.

4. Performance
By far most important difference between get and load in my opinion. get method will return a completely initialized object if  Object is not on the cache but exists on Database, which may involve multiple round-trips to database based upon object relational mappings while load() method of Hibernate can return a proxy which can be initialized on demand (lazy initialization) when a non identifier method is accessed. Due to above reason use of load method will result in slightly better performance, but there is a caveat that proxy object will throw ObjectNotFoundException later if corresponding row doesn't exists in database, instead of failing immediately so not a fail fast behavior.

5. load method exists prior to get method which is added on user request.

When to use Session get() and load() in Hibernate
get vs load hibernate interview questionSo far we have discussed how get and load are different to each other and how they can affect performance of your web application, after having this information in our kitty we can see some best practices to get most of load and get together. This section suggest some scenario which help you when to use get and load in Hibernate.

1. Use get method to determine if an instance exists or not because it can return null if instance doesn't exists in cache and database and use load method to retrieve instance only if you think that instance should exists and non availability is an error condition.

2.  As stated in difference number 2 between get and load in Hibernate. get() method could suffer performance penalty if only identifier method like getId()  is accessed. So consider using load method  if  your code doesn't access any method other than identifier or you are OK with lazy initialization of object, if persistent object is not in Session Cache because load() can return proxy.

How to call get records in Hibernate using get and load method
If you look at below code , there is not much difference on calling get() and load() method, though both are overloaded now and can accept few more parameters but the primary methods looks exactly identical. It's there behavior which makes them different.

//Example of calling get method of Hiberante Session class
Session session = SessionFactory.getCurrentSession();
Employee Employee = (Employee) session.get(Employee.class, EmployeeID);

//Example of calling load method of Hiberante Session
Session session = SessionFactory.getCurrentSession();
Employee Employee = (Employee) session.load(Employee.class, EmployeeID);


That's all on difference between get and load in Hibernate. No doubt Hibernate is a great tool for Object relational mapping but knowing this subtle differences can greatly help to improver performance of your J2EE application, apart from practical reason get vs load method is also frequently asked questions in Hibernate interview, so familiarity with differences between load and get certainly helps.

--
Bst Rgds,
Shakir
.
Skype ID : shakmac4u
Mobile :             +91 9820 386 949 (INDIA)

Knowledge is knowing what to do, skill is knowing how to do, virtue is getting it done. " – Norman Vincent Peale

Love Nature...
 Save a tree. Use Less Papers. Don't print this e-mail unless it's really necessary!!


Thursday, September 13, 2012

EJB2 vs EJB3: EoD ( Ease Of Development )

The deployment descriptors are no longer required; everything can be accomplished using metadata
annotations.

The CMP (Container Managed Persistence) has been simplified; it is now more like Hibernate or JDO.

Programmatic defaults have been incorporated. For example, the transaction model is set to
REQUIRED by default. The value needs to be set only if a specific value other than the default value
is desired.

The use of checked exceptions is reduced; the RemoteException is no longer mandatory on each
remote business method.

Inheritance is now allowed; therefore, beans can extend some of the base code.

The native SQL queries are supported as an EJB-QL (Query Language) enhancement.


--
Bst Rgds,
Shakir
.
Skype ID : shakmac4u
Mobile :             +91 9820 386 949 (INDIA)

Knowledge is knowing what to do, skill is knowing how to do, virtue is getting it done. " – Norman Vincent Peale

Love Nature...
 Save a tree. Use Less Papers. Don't print this e-mail unless it's really necessary!!


Tuesday, January 3, 2012

Fwd: Need Attention........................



---------- Forwarded message ----------
From: Mohammad Zeyaul Haque
Date: Tue, Jan 3, 2012 at 2:42 PM

 

 

 








--
Bst Rgds,
Shakir
.

"Watch your thoughts; they become words. Watch your words; they become actions. Watch your actions; they become habits. Watch your habits; they become character. Watch your character; it becomes your destiny."


Love Nature...
 Save a tree. Use Less Papers. Don't print this e-mail unless it's really necessary!!


Sunday, July 24, 2011

Onsite Opening for Java Professionals at Singapore

Job Location: Singapore

Dear Candidate,
We have excellent onsite opportunity for Java professionals with one of our leading client based in Chennai.

Candidate would be working at Singapore location.

Candidate should posses a valid passport.

Below are the details for the same :

Position : 10
Total exp - 4-6 years
Skills - Java J2ee
Domain - Banking domain
Location - Singapore
Job Type - Permanent
Joining time - 15-30 Days maximum

If interested, please mail me your resume asap to javaj2ee.dubai@gmail.com

Sunday, July 10, 2011

Java Developer - Job opportunity in Dubai

Dear Shakir,



If you have any of your friend with profile matching the job requirements stated below,

 kindly send us the latest CV for our review. 


Job requirement. 


 J2EE Skill Sets (minimum 4 years experience) 

 Springs, AJAX 

 Struts 

 JSP 

 ExtJS Components & Framework 

 iBatis 

 Hibernate 

 Strong in J2EE development. 


Also, furnish us the following details. 


- Current work location 

- No. of years of experience 

- Current CTC 

- Expected CTC 

- Earliest joining period (confirm if you are available in 2 weeks) 

- Marital Status 

- Contact Numbers (Home, Mobile) 


Your immediate response will be much appreciated. 


Thanks & regards, 

Zeya
--
Bst Rgds,
Mohammed Shakir
.
http://jobslinksaroundtheworld.blogspot.com/

( Congratulations!!! Reach out to the Whole New Internet Generation. Now Promote your Business on my Blog - Please email me for availing New Advertisement Services !!!)

"Watch your thoughts; they become words. Watch your words; they become actions. Watch your actions; they become habits. Watch your habits; they become character. Watch your character; it becomes your destiny."

Quran [2:216]  But you may dislike something which is good for you, and you may like something which is bad for you. GOD knows while you do not know.

http://shawnetv2.shawgrp.com/weekly/PublishingImages/GoGreenIcon_rev1.gifLove Nature...
 Save a tree. Use Less Papers. Don't print this e-mail unless it's really necessary!!


Saturday, July 2, 2011

Java - J2ME - DICETECK LLC - Dubai - United Arab Emirates

- 3+ Years of experience in Java/J2EE/J2ME technology. 
Proficient in Canvas, Graphics, and UI design
Proficient in developing J2ME applications using CLDC 1.1, MIDP 1.0/2.0/2.1, NETBEANS/ECL
- Must have good knowledge different APIs, JSRs, 
- Have thorough understanding (at low level) of different channels like SMS, GPRS, USSD
- Must be well versed with using PKI, Secure Elements available in SIM or NFC
- Well versed with latest mobile trends and technologies (NFC, TSM, Mobile Wallet, Location based Advertising, maps, Coupons, mobile POS)
- Plus to have knowledge of different devices and their SDKs/Emulators like Blackberry, Symbian, AndroidiPhoneWindows
- A quick learner of new technologies and ready to switch between different technologies

If your profile is suitable please email your profiles to reshmi@dicetekuae.com


--
Bst Rgds,
Mohammed Shakir
.
http://jobslinksaroundtheworld.blogspot.com/

( Congratulations!!! Reach out to the Whole New Internet Generation. Now Promote your Business on my Blog - Please email me for availing New Advertisement Services !!!)

"Watch your thoughts; they become words. Watch your words; they become actions. Watch your actions; they become habits. Watch your habits; they become character. Watch your character; it becomes your destiny."

Quran [2:216]  But you may dislike something which is good for you, and you may like something which is bad for you. GOD knows while you do not know.

Love Nature...
 Save a tree. Use Less Papers. Don't print this e-mail unless it's really necessary!!


Wednesday, June 15, 2011

Eclipse and MAC OS - A Natural Combination


Why Do Java Development on the Mac?

The ease of use of Mac OS X, the power and stability of UNIX, the integration of Java into Mac OS X and the availability of great development environments like Eclipse make the Mac a great Java development environment.
UNIX users feel at home in Darwin, the robust UNIX-based environment that underlies Mac OS X. That environment is accessible at any time from the Terminal application. All of the standard UNIX utilities and scripting languages are included in Mac OS X—editors such as emacs, vim and pico; file management tools such as cp, mv, ls and gnutar; shell scripts including bash, tcsh (csh) and zsh; and scripting languages such as Perl, PHP, tcl, Ruby and Python. For Java-based web engineers, Apache, Tomcat and JBoss are also included, so you can do JSP development or enterprise class J2EE applications.
Mac OS X also gives you a highly mobile platform. The PowerBook series provides a high-powered workstation that is completely portable and allows you to pick up and go, and then quickly resume work at a new location. Even as you open your laptop, network connections are being reestablished and the computer is immediately up and running.
Apple has made Java a core component of Mac OS X—every Mac ships with the full version of Java 2, Standard Edition included—meaning you have the Java Developer Kit (JDK) and the HotSpot virtual machine (VM) without downloading, installing or configuring anything. And because Apple has optimized Java on Mac OS X, Java applications act as first-class citizens on Mac OS X.
In addition to Eclipse many of the industry leading tools are available, including IntelliJ's IDEA, Borland's JBuilder, Oracle's JDeveloper, and Sun's NetBeans, just to name a few. Mac OS X also includes free developer tools which support rapid Java development right out of the box.

Getting Started

You can get a copy of Eclipse by visiting the Eclipse download page and downloading the latest build. (The current version of Eclipse requires Mac OS X v10.3 Panther.) All builds are delivered as .ZIP files.

Download and install Eclipse

  1. Using your Safari browser, go to the eclipse.org Website.
  2. Click Downloads.
  3. Click Main Eclipse Download Site. If you are not located in North America, use the mirror site closet to your location.
  4. Click the name of the Release Build you want. At the time of this writing, the "3.0 Stream Stable Build" is the latest developer preview of version 3.0. This version is currently fine for daily use.
  5. Under "Eclipse SDK, find "Mac OSX (Mac/Carbon) (Supported Versions)"—the file name is also displayed. Select either the HTTP or FTP download option.
  6. After reading the Notes, click "Download" at the bottom of the page.
  7. When the download is complete, unzip the archive into the appropriate folder.
    (Older versions of Stuffit truncated file names and caused problems with Eclipse. Make sure you are using the appropriate version.)

    Your installation is now complete.
  8. Click the Eclipse icon to launch the IDE.
The first time you run Eclipse, it completes a few remaining install tasks—such as creating a workspace directory—before the Eclipse environment appears.

Work through the tutorials

With Eclipse installed and running, you can begin by looking at an overview of Eclipse features and plugins installed on your system, and then doing a tutorial that guides you through building a simple Java application.
To see the overview of the Eclipse features: from the Help menu, choose About Eclipse Platform
To do a tutorial on building a simple Java application: from the Help menu, choose Java Development User Guide > Getting Started > Basic Tutorial

Resources for More Information


Maven in 5 Minutes


Maven in 5 Minutes

Installation

Maven is a Java tool, so you must have Java installed in order to proceed.
First, download Maven and follow the installation instructions. After that, type the following in a terminal or in a command prompt:
mvn --version
It should print out your installed version of Maven, for example:
Maven version: 2.0.8
Java version: 1.5.0_12
OS name: "windows 2003" version: "5.2" arch: "x86" Family: "windows"
Depending upon your network setup, you may require extra configuration. Check out the Guide to Configuring Maven if necessary.

Creating a Project

On your command line, execute the following Maven goal:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
If you have just installed Maven, it may take a while on the first run. This is because Maven is downloading the most recent artifacts (plugin jars and other files) into your local repository. You may also need to execute the command a couple of times before it succeeds. This is because the remote server may time out before your downloads are complete. Don't worry, there are ways to fix that.
You will notice that the generate goal created a directory with the same name given as the artifactId. Change into that directory.
cd my-app
Under this directory you will notice the following standard project structure.
my-app
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- com
    |           `-- mycompany
    |               `-- app
    |                   `-- App.java
    `-- test
        `-- java
            `-- com
                `-- mycompany
                    `-- app
                        `-- AppTest.java
The src/main/java directory contains the project source code, the src/test/java directory contains the test source, and the pom.xml is the project's Project Object Model, or POM.

The POM

The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively. This project's POM is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Maven Quick Start Archetype</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

What did I just do?

You executed the Maven goal archetype:generate, and passed in various parameters to that goal. The prefix archetype is the plugin that contains the goal. If you are familiar with Ant, you may conceive of this as similar to a task. This goal created a simple project based upon an archetype. Suffice it to say for now that a plugin is a collection of goals with a general common purpose. For example the jboss-maven-plugin, whose purpose is "deal with various jboss items".

Build the Project

mvn package
The command line will print out various actions, and end with the following:
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Thu Oct 05 21:16:04 CDT 2006
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------
Unlike the first command executed (archetype:generate) you may notice the second is simply a single word - package. Rather than a goal, this is a phase. A phase is a step in the build lifecycle, which is an ordered sequence of phases. When a phase is given, Maven will execute every phase in the sequence up to and including the one defined. For example, if we execute the compile phase, the phases that actually get executed are:
  1. validate
  2. generate-sources
  3. process-sources
  4. generate-resources
  5. process-resources
  6. compile
You may test the newly compiled and packaged JAR with the following command:
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
Which will print the quintessential:
Hello World!

Running Maven Tools

Maven Phases

Although hardly a comprehensive list, these are the most common default lifecycle phases executed.
  • validate: validate the project is correct and all necessary information is available
  • compile: compile the source code of the project
  • test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package: take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test: process and deploy the package if necessary into an environment where integration tests can be run
  • verify: run any checks to verify the package is valid and meets quality criteria
  • install: install the package into the local repository, for use as a dependency in other projects locally
  • deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
There are two other Maven lifecycles of note beyond the default list above. They are
  • clean: cleans up artifacts created by prior builds
  • site: generates site documentation for this project
Phases are actually mapped to underlying goals. The specific goals executed per phase is dependant upon the packaging type of the project. For example, packageexecutes jar:jar if the project type is a JAR, and war:war is the project type is - you guessed it - a WAR.
An interesting thing to note is that phases and goals may be executed in sequence.
mvn clean dependency:copy-dependencies package
This command will clean the project, copy dependencies, and package the project (executing all phases up to package, of course).

Generating the Site

mvn site
This phase generates a site based upon information on the project's pom. You can look at the documentation generated under target/site.

Conclusion

We hope this quick overview has piqued your interest in the versitility of Maven. Note that this is a very truncated quick-start guide. Now you are ready for more comprehensive details concerning the actions you have just performed. Check out the Maven Getting Started Guide.


http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html