Java Program to adjust LocalDate to next Tuesday with TemporalAdjusters class

Nancy Den
Updated on 30-Jul-2019 22:30:25
At first, set a LocalDate:LocalDate localDate = LocalDate.of(2019, Month.FEBRUARY, 2);Now, adjust the LocalDate to next Tuesday using next() method:LocalDate date = localDate.with(TemporalAdjusters.next(DayOfWeek.TUESDAY));Exampleimport java.time.DayOfWeek; import java.time.LocalDate; import java.time.Month; import java.time.temporal.TemporalAdjusters; public class Demo {    public static void main(String[] args) {       LocalDate localDate = LocalDate.of(2019, Month.FEBRUARY, 2);       System.out.println("Current Date = "+localDate);       System.out.println("Current Month = "+localDate.getMonth());       LocalDate date = localDate.with(TemporalAdjusters.firstDayOfMonth());       System.out.println("First day of month = "+date);       date = localDate.with(TemporalAdjusters.next(DayOfWeek.TUESDAY));       System.out.println("Next Tuesday date = "+date);    } }OutputCurrent Date = 2019-02-02 Current ... Read More

How to count horizontal values on a MySQL database?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25
You can use aggregate function COUNT() from MySQL to count horizontal values on a database. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstValue int,    SecondValue int,    ThirdValue int,    FourthValue int ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstValue, SecondValue, ThirdValue, FourthValue) values(-18, 45, 0, 155); Query OK,  1 row affected (0.22 sec) mysql> insert into DemoTable(FirstValue, SecondValue, ThirdValue, FourthValue) values(0, 235, null, 15); Query OK,  1 row affected (0.20 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following ... Read More

FloatBuffer get() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
The value at the current position of the buffer is read and then incremented using the method get() in the class java.nio.FloatBuffer. This method returns the value that is at the current buffer position. Also, the BufferUnderflowException is thrown if underflow situation occurs.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 {          FloatBuffer buffer = FloatBuffer.allocate(n);          buffer.put(4.5F);          buffer.put(1.2F);       ... Read More

Essential Python Tips And Tricks For Programmers?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25
In this article, we are going to cover some useful python tricks and tips that will come handy when you are writing program in competitive programming or for your company as they reduce the code and optimized execution.In-Place Swapping of two Numbersx, y = 50, 70 print(x, y) #swapping x, y = y, x print(x, y)Output50 70 70 50Creating a single string from a listlst = ['What', 'a', 'fine', 'morning'] print(" ".join(lst))OutputWhat a fine morningRemove duplicates from a list# Remove duplicates from a list #This method will not preserve the order lst = [2, 4, 4 ,9 , ... Read More

How to make a txt file in internal storage in android?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25
This example demonstrates How to make a txt file in internal storage 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 editext and button. When the user clicks on the button, it will take data from edit text and store in internal storage as /data/data//files/text/sample.txt.Step 3 − Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; ... Read More

How to insert own values into auto_increment column in MySQL?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
You can achieve this with the help of INSERT statement i.e, you can simply insert it like a normal insert. The syntax is as follows −INSERT INTO yourTableName (yourIdColumnName, yourColumnName) values(value1, 'value2'); Let us first create a table: mysql> create table InsertValueInAutoIncrement -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20) -> ); Query OK, 0 rows affected (0.59 sec)Now you can insert some records in the table using insert command. Here, we are also inserting our own values for the auto_increment field UserId. ... Read More

What are filters in JSP?

George John
Updated on 30-Jul-2019 22:30:25
Servlet and JSP Filters are Java classes that can be used in Servlet and JSP Programming for the following purposes To intercept requests from a client before they access a resource at the back end.To manipulate responses from the server before they are sent back to the client.There are various types of filters suggested by the specifications −Authentication FiltersData compression FiltersEncryption FiltersFilters that trigger resource access eventsImage Conversion FiltersLogging and Auditing FiltersMIME-TYPE Chain FiltersTokenizing FiltersXSL/T Filters That Transform XML ContentFilters are deployed in the deployment descriptor file web.xml and then map to either servlet or JSP names or URL patterns in ... Read More

How to get current state of activity in android?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25
This example demonstrates How to get current state of activity 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 text view to show activity state.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity { ... Read More

IntStream flatMap() method in Java

George John
Updated on 30-Jul-2019 22:30:25
The flatMap() method of the IntStream class returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.The syntax is as followsIntStream flatMap(IntFunction

Duration plusHours() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
An immutable copy of a duration where some hours are added to it can be obtained using the plusHours() method in the Duration class in Java. This method requires a single parameter i.e. the number of hours to be added and it returns the duration with the added hours.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofHours(1);       System.out.println("The duration is: " + d);       System.out.println("A copy with 2 hours added to the duration is: ... Read More
Advertisements