Programming Articles - Page 2142 of 3366

Difference between save() and persist() in Hibernate

Himanshu shriv
Updated on 21-Jan-2020 07:33:48

22K+ 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 in database2Return Type It return generated id and return type is ... Read More

Difference Between JDBC and Hibernate

Himanshu shriv
Updated on 14-Jul-2020 09:24:01

6K+ Views

JDBC is acronym of Java database connectivity. It is used to connect your application to the database and transactions . It is an open source Java api.  Hibernate is also used for connect your application to database and to do database related transactions but with different approach. It has a object relationship library which mapped the tables and columns of the database with the java object. It enables object oriented programming in database. Hibernate provides HQL to access the data from the database. Sr. No.KeyJDBCHibernate1Basic It is database connectivity technology It is a framework, 2Lazy Loading It does not support lazy loading Hibernate support ... Read More

Difference Between get() and load() in Hibernate

Himanshu shriv
Updated on 21-Jan-2020 07:19:37

26K+ 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 object It will throw object not found exception 3Lazy ... Read More

How to implement IntBinaryOperator using lambda expression in Java?

raja
Updated on 14-Jul-2020 09:22:47

453 Views

IntBinaryOperator is a functional interface in Java 8 from java.util.function package. This interface expects two parameters of type int as input and produces an int type result. IntBinaryOperator can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsInt().Syntax@FunctionalInterface public interface IntBinaryOperator {  int applyAsInt(int left, int right) }Exampleimport java.util.function.*; public class IntBinaryOperatorTest {    public static void main(String[] args) {       IntBinaryOperator test1 = (a, b) -> a + b; // lambda expression       System.out.println("Addition of two parameters: " + test1.applyAsInt(10, 20));       IntFunction test2 = new IntFunction() {     ... Read More

Difference Between First level cache and Second level cache in Hibernate

Himanshu shriv
Updated on 21-Jan-2020 07:12:08

10K+ 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 Function interface with lambda expression in Java?

raja
Updated on 14-Jul-2020 09:16:29

3K+ Views

Function interface is a functional interface from java.util.function package. This interface expects one argument as input and produces a result. Function interface can be used as an assignment target for a lambda expression or method reference. It contains one abstract method: apply(), two default methods: andThen() and compose() and one static method: identity().Syntax@FunctionalInterface public interface Function {  R apply(T t); }Exampleimport java.util.function.Function; public class FunctionTest {    public static void main(String[] args) {       Function f1 = i -> i*4;   // lambda       System.out.println(f1.apply(3));       Function f2 = i -> i+4; // lambda   ... Read More

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

raja
Updated on 14-Jul-2020 09:12:01

518 Views

DoubleSupplier interface is a built-in functional interface defined in java.util.function package. This functional interface doesn’t expect any input but produces a double-valued output. DoubleSupplier interface can be used as an assignment target for lambda expression and method reference. This interface contains only one abstract method: getAsDouble().Syntax@FunctionalInterface public interface DoubleSupplier {    double getAsDouble(); }Example of Lambda Expressionimport java.util.concurrent.ThreadLocalRandom; import java.util.function.DoubleSupplier; public class DoubleSupplierLambdaTest {    public static void main(String args[]) {       DoubleSupplier getRandomDouble = () -> {    // lambda expression          double doubleVal = ThreadLocalRandom.current().nextDouble(0000, 9999);          return Math.round(doubleVal);       };       ... Read More

Find elements of an Array which are Odd and Even using STL in C++

Sunidhi Bansal
Updated on 20-Jan-2020 10:18:07

332 Views

Given with an array and the task is to find the number of odd and even elements in an array using standard template library in C++.To solve this problem we are using the function count_if() present in C++ standard template library. What is a count_if() function?Syntaxcount_if(LowerBound, UpperBound, function)Description − This function returns the number of elements in an array that satisfies the given condition. It takes three parameters.Lower Bound − It points to the first element of an array or any other sequence.Upper Bound − It points to the last element of an array or any other sequence.Function − It ... Read More

Find elements of an array which are divisible by N using STL in C++

Sunidhi Bansal
Updated on 20-Jan-2020 10:26:44

261 Views

Given with an array and the task is to find the number which are divisible by N using standard template library in C++.To solve this problem we are using the function count_if() present in C++ standard template library.What is a count_if() function?Syntaxcount_if(LowerBound, UpperBound, function)Description − This function returns the number of elements in an array that satisfies the given condition. It takes three parameters.Lower Bound − It points to the first element of an array or any other sequence.Upper Bound − It points to the last element of an array or any other sequence.Function − It returns the Boolean value ... Read More

isprint() Working with C++

Sunidhi Bansal
Updated on 20-Jan-2020 10:15:22

367 Views

Isprint() in C++ is inbuilt function in “cctype.h” header file which checks whether the character is printable or not.Isprint returns true for constant cases as Isprint aside from the house character (' '), that returns true.A locale-specific model version of this function (Isprint) exists in cctype header file.-Isprint() function can be used to check any Non-Printing character in a series of sentences.-Isprint() is an Inbuilt function that provides efficient way to handle non printing characters-Isprint() helps to minimize the lines of code for programmer.-Isprint() is in true sense decreases the compilation time of program.Including cctype.h in your program not only ... Read More

Advertisements