Object Oriented Programming Articles

Page 496 of 589

Difference between sequence and identity in Hibernate

Himanshu shriv
Himanshu shriv
Updated on 21-Jan-2020 11K+ Views

Hibernate or JPA support 4 different types of primary key generator. These generators are used to generate primary key while inserting rows in the database. Below are the primary key generator −GenerationType.AUTOGenerationType. IDENTITYGenerationType.SEQUENCE GenerationType.TABLEGenerationType. IDENTITY − In identity , database is responsible to auto generate the primary key. Insert a row without specifying a value for the ID and after inserting the row, ask the database for the last generated ID. Oracle 11g does not support identity key generator. This feature is supported in Oracle 12c. GenerationType. SEQUENCE − In sequence, we first ask database for ...

Read More

Difference between Collection.stream().forEach() and Collection.forEach() in Java

Himanshu shriv
Himanshu shriv
Updated on 21-Jan-2020 1K+ Views

Collection.stream().forEach() and Collection.forEach() both are used to iterate over collection. Collection.forEach() uses the collection’s iterator. Most of the collections doesn’t allow the structurally modification while iterating over them. If any element add or remove while iteration they will immediately throw concurrent modification exception. If Collection.forEach() is iterating over the synchronized collection then they will lock the segment of the collection and hold it across all the calls. Collection.stream().forEach() is also used for iterating the collection but it first convert the collection to the stream and then iterate over the stream of the collection therefore the processing order is undefined. ...

Read More

Difference between save() and persist() in Hibernate

Himanshu shriv
Himanshu shriv
Updated on 21-Jan-2020 23K+ Views

Save() and persist() both methods are used for saving object in the database. As per docs −Save() − Persist the given transient instance, first assigning a generated identifier. (Or using the current value of the identifier property if the assigned generator is used.) This operation cascades to associated instances if the association is mapped with cascade="save-update".As per docs −persist() − Make a transient instance persistent. This operation cascades to associated instances if the association is mapped with cascade="persist". The semantics of this method are defined by JSR-220. Sr. No.Keysave()persist()1Basic It stores object in databaseIt also stores object ...

Read More

Difference Between get() and load() in Hibernate

Himanshu shriv
Himanshu shriv
Updated on 21-Jan-2020 27K+ Views

In hibernate, get() and load() are two methods which is used to fetch data for the given identifier. They both belong to Hibernate session class. Get() method return null, If no row is available in the session cache or the database for the given identifier whereas load() method throws object not found exception. Sr. No.KeyGet()Load()1Basic It is used to fetch data from the database for the given identifier It is also used to fetch data from the database for the given identifier 2Null Object It object not found for the given identifier then it will return null ...

Read More

Difference Between First level cache and Second level cache in Hibernate

Himanshu shriv
Himanshu shriv
Updated on 21-Jan-2020 11K+ Views

Hibernate support two type of cache one is first level cache and other is second level cache. First level cache is a session level cache and it is always associated with session level object. This type of cache is used for minimizing Db interaction by caching the state of the object. That is instead of updating after every modification done in the transaction, it updates the transaction only at the end of the transaction.Second level cache is session factory level cache and it is available across all sessions.While running the transactions, in between it loads the objects at the Session Factory level, ...

Read More

How to implement DoublePredicate using lambda and method reference in Java?

raja
raja
Updated on 16-Jan-2020 350 Views

DoublePredicate is a built-in functional interface defined in java.util.function package. This interface can accept one double-valued parameter as input and produces a boolean value as output. DoublePredicate interface can be used as an assignment target for a lambda expression or method reference. This interface contains one abstract method: test() and three default methods: and(), or() and negate().Syntax@FunctionalInterface public interface DoublePredicate { boolean test(double value) }Example of lambda expressionimport java.util.function.DoublePredicate; public class DoublePredicateLambdaTest { public static void main(String args[]) { DoublePredicate doublePredicate = (double input) -> { ...

Read More

How to match bold fields in a HTML script using a regular expression in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 10-Jan-2020 448 Views

The regular expression "\S" matches a non-whitespace character and the following regular expression matches one or more non space characters between the bold tags."(\S+)"Therefore to match the bold fields in a HTML script you need to −Compile the above regular expression using the compile() method.Retrieve the matcher from the obtained pattern using the matcher() method.Print the matched parts of the input string using the group() method.Exampleimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Example {    public static void main(String[] args) {      String str = "This is an example>/b> HTML script.";       //Regular expression to match contents of ...

Read More

How to detect duplicate values in primitive Java array?

karthikeya Boyini
karthikeya Boyini
Updated on 19-Dec-2019 2K+ Views

To detect the duplicate values in an array you need to compare each element of the array to all the remaining elements, in case of a match you got your duplicate element.One solution to do so you need to use two loops (nested) where the inner loop starts with i+1 (where i is the variable of outer loop) to avoid repetitions in comparison.Exampleimport java.util.Arrays; import java.util.Scanner; public class DetectDuplcate {        public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter the size of the array that is to ...

Read More

How to create array of strings in Java?

Sai Subramanyam
Sai Subramanyam
Updated on 19-Dec-2019 2K+ Views

In Java, you can create an array just like an object using the new keyword. The syntax of creating an array in Java using new keyword −type[] reference = new type[10];Where, type is the data type of the elements of the array.reference is the reference that holds the array.And, if you want to populate the array by assigning values to all the elements one by one using the index −reference [0] = value1; reference [1] = value2;You can declare an array of Strings using the new keyword as &mius;String[] str = new String[5]; And then, you can populate the string ...

Read More

How to add elements to the midpoint of an array in Java?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 19-Dec-2019 306 Views

Apache commons provides a library named org.apache.commons.lang3 and, following is the maven dependency to add library to your project.           org.apache.commons       commons-lang3       3.0     This package provides a class named ArrayUtils. You can add an element at a particular position in an array using the add() method of this class.Exampleimport java.util.Arrays; import org.apache.commons.lang3.ArrayUtils; public class AddingElementToMidPoint {    public static void main(String args[]) {       int[] myArray = {23, 93, 30, 56, 92, 39};       int eleToAdd = 40;       int position= myArray.length/2;       int [] result = ArrayUtils.add(myArray, position, eleToAdd);       System.out.println(Arrays.toString(result));    } }Output[23, 93, 30, 40, 56, 92, 39]

Read More
Showing 4951–4960 of 5,881 articles
« Prev 1 494 495 496 497 498 589 Next »
Advertisements