Found 34494 Articles for Programming

How to create a notification with NotificationCompat.Builder in Android?

George John
Updated on 26-Jun-2020 05:38:04

3K+ Views

Before getting into NotificationCompact.Builder, we should know what is a notification in android. Notification is just like as a message showing system on the action bar. just like missed call notification as shown belowThis example demonstrates how to integrate Android Notification.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.     Step 3 − Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.annotation.SuppressLint; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import ... Read More

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

karthikeya Boyini
Updated on 26-Jun-2020 05:42:05

6K+ 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.Example Live Demopublic class Example {    public static void ... Read More

Define integer literals as octal values in Java

Samual Sam
Updated on 30-Jul-2019 22:30:23

3K+ Views

Literals with a leading zero are octal literals. Any number prefixed with a 0 is considered octal. Octal numbers can only use digits 0-7, just like decimal can use 0-9, and binary can use 0-1. To define integer literals as octal value in Java is effortless. Here is the declaration and initialization. int myOct = 023; Example Live Demo public class Demo { public static void main(String []args) { int myOct = 023; System.out.println(myOct); } } Output 19 Let us see another example. Example Live Demo public class Demo { public static void main(String []args) { int myOct = 010; System.out.println(myOct); } } Output 8

How do I display an alert dialog on Android?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

3K+ Views

Before getting into alert dialog, we should know about what is alert dialog, Alert dialog is just like a pop-up where user can choose action by clicking "ok" or "cancel" button.Methods in Alert DialogsetView(View view) − It used to set custom view to alert dialogsetTitle(CharSequence title) − It is used to set title to alert dialogsetMessage(CharSequence message) − It is simple call as content in alert boxsetIcon(int resId) − it is used to set icon for alert boxsetButton(int whichButton,  CharSequence text,  Message msg) − It is used to set button for alert dialog as shown below example.getListView() − it is used to ... Read More

Hexadecimal literal of type long in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

887 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 Live Demo 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

Handler in android ?

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

12K+ Views

We cant touch background thread to main thread directly so handler is going to collect all events which are available in main thread in a queue and posses this queue to looper class.In android Handler is mainly used to update the main thread from background thread or other than main thread. There are two methods are in handler.Post() − it going to post message from background thread to main thread using looper.sendmessage() − if you want to organize what you have sent to ui (message from background thread) or ui functions. you should use sendMessage().This example demonstrate about how to ... Read More

Hexadecimal integer literal in Java

Samual Sam
Updated on 30-Jul-2019 22:30:23

5K+ Views

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 Here are some of the examples of hexadecimal integer literal declared and initialized as int. int one = 0X123; int two = 0xABC; Example Live Demo public class Demo { public static void main(String []args) { int one = 0X123; int two = 0xABC; System.out.println("Hexadecimal: "+one); System.out.println("Hexadecimal: "+two); } } Output Hexadecimal: 291 Hexadecimal: 2748

What is search view in android?

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

172 Views

Before getting into searchview example, we should know what is search view in android, search view is just like search box in HTML. we can search anything from particular list items.This example demonstrate about how to integrate search view 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 are giving search view and listview because search view going to search element from ... Read More

Different ways to format long with Java System.out.format

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

355 Views

The System.out.format is used in Java to format output. Here, let’s say the following is our long. long val = 787890; To format, we have considered the following that justifies the output. System.out.format("%d%n", val); System.out.format("%9d%n", val); System.out.format("%+9d%n", val); System.out.format("%08d%n", val); System.out.format("%, 9d%n", val); The following is the complete example that displays the difference in output as well. Example Live Demo import java.util.Locale; public class Demo { public static void main(String []args) { long val = 787890; System.out.format("%d%n", val); ... Read More

Compare Two Java long Arrays

Samual Sam
Updated on 30-Jul-2019 22:30:23

417 Views

To compare two Java long arrays in Java, use Arrays.equals() method. Let’s say we have the following long arrays. long[] arr1 = new long[] { 767, 568, 555, 897, 678 }; long[] arr2 = new long[] { 456, 756, 555, 999, 678}; long[] arr3 = new long[] { 767, 568, 555, 897, 678 }; Now, we can compare the equality of these arrays using the equals() method. Arrays.equals(arr1, arr2); Arrays.equals(arr2, arr3); Arrays.equals(arr1, arr3); The following is the complete example. Example Live Demo import java.util.*; public class Demo { public ... Read More

Advertisements