In this section we will see how to use the fork() to make child process in C. We also do some different tasks in each process. So in our parent process we will print different values.When fork() is called, it returns a value. If the value is greater than 0, then currently it is in parent process, otherwise it is in child process. So using this we can distinguish between the processes.Example Code#include #include int main() { int n = fork(); //subdivide process if (n > 0) { //when n is not 0, then it is ... Read More
This example demonstrate about Fragment Tutorial with Example in Android StudioStep 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 button views and linear layout to show different fragments.Step 3 − Add the following code to src /MainActivity.javapackage com.example.myapplication; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.view.View; public class MainActivity extends AppCompatActivity { ... Read More
To extract the subarray value in MongoDB, you can use $elemMatch projection operator.Let us first create a collection with documents −> db.extractSubArrayDemo.insertOne( ... { ... _id: 101, ... "clientName":"Larry", ... "ClientDetails": ... [ ... { ... "ClientProjectName":"Online Game", ... "DeveloperTeamSize": 10 ... }, ... { ... "ClientProjectName":"Pig Dice Game", ... "DeveloperTeamSize": ... Read More
The value of a duration in the form of a number of hours can be obtained using the method toHours() in the Duration class in Java. This method does not require any parameters and it returns the duration in the form of a number of hours.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class GFG { public static void main(String[] args) { Duration d = Duration.ofDays(1); System.out.println("The duration is: " + d); System.out.println("Number of ... Read More
Like Arrays, we can also iterate through Septet class in JavaTuples using loops.Let us first see what we need to work with JavaTuples. To work with Septet class in JavaTuples, you need to import the following package −import org.javatuples.Septet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Septet Class in JavaTuples, 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.Septet; public class Demo { public static void main(String[] args) { ... Read More
To calculate the total time duration in MySQL, you need to use SEC_TO_TIME(). Let us see an example by creating a tablemysql> create table AddTotalTimeDemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > LoginTime time - > ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into AddTotalTimeDemo(LoginTime) values('05:05:00'); Query OK, 1 row affected (0.10 sec) mysql> insert into AddTotalTimeDemo(LoginTime) values('07:20:00'); Query OK, 1 row affected (0.16 sec) mysql> insert ... Read More
The element forwards the request object containing the client request information from one JSP file to another file. The target file can be an HTML file, another JSP file, or a servlet, as long as it is in the same application context as the forwarding JSP file.sendRedirect sends HTTP temporary redirect response to the browser, and browser creates a new request to go the redirected page.
An immutable copy of a MonthDay with the month altered as required is done using the method withMonth() in the MonthDay class in Java. This method requires a single parameter i.e. the month that is to be set in the MonthDay and it returns the MonthDay with the month altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { MonthDay md1 = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md1); ... Read More
The DoubleStream.iterate() returns an infinite sequential ordered DoubleStream produced by iterative application of a function f to an initial element seed, producing a Stream consisting of seed.The syntax is as followsstatic DoubleStream iterate(double seed, DoubleUnaryOperator f)Here, seed is the initial element and f is a function to be applied to the previous element to produce a new element.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to generate infinite stream of Double in Java with DoubleStream.iterate()Exampleimport java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { ... Read More
The parallel() method of the IntStream class in Java returns an equivalent parallel stream. The method may return itself, either because the stream was already parallel, or because the underlying stream state was modified to be parallel.The syntax is as follows:IntStream parallel()Create an IntStream and you can use the range() method as well to set the range of elements:IntStream intStream = IntStream.range(20, 35);Now, use the parallel() method:intStream.parallel()The following is an example to implement IntStream parallel() method in JavaExample Live Demoimport java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.range(20, 35); ... Read More