Create Stream from a String Byte Array in Java

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

607 Views

Create an input stream and set the string:DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream("pqrs tu v wxy z".getBytes()));The getBytes() method is used to convert a string into sequence of bytes and returns an array of bytes.Now return one single input byte:(char) inputStream.readByte()Exampleimport java.io.ByteArrayInputStream; import java.io.DataInputStream; public class Demo { public static void main(String[] args) throws Exception {    DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream("pqrs tu v wxy z".getBytes()));       System.out.print((char) inputStream.readByte());       System.out.print((char) inputStream.readByte());       inputStream.close();    } }OutputPq

Provider Keys Method in Java

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

150 Views

An enumeration of the keys of the required hash table can be obtained using the keys() method in the class java.security.Provider. This method requires no parameters and it returns the enumeration of the keys of the hash table.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) throws Exception {       try {          Signature sign = Signature.getInstance("DSA");          Provider p = sign.getProvider();          Enumeration enumeration = p.keys();          System.out.println("The enumeration of ... Read More

Remove Data from LinkedHashSet in Android

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

121 Views

This example demonstrate about How to remove data from Linked hashset in AndroidStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                                       In the above code, we have taken the name and record number as Edit text, when user click on save button it will store the data into arraylist. Click on delete ... Read More

Insert Rows into a ResultSet in JDBC

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

1K+ Views

You can retrieve the contents of a table as a ResultSet and, insert a new row to it directly. To do so, first of all, you need to make sure your ResultSet is updatable.The moveToInsertRow() method of the ResultSet interface navigates the cursor to the position where you need to insert the next record. Therefore, move the cursor to the appropriate position to insert a row using this method.The updateXXX() methods of the ResultSet interface allows you to insert/update values into the ResultSet object.Add values to the new row using these methods for example if you need to insert an ... Read More

LocalDateTime withHour Method in Java

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

69 Views

An immutable copy of a LocalDateTime with the hour altered as required is done using the method withHour() in the LocalDateTime class in Java. This method requires a single parameter i.e. the hour that is to be set in the LocalDateTime and it returns the LocalDateTime with the hour altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt1);       LocalDateTime ldt2 = ldt1.withHour(5);       ... Read More

Call Stored Procedure with Output Parameters Using JDBC

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

10K+ Views

A. Stored procedures are sub routines, segment of SQL statements which are stored in SQL catalog. All the applications that can access Relational databases (Java, Python, PHP etc.), can access stored procedures.Stored procedures contain IN and OUT parameters or both. They may return result sets in case you use SELECT statements. Stored procedures can return multiple result sets.You can call a stored procedure using the following syntax:CALL procedure_name (input_parameter1, input_parameter2, input_parameter3)JDBC provides a standard stored procedure SQL escape syntax using which you can procedures in all RDBMSsTo call a stored procedure using a JDBC program you need to:Register the driver: ... Read More

Group By One Column and Select All Data in MySQL

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

1K+ Views

Yes, you can use group_concat() for this. Let us first create a table −mysql> create table groupByOneSelectAll    -> (    -> StudentDetails varchar(100),    -> StudentName varchar(100)    -> ); Query OK, 0 rows affected (0.91 sec)Following is the query to insert some records in the table using insert command −mysql> insert into groupByOneSelectAll values('StudentFirstName', 'John'); Query OK, 1 row affected (0.14 sec) mysql> insert into groupByOneSelectAll values('StudentFirstName', 'Chris'); Query OK, 1 row affected (0.21 sec) mysql> insert into groupByOneSelectAll values('StudentFirstName', 'Robert'); Query OK, 1 row affected (0.65 sec) mysql> insert into groupByOneSelectAll values('StudentFirstName', 'Bob'); Query ... Read More

Get First N Characters from a MySQL Column

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

984 Views

Use SUBSTRING() to get first N characters from a MySQL column. Let us first create a table −mysql>create table DemoTable (    Information text ); Query OK, 0 rows affected (2.63 sec)Insert records in the table using insert command −mysql>insert into DemoTable values('MySQL is a structured query language'); Query OK, 1 row affected (0.13 sec)Following is the query to display all records from the table using select statement −mysql>select *from DemoTable;This will produce the following output −+--------------------------------------+ | Information                         | +--------------------------------------+ | MySQL is a structured query ... Read More

How the Tech Industry Manipulates Its Customers

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

116 Views

Did you know all the articles you read about the reviews of a particular product: about its pros, cons, and ratings from some popular, so-called "authentic and genuine" tech blogs are actually,  just paid ones?In fact, because of these people, the articles with the original product review are pushed to the very end of the priority line by the big tech companies, that can’t seem to get enough affirmation to their success. In some cases, there is no place left for constructive criticism. As you know, criticism also plays an important part in the improvement of technology and its impact on the consumer. ... Read More

ShortBuffer toString Method in Java

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

171 Views

A string that provides the buffer state in a summary can be obtained using the method toString() in the class java.nio.ShortBuffer. This method requires no parameters and it returns the buffer state in a summary using a string.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          ShortBuffer buffer = ShortBuffer.allocate(n);          buffer.put((short)12);          buffer.put((short)91);          buffer.put((short)25);       ... Read More

Advertisements