karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 75 of 143

Hexadecimal literal of type long in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

Hexadecimal literal of type long is represented as − long hexLong = 0XABL; For Hexadecimal, the 0x or 0X is to be placed in the beginning of a number. Note − Digits 10 to 15 are represented by a to f (A to F) in Hexadecimal Example public class Demo { public static void main(String []args) { long hexLong = 0XABL; System.out.println("Hexadecimal literal of type long: "+hexLong); } } Output Hexadecimal literal of type long:171

Read More

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

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 118 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 Date set to the last possible millisecond of the minute −Exampleimport java.util.Calendar; import java.util.GregorianCalendar; public class Demo {    public static void main(String[] argv) throws Exception {       Calendar calendar = Calendar.getInstance();       // seconds       calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));       // milliseconds   ...

Read More

Locale-specific formatting in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 196 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 −Exampleimport java.util.Calendar; import java.util.Formatter; import java.util.Locale; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar c = Calendar.getInstance(); f.format(Locale.TAIWAN, "Locale.TAIWAN: %tc", c); ...

Read More

Java program to display Astrological sign or Zodiac sign for given date of birth

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 7K+ Views

Each date of birth corresponds to a given Zodiac sign. A table that demonstrates these signs and their corresponding dates is given below −Zodiac SignDateAriesMarch 21 - April 19TaurusApril 20 - May 20GeminiMay 21 - June 20CancerJune 21 - July 22LeoJuly 23 - August 22VirgoAugust 23 - September 22LibraSeptember 23 - October 22ScorpioOctober 23 - November 21SagittariusNovember 22 - December 21CapricornDecember 22 - January 19AquariusJanuary 20 - February 18PiscesFebruary 19 - March 20A program that displays the Astrological sign or Zodiac sign for a given date of birth is given as follows.Examplepublic class Example {    public static void main ...

Read More

Java Program to validate if a String contains only numbers

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

To validate if a String has only numbers, you can try the following codes. We have used the matches() method in Java here to check for number in a string.Examplepublic class Demo {    public static void main(String []args) {       String str = "978";       System.out.println("Checking for string that has only numbers...");       System.out.println("String: "+str);       if(str.matches("[0-9]+") && str.length() > 2)       System.out.println("String has only numbers!");       else       System.out.println("String consist of characters as well!");    } }OutputChecking for string that has only numbers... String: ...

Read More

Formatter Specifier for Octal and Hexadecimal in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 236 Views

For Formatter, import the following package −import java.util.Formatter;Now create a Formatter object like this −Formatter f1 = new Formatter(); Formatter f2 = new Formatter(); Formatter f3 = new Formatter();If you want a Format specifier for Octal, use %o −f3.format("Octal values %o %o %o", 15, 55, 78);If you want a Format specifier for Hexadecimal, use %x −f2.format("Hexadecimal values %x %x %x", 24, 98, 110);The following is an example −Exampleimport java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f1 = new Formatter(); Formatter ...

Read More

Store unicode in a char variable in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

To store Unicode in a char variable, simply create a char variable.char c;Now assign unicode.char c = '\u00AB';The following is the complete example that shows what will get displayed: when Unicode is stored in a char variable and displayed.Examplepublic class Demo {    public static void main(String []args) {       int a = 79;       System.out.println(a);       char b = (char) a;       System.out.println(b);       char c = '\u00AB';       System.out.println(c);    } }Output79 O «

Read More

Java program to extract 'k' bits from a given position

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 587 Views

Extraction of k bits from the given position in a number involves converting the number into its binary representation. An example of this is given as follows −Number = 20 Binary representation = 10100 k = 3 Position = 2 The bits extracted are 010 which represent 2.A program that demonstrates this is given as follows.Examplepublic class Example {    public static void main (String[] args) {       int number = 20, k = 3, pos = 2;       int exNum = ((1 > (pos - 1));       System.out.println("Extract " + k + " ...

Read More

Display the Operating System name in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 4K+ Views

Use the System.getProperty() method in Java to get the Operating System name.It’s syntax is −String getProperty(String key)Above, the key is the name of the system property. Since, we want the OS name, therefore we will add the key as −os.nameExamplepublic class Demo {     public static void main(String[] args) {        System.out.print("Operating System: ");        System.out.println(System.getProperty("os.name"));     } }OutputOperating System: Linux

Read More

Convert string to char array in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 4K+ Views

The following is our string.String str = "Tutorial";Now, use the toCharArray() method to convert string to char array.char[] ch = str.toCharArray();Now let us see the complete example.Examplepublic class Demo {    public static void main(String []args) {       String str = "Tutorial";       System.out.println("String: "+str);       char[] ch = str.toCharArray();       System.out.println("Character Array...");       for (int i = 0; i < ch.length; i++) {          System.out.print(ch[i]+" ");       }    } }OutputString: Tutorial Character Array... T u t o r i a l

Read More
Showing 741–750 of 1,421 articles
« Prev 1 73 74 75 76 77 143 Next »
Advertisements