Change Current Country Name in Android

Anvi Jain
Updated on 30-Jul-2019 22:30:25

236 Views

This example demonstrate about How to change current country name 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 have taken a text view to show country name information.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.Manifest; import android.content.pm.PackageManager; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.location.LocationManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; import java.io.IOException; ... Read More

Static Channel Allocation in Computer Networks

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

4K+ Views

When there is more than one user who desires to access a shared network channel, an algorithm is deployed for channel allocation among the competing users. Static channel allocation is a traditional method of channel allocation in which a fixed portion of the frequency channel is allotted to each user, who may be base stations, access points or terminal equipment. This scheme is also referred to as fixed channel allocation or fixed channel assignment.Working PrincipleSuppose that there are N competing users. Here, the total bandwidth is divided into N discrete channels using frequency division multiplexing (FDM). In most cases, the ... Read More

Get Month Using MonthDay.getMonth Method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

223 Views

The month name for a particular MonthDay can be obtained using the getMonth() method in the MonthDay class in Java. This method requires no parameters and it returns the month name in the year.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       MonthDay md = MonthDay.parse("--02-22");       System.out.println("The MonthDay is: " + md);       System.out.println("The month is: " + md.getMonth());    } }OutputThe MonthDay is: --02-22 The month is: FEBRUARYNow let us understand the above program.First the MonthDay is displayed. ... Read More

LocalTime withHour Method in Java

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

55 Views

An immutable copy of a LocalTime with the hour altered as required is done using the method withHour() in the LocalTime class in Java. This method requires a single parameter i.e. the hour that is to be set in the LocalTime and it returns the LocalTime with the hour altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalTime lt1 = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt1);       LocalTime lt2 = lt1.withHour(5);       ... Read More

Query Records Where Field is Null or Not Set in MongoDB

Smita Kapse
Updated on 30-Jul-2019 22:30:25

766 Views

Let us work around two cases −Case 1 − The syntax is as follows when the field is present and set to null.db.yourCollectionName.count({yourFieldName: null});Case 1 − The syntax is as follows when the field is not present and not set.db.yourCollectionName.count({yourFieldName: {$exists: false}});To understand both the above syntaxes, let us create a collection with the document. The query to create a collection with a document is as follows −> db.fieldIsNullOrNotSetDemo.insertOne({"EmployeeName":"Larry", "EmployeeAge":null, "EmployeeSalary":18500}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a995c6cea1f28b7aa07fe") } > db.fieldIsNullOrNotSetDemo.insertOne({"EmployeeName":"Bob", "EmployeeAge":21, "EmployeeSalary":23500}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a99836cea1f28b7aa07ff") } > db.fieldIsNullOrNotSetDemo.insertOne({"EmployeeName":"Carol", "EmployeeSalary":45500}); { ... Read More

Select Timestamp as Date String in MySQL

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

299 Views

To select timestamp as date string in MySQL, the syntax is as follows −select FROM_UNIXTIME(yourColumnName, '%Y-%m-%d %H:%i:%s') from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table select_timestampDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ArrivalDateTime int    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into select_timestampDemo(ArrivalDateTime) values(1546499730); Query OK, 1 row affected (0.18 sec) mysql> insert into select_timestampDemo(ArrivalDateTime) values(1546210820); Query OK, 1 ... Read More

Use getFirst in Android LinkedBlockingDeque

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

141 Views

Before getting into an example, we should know what LinkedBlockingDeque is. It is implemented by Collection interface and the AbstractQueue class. It provides optional boundaries based on linked nodes. It going to pass memory size to a constructor and helps to provide memory wastage in android.This example demonstrates about How to use getFirst () in android LinkedBlockingDequeStep 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 have taken ... Read More

Passing Data Between Activities in Android

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

791 Views

For this lesson we are only concerned with passing data between activities without making them persistent so we’ll look at the two simplest ways to achieve that which are by using Static methods and IntentsUsing Static methodsThis example demonstrate about Passing data between activities in Android using Static methods.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.myapplication; import android.content.Intent; import android.os.Bundle; import ... Read More

Remove Duplicate Elements in Java with HashSet

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

13K+ Views

Set implementations in Java has only unique elements. Therefore, it can be used to remove duplicate elements.Let us declare a list and add elements −List < Integer > list1 = new ArrayList < Integer > (); list1.add(100); list1.add(200); list1.add(300); list1.add(400); list1.add(400); list1.add(500); list1.add(600); list1.add(600); list1.add(700); list1.add(400); list1.add(500);Now, use the HashSet implementation and convert the list to HashSet to remove duplicates −HashSetset = new HashSet(list1); Listlist2 = new ArrayList(set);Above, the list2 will now have only unique elements.Example Live Demoimport java.util.ArrayList; import java.util.HashSet; import java.util.List; public class Demo {    public static void main(String[] argv) {       Listlist1 = new ArrayList(); ... Read More

Display BIT(1) Fields in MySQL

George John
Updated on 30-Jul-2019 22:30:25

777 Views

Let us first create a table. Here, our columns is of type bit(1) −mysql> create table DemoTable (    isCaptured bit(1) ); Query OK, 0 rows affected (1.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.29 sec)Following is the query to display all records from the table using select statement −mysql> select ... Read More

Advertisements