ShortBuffer Compact Method in Java

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

113 Views

The buffer can be compacted using the compact() method in the class java.nio.ShortBuffer. This method does not require a parameter and it returns the new compacted ShortBuffer with the same content as the original buffer. If the buffer 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.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          ShortBuffer buffer = ShortBuffer.allocate(n);          buffer.put((short)25);          buffer.put((short)18);   ... Read More

Evaluation of Boolean Expression

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

510 Views

We write a program in 8085 in the assembly language just for the evaluation of only wo Boolean expressions of 4 variables by using the interface of logic controller. The output of the program should be logically tested automatically by the output by the input changing from the inputs from 0000, 0001, … to 1111 just to press any key.Let us say we want to evaluate the following Boolean expressions.First of all, truth table for the Boolean expressions is written down as shown in the following table.PQRSXY000010000100001010001100010010010100011010011100100001100101101010101100110000110111111000111100The inputs of the PQRS gets connected to PB3, PB2, PB1, and PB0 of ... Read More

Tuple setAt0 Method for Unit Class in Java

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

115 Views

The setAt0() method is used to set the Unit value in JavaTuples and a copy with a new value at index 0.Let us first see what we need to work with JavaTuples. To work with the Unit class in JavaTuples, you need to import the following package −import org.javatuples.Unit;Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE to run Unit Class in Java Tuples, then Right Click Project ->Properties ->Java Build Path ->Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Unit; public class Demo {    public static void main(String[] ... Read More

Load WebView from Cache in Android

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

1K+ Views

This example demonstrate about How to load webview from cache in android.Step 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 web view to show mylocation.org.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.app.ProgressDialog; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.EditText; public class MainActivity extends AppCompatActivity {    @RequiresApi(api = Build.VERSION_CODES.P)    @Override    protected ... Read More

Get Month from LocalDateTime in Java

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

249 Views

The month name for a particular LocalDateTime can be obtained using the getMonth() method in the LocalDateTime class in Java. This method requires no parameters and it returns the month name in the year.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The month is: " + ldt.getMonth());    } }OutputThe LocalDateTime is: 2019-02-18T23:15:30 The month is: FEBRUARYNow let us understand the above program.First the LocalDateTime is ... Read More

Collectors.partitioningBy() Method in Java 8

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

2K+ Views

The partioningBy() method returns a Collector that partitions the input elements according to a Predicate, and organizes them into a Map.The syntax is as follows.static Collector partitioningBy(Predicate

Use Sublist in Android CopyOnWriteArrayList

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

159 Views

Before getting into the example, we should know what CopyOnWriteArrayList is. It is a thread-safe variant of ArrayList and operations add, set, and so on by making a fresh copy of the underlying array.This example demonstrates about How to use subList() in android CopyOnWriteArrayListStep 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 a text view to show CopyOnWriteArrayList elements.Step 3 − Add the following code ... Read More

Select Results from the Middle of a Sorted List in MySQL

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

933 Views

To select results from the middle of a sorted list, use ORDER BY clause along with LIMIT.Let us first create a table. Following is the query −mysql> create table sortedListDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(100)    -> ); Query OK, 0 rows affected (0.46 sec)Following is the query to insert some records in the table using insert command −mysql> insert into sortedListDemo(StudentName) values('John'); Query OK, 1 row affected (0.62 sec) mysql> insert into sortedListDemo(StudentName) values('Sam'); Query OK, 1 row affected (0.18 sec) mysql> insert into sortedListDemo(StudentName) values('Adam'); ... Read More

C++ Program to Implement Direct Addressing Tables

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

672 Views

This is a C++ program to implement Direct Addressing Tables. Direct Addressing Tables are used when each element has a key drawn from a universal set S = {0, 1, . . . ,n − 1} where n isn’t too large and each key is unique. It facilitates fast insertion, searching and deletion operations.Functions and pseudocodesBegin    insert():       Take the table variables word and key as argument.       T[ x.key ] = x, where x is a value of key.    delete():       Take the table variables word and key as argument.   ... Read More

Use InnoDB and MyISAM Tables in a Single Database in MySQL

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

564 Views

Yes, you can use InnoDB and MyISAM tables in one database or combine both of them in a single database. This is the recommended way.Here is the demo of both MyISAM and InnoDB in a one database. The following is the database and both the table types InnoDB and MyISAM. The query to create a database is as follows −mysql> create database BothInnoDBandMyISAM; Query OK, 1 row affected (0.20 sec) mysql> use BothInnoDBandMyISAM; Database changedI have a database with name ‘BothInnoDBandMyISAM’.First the table has engine type InnoDB. The query to create a table with engine InnoDB is as follows −mysql> ... Read More

Advertisements