- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4337 Articles for Java 8
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
For using Calendar class, import the following package.import java.util.Calendar;Now, let us create an object of Calendar class.Calendar calendar = Calendar.getInstance();Set the date, month and year.calendar.set(Calendar.YEAR, 2018); calendar.set(Calendar.MONTH, 11); calendar.set(Calendar.DATE, 18);Create a Date object using Calendar class.java.util.Date dt = calendar.getTime();The following is an example.Example Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); // Set year, month and date calendar.set(Calendar.YEAR, 2018); calendar.set(Calendar.MONTH, 11); calendar.set(Calendar.DATE, 18); // util date object java.util.Date dt = ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
381 Views
To get the day of the week, use the Calendar.DAY_OF_WEEK.Firstly, let us get the current date.java.util.Date utilDate = new java.util.Date(); java.sql.Date dt = new java.sql.Date(utilDate.getTime());Now, using GregorianCalendar, set the time.java.util.GregorianCalendar cal = new java.util.GregorianCalendar(); cal.setTime(dt);The last step would display the day of the week as shown in the following example.Example Live Demoimport java.text.ParseException; public class Demo { public static void main(String[] args) throws ParseException { java.util.Date utilDate = new java.util.Date(); java.sql.Date dt = new java.sql.Date(utilDate.getTime()); System.out.println("Today's date: "+dt); java.util.GregorianCalendar cal = new java.util.GregorianCalendar(); cal.setTime(dt); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
4K+ Views
Import the following package to work with Date class.import java.util.Date;No create a Date object.Date d = new Date();Let us convert the current date to milliseconds.d.getTime()The following is an example.Example Live Demoimport java.util.Date; public class Demo { public static void main(String[] args) { Date d = new Date(); System.out.println("Date = " + d); System.out.println("Milliseconds since January 1, 1970, 00:00:00 GMT = " + d.getTime()); } }OutputDate = Mon Nov 19 06:30:11 UTC 2018 Milliseconds since January 1, 1970, 00:00:00 GMT = 1542609011369
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
465 Views
Firstly, create a Calendar class object.Calendar calendar = Calendar.getInstance();Now, import the following package.import java.sql.Date;Using a Date class now and creating an object would belong to the above package. Convert the current time to the java.sql.Date Object.Date sqlDate = new Date((calendar.getTime()).getTime());The following is an example.Example Live Demoimport java.util.Calendar; import java.sql.Date; import java.text.ParseException; public class Demo { public static void main(String[] args) throws ParseException { Calendar calendar = Calendar.getInstance(); // object Date sqlDate = new Date((calendar.getTime()).getTime()); System.out.println(sqlDate); } }Output2018-11-19Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
464 Views
First, let us create a java.util.Date object.// util object java.util.Date utilObj = new java.util.Date();Now, create a java.sql.Date object.java.sql.Date sqlObj = new java.sql.Date();Converting from a java.util.Date object to a java.sql.Date object.java.sql.Date sqlObj = new java.sql.Date(utilObj.getTime());The following is an example.Example Live Demoimport java.util.Date; public class Example { public static void main(String args[]) { // util object java.util.Date utilObj = new java.util.Date(); // sql object java.sql.Date sqlObj = new java.sql.Date(utilObj.getTime()); System.out.println("Util Date = " + utilObj); System.out.println("SQL Date = " + sqlObj); } }OutputUtil ... Read More
![Deepti S](https://www.tutorialspoint.com/assets/profiles/654803/profile/60_3875308-1684130615.jpg)
4K+ Views
Escape sequences are a unique kind of character that are used to indicate a different way of interpreting a group of characters. An escape sequence in Java is a character that is preceded by a backslash (). An escape sequence is treated by the Java compiler as a single character with unique meaning. Java frequently employs the following escape sequences: \t: Adds a new tab : Adds a new line \r: Adds a carriage return ': Adds a single quote ": Adds a double quote \: Adds a backslash These escape sequences can be used to control the ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
839 Views
Let’s say we have the following string.String str = "{Java is a programming language} {James Gosling developed it.}";Above, the string is enclosed with parentheses. We can split a string with these parentheses using the split() method.String[] strSplit = str.split("[{}]");The following is an example.Example Live Demopublic class Demo { public static void main(String[] args) throws Exception { String str = "{Java is a programming language} {James Gosling developed it.}"; String[] strSplit = str.split("[{}]"); System.out.println("Splitting String..."); for (int i = 0; i < strSplit.length; i++) System.out.println(strSplit[i]); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
418 Views
Let’s say the following is our string.String str = "Java is a programming language. James Gosling developed it.";We will now see how to split a string using the split() method. Include the delimiter as the parameter.String[] strSplit = str.split("\.");Above, we have split the string with dot as you can see under the split methods parameter.The following is an example.Example Live Demopublic class Demo { public static void main(String[] args) { String str = "Java is a programming language. James Gosling developed it."; System.out.println("String: "+str); String[] strSplit = str.split("\."); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
5K+ Views
The following are our strings with single and double quote.String str1 = "This is Jack's mobile"; String str2 = "\"This is it\"!";Above, for single quote, we have to mention it normally like.This is Jack's mobileHowever, for double quotes, use the following and add a slash in the beginning as well as at the end.String str2 = "\"This is it\"!";The following is an example.Example Live Demopublic class Demo { public static void main(String[] args) { String str1 = "This is Jack's mobile"; String str2 = "\"This is it\"!"; System.out.println("Displaying Single Quote: "+str1); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
263 Views
The following is our string −String str = "";We will check whether it is empty or not using the isEmpty() method. The result will be a boolean −str.isEmpty()The following is an example −Example Live Demopublic class Demo { public static void main(String[] args) { String str = ""; System.out.println("String is empty: "+str.isEmpty()); } }OutputString is empty: true