Posts

Showing posts from December, 2014

java program to find missing numbers in an array

Most frequently asked interview question specially in banking and telecom domain. Interviewer wants to check your logical analysis and problem solving skills by asking these types of questions. Sometimes you will get the signature of the methods and your job is to complete that methods for example, I faced an interview with one of the world's largest telecom domain company, where there is a question sheet with signature of the methods as given below. public static int[] findMissingNumbers(int[] numArray, int firstNum,int lastNum) {} Description : Complete the above method to find all the missing numbers from an sorted array. The numArray is an sorted array and firstNum is the starting number from an array and the lastNum is the last number in an numArray. For example, if numArray is like 3,4,5,6,8,10 and firstNum is 1 and the lastNum is 10 then out put would be an array of 1,2,7,9. Well there is a lots of way to solve this problem, and here we are going to use one of them. ...

hilo generator in hibernate example

Image
In hibernate generator classes are used to generate unique identifiers for instances of the persistence class. Hibernate provides the list of built in generator classes to generate unique identifiers, all the generator classes implements the org.hibernate.id.IdentifierGenerator interface, and if your needs of unique identifiers is not solved by using built in generator classes, then you can create your own generator classes by implementing org.hibernate.id.IdentifierGenerator interface. Here is a example of custom generator class via implementing org.hibernate.id.IdentifierGenerator interface. In this post we are going to show you, how to use hilo generator in your mapping file. The hilo strategy is based on high/low algorithm to efficiently generate unique identifiers of type long,int or short, it uses a separate table for the hi value. The default table uses for the hi value is hibernate_unique_key with column hi_next as a hi value. Instead of default table you can create you...

identity generator in hibernate example

Image
In hibernate generator classes are used to generate unique identifiers for instances of the persistence class. Hibernate provides the list of built in generator classes to generate unique identifiers, all the generator classes implements the org.hibernate.id.IdentifierGenerator interface, and if your needs of unique identifiers is not solved by using built in generator classes, then you can create your own generator classes by implementing org.hibernate.id.IdentifierGenerator interface. Here is a example of custom generator class via implementing org.hibernate.id.IdentifierGenerator interface. In this post we are going to show you the implementation of identity generator, one of my favorite generator provided by hibernate. The identity generator is not supported by all the databases like oracle database does not support this, but DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL supports identity generator . If no <generator> element is specified, then hibernate will ass...

assigned generator in hibernate example

Image
In hibernate generator class is used to generate unique identifiers for instances of the persistence class. Hibernate provides the list of built in generator classes to generate unique identifiers, all the generator classes implements the org.hibernate.id.IdentifierGenerator interface, and if your needs of unique identifiers is not solved by using built in generator classes, then you can create your own generator classes by implementing org.hibernate.id.IdentifierGenerator interface. Here is a example of custom generator class via implementing org.hibernate.id.IdentifierGenerator interface. The default generator class provided by hibernate is assigned , If you explicitly not provide any <generator> element then hibernate will used assigned as the <generator> element. If we are using assigned as our generator class, then we must have to explicitly provide the primary key values of the persistence object before the object get persist. Lets create a simple project to s...

Custom generator class in hibernate using annotation example

Image
In this post we are going to show you, how to create custom generator class in hibernate. In hibernate generator class is used to generate unique identifiers for instances of persistence class. Hibernate provides you the list of default generator classes and of course they all have advantages and disadvantages. But sometimes it may, you need more specialized unique identifiers for your persistence classes, It may that your requirement is not fulfilled by the default generator class and your job is to create your own generator class. For example for one of our project requirement was to create an employee id with the combination of R&D000001,R&D000002..and so on. In this post we are going to implement the same, It will first fetched the latest created employee id from the database and add +1 value to it each time we insert new employee into the database . Lets create our own generator class and implement in our persistence class. In hibernate all default generator classes are...

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104) at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:209) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887) at org.hibernate.cfg.Configuration.build...

transient keyword in java with example

Last updated: September 2026 — rewritten with examples and interview Q&A. The transient keyword almost always comes up right after serialization in an interview. The interviewer has just asked how serialization works — now they want to know if you understand what gets left out . What transient does transient marks a field to be skipped during serialization . When the object is deserialized, transient fields are restored to their default values — 0 / false for primitives, null for references. The constructor does not run, so nothing re-initializes them. It applies to fields only — never to methods or classes. The classic use case: fields that must not travel with the object, like passwords, or fields that can't be serialized, like Thread , Socket , or stream objects (leaving a non-serializable field non-transient gives you NotSerializableException at runtime). transient in code public class User implements Serializable { private String username; private tr...

What is the use of serialVersionUID in serialization in java

Image
Last updated: September 2026 — refreshed with modern Java notes and interview Q&A. In java all the Serializable classes are automatically given a unique identifier if you explicitly not defined. The unique identifier of the class is maintained by serialVersionUID field. So the serialVersionUID is a unique identifier of the serializable classes, and the value of serialVersionUID is used at the time of de-serialization to verify that the sender and receiver of a serialized object have loaded a class for that object that are compatible with respect to serialization. The default value of serialVersionUID is computed based on your class's field, method, interfaces etc. It may be vary from environment to environment or compiler to compiler. That's why you always need to define explicitly the value of serialVersionUID. It's better to redefine the value of serialVersionUID each time you changed the structure of your class. Syntax to define serialVersionUID: ANY-ACCESS-M...

Serializable vs Externalizable in Java Serialization

Last updated: September 2026 — rewritten with a comparison table, code examples, and interview Q&A. "Serializable vs Externalizable" is a favorite second-round interview question, especially for 3–5 year experienced roles. The interviewer isn't testing whether you've memorized two interfaces — they're testing whether you understand who controls the byte format and what that costs. If you haven't read the basics yet, start with what serialization is . Serializable vs Externalizable: the differences Feature Serializable Externalizable Interface type Marker interface — no methods Two methods: writeExternal() , readExternal() Who controls the format The JVM (default protocol) You (custom protocol) Effort Zero — just implement the interface You hand-write the field logic Constructor on deserialization Not called Public no-arg constructor is called (mandatory) Performance Slower — uses reflection Faster — direct method calls, smaller streams Custo...

What is externalizable interface in java

Last updated: September 2026 — refreshed with modern Java notes and interview Q&A. In this post we will learn about the java.io.Externalizable interface. Externalizable is an another way of serializing an object in java. To serialized an object your class or any of it's super classes must implements either the Serializable interface or it's sub interface called Externalizable. Before starting Externalizable you must have to know what serialization is? here is a Serialization tutorial . java.io.Externalizable is an interface unlike java.io.Serializable interface it has two methods called writeExternal() and readExternal(). Externalizable interface is use to serialized an object, but serialization of an object is already achieved by implementing Serializable marker interface then why additional interface called Externalizable? Well Externalizable interface extends Serializable interface and allows you to customize the default protocol of serialization with the help ...