Samual Sam has Published 2492 Articles

How to work with one database connection object in the entire Java-MySQL application?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

675 Views

Use the singleton design pattern. Here is the Java code that returns a single object −ConnectDatabase.javaimport java.sql.Connection; import java.sql.DriverManager; public class ConnectDatabase {    static Connection conn = null;    public static Connection getConnection() {       if (conn != null) return conn;       String database = ... Read More

FloatBuffer allocate() method in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

83 Views

A new FloatBuffer can be allocated using the method allocate() in the class java.nio.FloatBuffer. This method requires a single parameter i.e. the capacity of the buffer. It returns the new FloatBuffer that is allocated. If the capacity provided is negative, then the IllegalArgumentException is thrown.A program that demonstrates this is ... Read More

KeyPairGenerator getAlgorithm() method in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

59 Views

The algorithm name for the key pair generator can be obtained using the method getAlgorithm() in the class java.security.KeyPairGenerator. This method requires no parameters and it returns the algorithm name for the key pair generator.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class ... Read More

Duration multipliedBy() method in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

58 Views

An immutable copy of a duration where the required duration is multiplied by a value can be obtained using the method multipliedBy() in the Duration class in Java. This method requires a single parameter i.e. the value which is to be multiplied and it returns the immutable copy of the ... Read More

What are the standard attributes that should be passed to a custom tag in a JSP page?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

48 Views

Consider including the following properties for an attribute −S.No.Property & Purpose1nameThe name element defines the name of an attribute. Each attribute name must be unique for a particular tag.2requiredThis specifies if this attribute is required or is an optional one. It would be false for optional.3rtexprvalueDeclares if a runtime expression ... Read More

How to check index within a string of a specified substring in JSP?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

360 Views

The fn:indexOf() function returns the index within a string of a specified substring.SyntaxThe fn:indexOf() function has the following syntax −int indexOf(java.lang.String, java.lang.String)ExampleFollowing is the example to explain the functionality of the fn:indexOf() function − Using JSTL Functions ... Read More

Reserving MySQL auto-incremented IDs?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

219 Views

To reserve MySQL auto-incremented IDs, the syntax is as follows −START TRANSACTION; insert into yourTableName values(), (), (), (); ROLLBACK; SELECT LAST_INSERT_ID() INTO @anyVariableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table reservingAutoIncrementDemo    -> (   ... Read More

FloatBuffer arrayOffset() method in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

59 Views

The offset of the first element of the buffer inside the buffer array is obtained using the method arrayOffset() in the class java.nio.FloatBuffer. If the buffer backed by the array is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; ... Read More

Duration plusMillis() method in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

47 Views

An immutable copy of a duration where some milliseconds are added to it can be obtained using the plusMillis() method in the Duration class in Java. This method requires a single parameter i.e. the number of milliseconds to be added and it returns the duration with the added milliseconds.A program ... Read More

Why is address zero used for the null pointer in C/C++?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

496 Views

Null pointer is a pointer which points nothing.Some uses of null pointer are:b) To initialize a pointer variable when that pointer variable isn’t assigned any valid memory address yet.b) To pass a null pointer to a function argument when we don’t want to pass any valid memory address.c) To check ... Read More

Advertisements