
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 9150 Articles for Object Oriented Programming

2K+ Views
A time zone is a region of the globe that observes a uniform standard time for legal, commercial, and social purposes. Suppose you have an application that is running in India as well as Japan. Here, you can't use the same time zone for both regions. Therefore, it is necessary to display time in different time zones. Java provides various built-in classes like TimeZone and ZoneId and methods like getTimeZone() that can help in displaying the current time in another time zone. However, before using them, you must import them into your Java program. Using getTimeZone() and setTimeZone() Methods ... Read More

2K+ Views
In Java, we can create a date object using the calendar class, which gives us more control on date and time. We will discuss the process in this article. What is the Calendar class? In order to understand the usage of we must know what is the calendar class. The Calendar class allows us to work with date and time more easily than Date class. like, we can set specific parts of the date, like month, year, and day. For using Calendar class, import the following package. import java.util.Calendar; Now, let us create an object of Calendar class. Calendar ... Read More

480 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

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

647 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

677 Views
In this article, we will learn to convert a java.util.Date object to a java.sql.Date object in Java. This is a common requirement when working with databases, as many database systems use the java.sql.Date class to represent date values. While java.util.Date is used for general date and time representation in Java, java.sql.Date is specifically designed to handle SQL-compatible date formats. java.util.Date The Date class in the java.util package representing a specific moment in time, measured in milliseconds since January 1, 1970, UTC (the "epoch"). It's a general-purpose date and time representation. java.sql.Date A subclass of ... Read More

6K+ 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

1K+ 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

628 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

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