Posts

Proguard

What is ProGuard? ProGuard is a free java tool in Android, which helps us to do the following, Shrink(Minify) the code: Remove unused code in the project. Obfuscate the code: Rename the names of class, fields, etc. Optimize the code: Do things like inlining the functions. In short, ProGuard makes the following impact on our project, It reduces the size of the application. It removes the unused classes and methods that contribute to the 64K method counts limit of an Android application. It makes the application difficult to reverse engineer by obfuscating the code. How it is useful for our application? In Android, proguard is very useful for making a production-ready application. It helps us to reduce the code and make apps faster. Proguard comes out of the box by default in Android Studio and it helps in a lot of ways, few of them are mentioned below, It obfuscates the code, which means that it changes the names to some smaller names like for  MainViewModel  it might change th...

Data Binding

The Data Binding Library is a support library that allows us to bind UI components in our layouts to data sources in our app using a declarative format Benefits : Improves the performance of the app Eliminates the use of findViewById() which makes the code concise, easier to read and maintain. Recognizes errors during compile time In build.gradle, under the android tab, add buildFeatures { dataBinding true } plugins {     id 'kotlin-kapt' } annotationProcessor 'androidx.databinding:databinding-compiler:3.2.0-alpha16' In an Activity : class MainActivity : AppCompatActivity() { private lateinit var binding : ActivityMainBinding override fun onCreate (savedInstanceState: Bundle?) { super .onCreate(savedInstanceState) binding = DataBindingUtil.setContentView( this, R.layout. activity_main ) binding . btnRoll .setOnClickListener { rollDice() } } private fun rollDice () { val data = when (( 1 .. 6 ). rand...

Palindrome Number

import   java.util.Scanner ; /**  *  Java program to check if the number is palindrome or not .  * A number is called palindrome if the number and its reverse is equal  * This Java program can also be used to reverse a number in Java  */ public   class  NoClassDefFoundErrorDueToStaticInitFailure  {      public   static   void  main ( String  args []){                  System . out . println ( "Please Enter a number : " ) ;          int  palindrome =  new   Scanner ( System . in ) . nextInt () ;                 if ( isPalindrome ( palindrome )){              System . out . println ( "Number : "  + palindrome +  " is a palindrome" ) ;          } else {              System . out ....

Program to find sum of prime numbers between 1 to n

// Java program to find sum of primes in range from 1 to n. import java.io.*; import java.util.*;     class GFG {              // Returns sum of primes      // in range from      // 1 to n.      static int sumOfPrimes( int n)      {          // Array to store prime numbers          boolean prime[]= new boolean [n + 1 ];                   // Create a boolean array "prime[0..n]"          // and initialize all entries it as true.          // A value in prime[i] will finally be          // false if i is Not a prime, else true.          ...