Karthikeya Boyini has Published 2383 Articles

Display path separator in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

152 Views

To display the path separator, use the Properties class and import the following package −import java.util.Properties;Use the getProperties() method first and create an object −Properties p = System.getProperties();Now, set the key for path separator −p.getProperty("path.separator")The following is an example −Example Live Demoimport java.util.Properties; public class Demo { public ... Read More

Set width and precision to format output in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

1K+ Views

Set width in output as shown below. Here, %10 sets a 10 character fieldSystem.out.printf("d1 = %10.2f d2 = %8g", d1, d2);Above, the value after the decimal is for decimal places i.e. 5.3 is for 3 decimal places −System.out.printf("d1 = %5.3f d2 = %2.5f", d1, d2);The following is an example −Example Live ... Read More

MySQL update query to remove spaces?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

1K+ Views

You can use TRIM() function to remove spaces. The syntax is as follows −UPDATE yourTableName SET yourColumnName=TRIM(yourColumnName);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table removeSpaceDemo -> ( -> Id int ... Read More

Get localized short day-in-week name in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

223 Views

Use the ‘a’ date conversion character to display short day-in-week.System.out.printf("Localized short day name = %ta/%Ta", d, d);Above, d is a date object −Date d = new Date();The following is an example −Example Live Demoimport java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; public class Demo { public static void main(String[] args) ... Read More

Java Program to return a Date set to the last possible millisecond of the month before midnight

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

242 Views

Use the getMaximum() method in Java to returns the maximum value for the given calendar field. We will use it to set the minute, second and millisecond.Let us first declare a calendar object −Calendar dateNoon = Calendar.getInstance();Now, we will set the hour, minute, second and millisecond to the last possible ... Read More

try and except in Python

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

765 Views

To use exception handling in python, we first need to catch the all except clauses.Python provides, “try” and “except” keywords to catch exceptions. The “try” block code will be executed statement by statement. However, if an exception occurs, the remaining “try” code will not be executed and the except clause ... Read More

Add results from several COUNT queries in MySQL?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

117 Views

To add results from several COUNT queries, you can use the following syntax −SELECT (SELECT COUNT(*) FROM yourTableName1)+ (SELECT COUNT(*) FROM yourTableName2)+ (SELECT COUNT(*) FROM yourTableName3)+ . . . N AS anyAliasName;Let us use three tables in the test database −userssortingstringdemouserlogintableCheck the table records from the table using a select ... Read More

MySQL command to order timestamp values in ascending order without using TIMESTAMP()?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

133 Views

You can use ORDER BY ASC to order timestamp values in ascending order.The following is the syntax without using TIMESTAMP() −SELECT yourTimestampColumnName from yourTableName order by yourTimestampColumnName ASC;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Timestamp_TableDemo ... Read More

Java Program to return a Date set to the last possible millisecond of the minute

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

53 Views

Let us first set the calendar object −Calendar calendar = Calendar.getInstance();Use the getMaximum() method in Java to returns the maximum value for the given calendar field. We will use it to set the minute, second and milliseconds.For seconds −calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));For milliseconds −calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));The following is an example that returns a ... Read More

Locale-specific formatting in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

98 Views

For locale-specific formatting, firstly import the following packages.import java.util.Calendar; import java.util.Formatter; import java.util.Locale;Create a Formatter and Calendar object −Formatter f = new Formatter(); Calendar c = Calendar.getInstance();We are formatting for different Locales −f.format(Locale.TAIWAN, "Locale.TAIWAN: %tc", c); f.format(Locale.ITALY, "Locale.ITALY: %tc", c);The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; import ... Read More

Advertisements