Posts

Check If table exist or not

​To check if table exists or not , below is the code snippet-    import java.sql.Connection;    import java.sql.DatabaseMetaData;    import java.sql.ResultSet;     public class Main {        public static void main(String[] argv) throws Exception {          Connection c = null;          DatabaseMetaData dbm = c.getMetaData();          ResultSet rs = dbm.ge​​tTables(null, null, "employee", null);          if (rs.next()) {            System.out.println("Table exists");           } else {            System.out.println("Table does not exist");           }        }     } For Android internal memory, SQLLite -      public boolean doesTableExists(Stri...

Difference between dp, dip, sp, px

Screen density is the amount of pixels within an area (like inch) of the screen. Generally it is measured in dots-per-inch (dpi). Screen density is grouped as low, medium, high and extra high. Resolution is the total number of pixels in the screen. dp: Density Independent Pixel , it varies based on screen density. In 160 dpi screen, 1 dp = 1 pixel. Except for font size, use dp always. dip: dip == dp. In earlier Android versions dip was used and later changed to dp. sp: Scale Independent Pixel , scaled based on user’s font size preference. Fonts should use sp. Always use dp and sp only. sp for font sizes and dp for everything else.

Read/Write Images

To read Image from Gallery- I worked on ImageButton to get Image from gallery: private void uploadImageClicked() {     new Thread(new Runnable() {         Intent intent = new Intent(Intent.ACTION_PICK);         public void run() {             openGallery(intent);         }     }).start(); } private void openGallery(Intent intent) {     intent.setType("image/*");       startActivityForResult(intent, 0); } The above piece of code open the Gallery to select the Image as desired. Here, we create an INTENT in order to access Gallery and hence, set the path as "image/*" and call startActivityForResult(intent, 0) so as to start the activity that utilize intent. To write Image from Gallery-     @Override     public void onActivityResult(int requestCode, int resultCode, Intent data) {       ...

Picasso Vs Glide

Below link gives great explaination between them- https://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en

Multiple Inheritance is not supported in Java

Below diagram explains is called Diamond Problem because of the inheritance structure.       A foo()           / \          /   \ foo() B C foo()          \   /           \ /         D foo() Multiple inheritance does cause casting, constructor chaining,etc problems. Also, multiple inheritance leads to complexity. Hence, Java do not support multiple inheritance. But recently, in JAVA 8, this problem is handled in different way, that is, the compiler will throw exception in this scenario and we will have to provide implementation logic in the class implementing the interfaces.

Java 8 Features

Java 8 has really come out to be powerful where it has improved the performance with boilerplate code with respect to collections, interface. Below are some key points- forEach() method in Iterable interface default and static methods in Interfaces Functional Interfaces and Lambda Expressions Java Stream API for Bulk Data Operations on Collections Java Time API Collection API improvements Concurrency API improvements Java IO improvements Miscellaneous Core API improvements You can have a deeper understanding in below mentioned link- http://www.journaldev.com/2389/java-8-features-with-examples https://leanpub.com/whatsnewinjava8/read  (Along with Github link) https://www.javacodegeeks.com/2014/03/8-new-features-for-java-8.html

Parcelable Object - passing data between intents

It is explained in a simple and elaborated way under below link- https://guides.codepath.com/android/using-parcelable#passing-data-between-intents