July 13 2015

Hibernate cascade delete

Hibernate cascade delete

When cascade=”delete” is declared on association, hibernate deletes all the persistent instances of the association (children) whenever the delete operation is performed on object. If you don’t not use cascade delete, you have to delete all the child objects one by one explicitly before deleting the parent object.

Hibernate cascade delete example

In the below example, ’CascadeType.DELETE’ is declared for the association. Whenever delete operation is performed on Student object, all the associated StudentMarks records will be deleted along with Student record.

select * from student;

STUDENT_ID STUDENT_NAME FATHER_NAME DATE_OF_BIRTH COURSE
105 PAUL GEORGE 5/22/2015 MS

select * from student_marks; Continue reading

July 13 2015

Hibernate cascade delete orphan

Hibernate cascade delete orphan

Deletes the persistent instance that has been removed (from collection) or dereferenced (object).The orphan delete allows us to delete the child entity by removing or dereferencing it from parent instead of deleting the child entity’s directly.

Hibernate cascade delete orphan Example

select * from student;

STUDENT_ID STUDENT_NAME FATHER_NAME DATE_OF_BIRTH COURSE
105 PAUL GEORGE 5/22/2015 MS

select * from student_marks; Continue reading

July 9 2015

Core java interview questions and answers for freshers

Core java interview questions and answers for freshers

  1. Legal identifier?

Names used for classes, methods, interfaces and variables are called Identifiers. The first character must start with a letter or currency character ($) or underscore (_). It cannot start with number. After first character, identifier can contain letters, numbers, currency symbol ($) and underscore (_) in any combination. Read more

  1. Class?

A class can be defined as a template that describes the state and behaviors that object of its type support.

public class Student {

// variables and methods

} Continue reading

July 7 2015

Static variables in java

Static variables in java

The variables which are marked with static modifier are called static variables. Static variables will have only one copy in memory and that is shared by all the objects, any modification to it will also affect other objects. Static variables are also called as class variables.

The instance variables are per object whereas static variables are per class. Static variable can be accessed with class name as well as object reference.

Local variables cannot be marked as static. Static variable are not of object’s state and are not serialized. Static variable gets loaded when class is loaded by ClassLoader, and would be removed when it is unloaded.

Example Continue reading

July 3 2015

Local variables in java

Local variables in java

Variables which are declared inside the methods are called local variables. They are visible only inside the method in which they are declared. Local variables cannot have any access specifiers and they cannot be declared with any modifiers except final.

Syntax

[modifier] datatype variables=intialvalue;

modifier – final

datatype – primitives | object references

Local variables do not get default values like instance variables and have to be initialized before they are used. Continue reading

July 2 2015

Instance variables in java

Instance variables in java

Instance variables are the variables defined inside the class and outside the methods. Instance variables can be accessible throughout the class. They are also called object variables. Instance variables are accessible using object and every object will have its own copy of the class’s instance variables.

Syntax

accessspecifier  [modifier] datatype variablename;

access specifier – public | protected | default | private

modifier – final | transient

datatype – primitives | object references Continue reading

June 30 2015

Finally block in java

Finally block in java              

A try and catch block can have optional finally block which is always executed whether an exception is thrown or not. Finally block is generally used to release the memory, close the files and connections regardless of what happens in the try block.

If try blocks executes without any exception, finally block will be executed immediately after the try block. If there is an exception occurred in try block, finally block will be executed after matching catch block execution. Continue reading

June 26 2015

Interface example in java

Interface example in java

An interface is 100 % abstract class. It cannot be instantiated.  Interface is created when all the methods in the class have different behavior for subclasses and to enforce the subclasses to provide the implementation according to specific type.

An interface is a contract. The classes which are implementing the interface has to provide implementation for all the methods of interface. It can be used to achieve loose coupling.

To create an interface, use the interface keyword instead of the class keyword. To make a class that conforms to an interface, use the implements keyword instead of extends.

public interface EmployeeDao {

// declaration of methods

} Continue reading

June 24 2015

Java abstract class example

Java abstract class example

Abstract class

An abstract class cannot be instantiated. If a class contains one or more abstract methods, the class has to be declared as abstract. The first concrete (non-abstract) class which is extending the abstract class must implement all the abstract methods. An abstract class can have both abstract and non-abstract methods.

public abstract class Employee {  }

Abstract method

Abstract method is a method with only declaration and without implementation. Abstract method ends with a semi colon instead of curly braces. Abstract methods are created when there is different behavior for subclasses and to enforce the subclasses to provide the implementation according to specific type. Abstract methods cannot be private. Continue reading

June 20 2015

Jsp usebean example

Jsp usebean example

<jsp:useBean> action tag is used to instantiate or locate java bean instance and associate it with a jsp scripting variable.

Attributes

id – represents the name of java bean

scope – represents the scope of the java bean. Valid values are page, request, session and application. The default values is page.

class – takes the qualified class name to create a java bean if java bean is not available in specific scope

type – takes the qualified class name or interface name. A bean can implement many interfaces, the desired interface type can be specified in type attribute. Type attribute can be used with or without class or beanName attributes. If only type attribute is specified and no matching object is found, jsp container throws InstantiationException exception Continue reading

Category: Jsp | LEAVE A COMMENT