Get Value Stored in a Byte as Unsigned Integer in Java

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

281 Views

Let us first create signed byte −byte signedVal = -100;Now convert a byte to an unsigned integer −int unsignedVal = Byte.toUnsignedInt(signedVal);Examplepublic class Demo {    public static void main(String[] args) {       byte signedVal = -100;       int unsignedVal = Byte.toUnsignedInt(signedVal);       System.out.println("Signed value (byte) = " + signedVal);       System.out.println("Unsigned value (byte) = " + unsignedVal);    } }OutputSigned value (byte) = -100 Unsigned value (byte) = 156

C++ Program to Implement Gauss-Seidel Method

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

4K+ Views

Gauss Seidel method is used to solve linear system of equations in iterative method. This is a C++ Program to Implement Gauss Seidel Method.AlgorithmBegin    Take the dimensions of the matrix p and its elements as input.    Take the initials values of x and no of iteration q as input.    While q>0       Make a for loop i = 0 to p-1          initialize n[i] = (b[i] / a[i][i]).             Make a for loop i = 0 to p-1             If (j == ... Read More

Built-in Function for Week of the Month in MySQL

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

846 Views

There is no standard function to get week of month in MySQL. You need to use the following syntax −SELECT WEEK(yourDateColumnName, 5) - WEEK(DATE_SUB(yourDateColumnName, INTERVAL DAYOFMONTH(yourDateColumnName) - 1 DAY), 5) + 1 AS anyAliasName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table FirstWeekOfMonth -> ( -> Id int NOT NULL AUTO_INCREMENT primary key, -> yourdate date -> ); Query OK, 0 rows affected (2.50 sec)Now you can insert some records in the table ... Read More

ShortBuffer asReadOnlyBuffer Method in Java

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

106 Views

A read-only short buffer can be created using the contents of a buffer with the method asReadOnlyBuffer() in the class java.nio.ShortBuffer. The new buffer cannot have any modifications as it is a read-only buffer. However, the capacity, positions, limits etc. of the new buffer are the same as the previous buffer.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(5);          buffer.put((short)12); ... Read More

Clock System Method in Java

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

275 Views

The current instance of the clock for the required zoneID can be obtained using the method system() in Clock Class in Java. This method requires a single parameter i.e. the zoneID or the time zone and it returns the current instance of the clock for that time zone.A program that demonstrates this is given as follows −Exampleimport java.time.*; public class Main { public static void main(String[] args) { ZoneId zone = ZoneId.of("Australia/Melbourne"); Clock c = Clock.system(zone); ZonedDateTime zdt = ... Read More

Add Value to Unit Tuple in Java

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

191 Views

The addAtX() method is used to add value to the Tuple. The index can be set here with the X i.e. the place where the value gets added.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;Here, we have also used the Pair class, therefore import the following package also −import org.javatuples.Pair;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 ... Read More

Architecture of JDBC

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

4K+ Views

If you want to develop a Java application that communicates with a database, you should use JDBC API. A driver is the implementation of the said API; various vendors provide various drivers, you need to use a suitable driver with respect to the database you need to communicate with. The driver manager loads the driver and manages the driver.Following are the components of JDBC:JDBC DriverManager: The DriverManager class of the java.sql package manages different types of JDBC drivers. This class loads the driver classes. In addition to this whenever a new connection establishes it chooses and loads the suitable driver ... Read More

HashCode Method of CopyOnWriteArrayList in Java

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

221 Views

To get the hash code value of the list, you need to use the hashCode() method of the CopyOnWriteArrayList class.The syntax is as followspublic int hashCode()To work with CopyOnWriteArrayList class, you need to import the following packageimport java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class hashCode() method in JavaExample Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList arrList = new CopyOnWriteArrayList();       arrList.add(30);       arrList.add(40);       arrList.add(60);       arrList.add(70);       arrList.add(90);       arrList.add(100);       arrList.add(120);   ... Read More

ListIterator Method of AbstractList Class in Java

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

127 Views

The listIterator() method of the AbstractList class in Java is used to return a list iterator over the elements in this list.The syntax is as follows.public ListIterator listIterator()Here, ListIterator is an iterator for lists.To work with the AbstractList class, import the following package.import java.util.AbstractList;For ListIterator, import the following package.import java.util.ListIterator;The following is an example to implement listIterator() method of the AbstractlList class in Java.Example Live Demoimport java.util.ArrayList; import java.util.ListIterator; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new ArrayList();       myList.add(75);       myList.add(100);       ... Read More

Best Replacement of OnItemClickListener in Android RecyclerView

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

142 Views

This example demonstrates about Best replacement of onItemClickListner in android recyclerviewStep 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 recyclerview.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.annotation.TargetApi; import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.widget.TextView; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { ... Read More

Advertisements