Skip to main content

Posts

Simplify Your Tax Calculations with GST Calculator 2024: The Ultimate Tool for Businesses and Individuals

Swap two numbers in java | Using third variable | without third variable | XOR Bitwise opearation | Java tutorial for beginners .

When we learning any programming languages like C, C++, Python, PHP etc, then the " Number Swap Programming " comes first for learning.  In this article I write the number swapping between two numbers in JAVA with 3 different algorithms .  1. Creating an auxiliary memory cell in the memory ; i.e use a temporary or 3rd variable. 2. Without creating any auxiliary(additional) memory cell ; i.e without use of any 3rd variable. 3. Using exclusive OR (Bit-wise XOR) operator. Problem Statement: Write a program in java to swap two numbers. Approach- 1 :  Creating an auxiliary memory cell in the memory ; i.e use a temporary or 3rd variable. In this approach we take a extra variable that temporarily holds the value of one variable. public class Test { public static void main (String[] args) { swapUsingTempVar( 5 , 6 ); } static void swapUsingTempVar ( int a, int b) { int temp; System. out . p...

Understand the concept of Java Classes and Objects with an example | Class | Object | Java

 In this article, We try to understand the concept of Java Classes and Objects with an example. The key content of this article are- (i) What is class and Object (ii) Example of class and object (iii) Difference between Class and Object (i.a) Class In Java: A class is an entity that determines how an object will behave and what the object will contain. In other words, it is a blueprint or a set of instruction to build a specific type of object. It provides initial values for member variables and member functions or methods. (i.b) Object In Java: An object is nothing but a self-contained component that consists of methods and properties to make a data useful. It helps you to determines the behaviour of the class. i.e we say that " A class is a template for an object, and an object is an instance of a class ". That's why class is called as logical entity , where object is physical entity .  So simply, a class does not allocate memory space when it is created, on other han...

SearchView in Android with RecyclerView | Toolbar | Kotlin

 The search functionality in android App is a very important feature of any list page. In this article I make a simple android application to describe the SearchView integration in Android with RecyclerView | Toolbar | Kotlin. Follow the steps- Step 1 :  First create a blank project in android studio with simple empty activity. Step 2 :  Use the below code in colors.xml file <?xml version="1.0" encoding="utf-8"?> <resources> <color name= "purple_200" > #FFBB86FC </color> <color name= "purple_500" > #FF6200EE </color> <color name= "purple_700" > #FF3700B3 </color> <color name= "teal_200" > #FF03DAC5 </color> <color name= "teal_700" > #FF018786 </color> <color name= "black" > #FF000000 </color> <color name= "white" > #FFFFFFFF </color> </resources> Step ...

Recycler View Like Google Play Store App | How to use SnapHelper Android, Kotlin

 If we see the google play store android app, we can see that the app list in horizontal recycler view hold a property that the first property hold always full visible or not visible, but a portion visible is not seeing. This property is snap property. In this article I show you how to use it in our own application. Basically we use two type of snap. Center Snap and start snap. I show you both here. So read full article here. The Key Moment code is here- For center snap you need to write 2 lines code- //center Snap val snapHelper = LinearSnapHelper() snapHelper.attachToRecyclerView(recyclerView1) For start snap, create a class in kotlin say StartSnapHelper.kt package com.example.snaphelpersampleapp import android.view.View import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearSnapHelper import androidx.recyclerview.widget.OrientationHelper import androidx.recyclerview.widget.RecyclerView class StartSnapH...

Popular posts from this blog

How to fetch Latitude, Longitude from address and vice-versa(address from Latitude, Longitude) using Google Geo coder SDK in android| Kotlin

 In this Android development related article, you will get a simple solution that, how to get address using Latitude, Longitude and vice-versa. i.e latitude, longitude from an address text. It is very easy and simple. Read full article and carefully follow all the steps. Here we use google Geocoder SDK. Okay, first we create an android project in kotlin and create an Activity say MainActivity.kt. Use the below code- Function get Latitude, Longitude from Address- fun getLatLngFromAddress (context: Context, mAddress: String): String { val coder = Geocoder(context) lateinit var address: List<Address> try { address = coder.getFromLocationName(mAddress, 5 ) if (address == null ) { return "Fail to find Lat,Lng" } val location = address[ 0 ] return " Latitude: ${location.latitude}\n Longitude: ${location.longitude}" } catch (e: Exception...

How to Insert Multiple rows in a single db transaction in Android Room Database? | Android | Room DB

  To insert multiple rows into a Room database in Android, you can follow these steps: 1. Set up Room Database: First, make sure you have set up your Room database correctly in your Android project. Define your Entity class, create a Database class that extends RoomDatabase, and set up your DAO (Data Access Object) interface. 2. Create Entity Class: Define an Entity class that represents the data you want to insert into the database. For example: 1 2 3 4 5 6 7 8 9 @Entity (tableName = "my_table" ) public class MyEntity { @PrimaryKey (autoGenerate = true ) public int id; public String name; public int age; // Add other fields and getters/setters as needed } Create DAO: Create a DAO interface with a method to insert multiple rows. For example: 1 2 3 4 5 @Dao public interface MyEntityDao { @Insert void insertAll (List<MyEntity> entities); } Initialise Database and DAO: In your application code, create an insta...

onBackPressed() method is deprecated, you are looking for an alternative? Here It is the Latest Solution in android | Kotlin

With the evolution of Android development, several APIs and functions get deprecated over time to make way for more robust and flexible alternatives. One such deprecation that developers need to be aware of is the onBackPressed() method in Android. In Android, onBackPressed() was commonly used to handle back button presses within an activity. However, with the introduction of the Jetpack libraries and the emphasis on more structured navigation, this method has been deprecated. This blog will explore why onBackPressed() is deprecated and what the best alternative solutions are in Kotlin for handling back navigation. Why onBackPressed() is Deprecated The primary reasons for deprecating onBackPressed() include: Improved Navigation Architecture: Android Jetpack's Navigation Component provides a more consistent and predictable way to handle navigation, including back navigation. Lifecycle Awareness: Handling back...