The LocalDate can be formatted with the specified formatter using the format() method in the LocalDate class in Java. This method requires a single parameter i.e. the LocalDate object to be formatted and it returns the formatted LocalDate with the specified formatter.A program that demonstrates this is given as follows −Example Live Demoimport java.util.*; import java.time.*; import java.time.format.DateTimeFormatter; public class Main { public static void main(String[] args) { LocalDate ld = LocalDate.parse("2019-02-14"); System.out.println("The LocalDate is: " + ld); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/YYYY"); System.out.println("The formatted LocalDate is: " + ... Read More
The accept() method of the LongStream.Builder class adds an element to the stream being built.The syntax is as followsvoid accept(long i)Here, i is the input.To use the LongStream.Builder class in Java, import the following packageimport java.util.stream.LongStream;Create a LongStreamLongStream.Builder builder = LongStream.builder();Add some elementsbuilder.accept(200L); builder.accept(600L); builder.accept(400L);The following is an example to implement LongStream.Builder accept() method in JavaExample Live Demoimport java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream.Builder builder = LongStream.builder(); builder.accept(200L); builder.accept(600L); builder.accept(400L); builder.accept(350L); builder.accept(900L); builder.accept(850L); ... Read More
The following is the code to create a database in MySQL from Java. We are creating the database with name, “Customer_Tracker_Database”import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class CreateDatabaseDemo { public static void main(String[] args) { Connection con=null; Statement stmt=null; String yourDatabaseName="Customer_Tracker_Database"; try { con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test3?useSSL=false", "root", "123456"); stmt = con.createStatement(); int status = stmt.executeUpdate("CREATE DATABASE "+yourDatabaseName); if(status > 0) { System.out.println("Database ... Read More
In this section we will see how to execute the if and else section simultaneously in a C or C++ code. This solution is little bit tricky.When the if and else are executed one after another then it is like executing statements where if-else are not present. But here we will see if they are present how to execute them one after another.Example Code#include using namespace std; int main() { int x = 10; if(x > 5) { lebel_1: cout
Before getting into 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 demonstrate about How to use remove() 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 text view to show CopyOnWriteArrayList elements.Step 3 − Add the following code to src/MainActivity.javapackage ... Read More
Internet Protocol is currently in the process of moving from version 4 to version 6. This is necessitated because version 4 doesn’t provide enough addresses to handle the increasing number of devices with direct connections to the internet.An IPv4 address is composed of 32 bits, represented into four eight bit groups called as "octets". This is a "dotted decimal" format where each eight-bit octet can have a decimal value 0 to 255.For example: 192.168.1.1IPv4 address with CIDR notation: 192.168.1.1/24 where 24 means first three octets identify the network and last octet identifies node.An IPv6 address is 128 bits long. It ... Read More
Create a Random class object −Random random = new Random();Now let us create a random BigInteger within the range set below −BigInteger i = new BigInteger(1024, random);Example Live Demoimport java.math.BigInteger; import java.util.Random; public class Demo { public static void main(String[] args) { Random random = new Random(); BigInteger i = new BigInteger(1024, random); System.out.println("Random BigInteger = "+i); } }OutputRandom BigInteger = 172988250696765715389833755481951104504569480256142363412177847577736195982554760981595486734850686498607899498518922990162874103419942352546847073039976287403845518172884710426458735414702299598858093908453406020426533304237452347610248118892069951238970445771615614781904759399589093691142208659284351662649
In C or C++, there are four different datatypes, that are used for integer type data. These four datatypes are short, int, long and long long. Each of these datatypes takes different memory spaces. The size varies in different architecture and different operating systems. Sometimes int takes 4-bytes or sometimes it takes 2-bytes. This also happen for the compilers. So we can use cross compilers.The cross compilers are basically a compiler, which is capable of compiling for a platform other than current platform.So if we want to compile the following code in 32bit system, and 64-bit system, it will generate ... Read More
A double array can be wrapped into a buffer using the method wrap() in the class java.nio.DoubleBuffer. This method requires a single parameter i.e. the array to be wrapped into a buffer and it returns the new buffer created. If the returned buffer is modified, then the contents of the array are also similarly modified and vice versa.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) { try { double[] arr = { 8.7D, 1.5D, 3.2D, 7.4D, 5.9D ... Read More
The last three clock cycles in ‘MOV C, M’ instruction are the example for Memory Read machine cycle. Waveforms for Machine Read machine cycle is shown below: InstructionOperationAddress reg.LDA 1234HLoading W with 12H (or Z with 34H)PCPOP BPopping information from stack topSPMOV C, MLoading A from memory pointed by HLHLLDAX BLoading A from memory pointed by BCBCLDAX DLoading A from memory pointed by DEDELDA 1234HLoading A from memory Location 1234HWZ The data, which is received in a register during a Memory Read machine cycle depends on the MR machine cycle within an instruction as shown below. Where ‘r’ stands for any of ... Read More