Posts

Java 23 Is Here, but Stream API’s filter Still Lags Behind: A Fresh Take

Java 23: Stream.filter Misses Performance Optimization With the release of Java 23 , developers are excited about the new features and enhancements that push the language forward. However, despite all the innovations, one key area that remains largely unchanged is the Stream.filter method in the Stream API . The filter operation is a critical tool for functional programming in Java, but it hasn’t seen the performance optimizations it desperately needs, especially when working with large datasets and parallel processing. In this blog, I will explore the existing filter implementation, why it still lags behind in performance, and what improvements could have been made in Java 23 to boost efficiency, reduce memory consumption, and scale better in modern, high-performance applications. The Current filter Implementation in Java 23 Java’s Stream API offers a declarative way to process collections, and the filter method plays a pivotal r...

Best programming practice

Today, I was going through the code of someone and found it difficult for myself to read it. And the reason behind that was too many If's and too many switch cases. Each method was written with more then 30 line of code. I wasn't sure that why he has choose Object Oriented Programming when he had to do that. Every developer who is willing to improve his programming skills he must need to keep one rule in his mind before writing code: Someone will read your code someday I think few just leave their code without method level or class level comments; so that no one get to know that who wrote that code. But, those stupids forget that subversion do this too. Anyway few of the things I think should be simple in code: Class level comments Method level comments Method should be well-commented Atomic NO to Conditional Programming I am not going to debate on comments because you can get this information from a lot of blogs. So, I will start this blog from the 4th Poi...

MySQL- Hierarchical Data

Image
No developer ever came into the problem of storing hierarchical data. And we always come up with a solution that store the parentId into the same table. And when we just need to retrieve the data then it becomes a nightmare to optimize the nested-join. The advantage to these systems is that they don't take a lot of space, but the disadvantage is that nearly all the maintenance has to be done in the application. So, in essence, these approaches trade lots of queries at retrieval time, for lots of queries at update and insert/delete time, and often some additional programming complexity. Just imagine a tree and what outcome a user may want: root - son - son#2 - grandson#1 - super grandson - son#3 -grandson#2 and I want to display it like: root -> son root -> son#2 root -> son#2 -> grandson#1 root -> son#2 -> grandson#1 -> super grandson root -> son#3 root -> son#3 -> grandson#2 In order to get the following output we apply the ...

Java 8 - Lambda & Functional Interfaces

Java 8 supposted to be a major release after Java 5 and it brought a lot of new changes and ease for java developers i.e. language,compiler,libraries,tools and runtime (JVM) Lambdas and Functional Interfaces Lambdas allow us to treat functionality as a method argument (passing functions around), or treat a code as data. So, this is must be good news for functional developers and from now on no need for anonymous classes in order to do functional programming with java. Examples (-> lambda): Arrays.asList(“a”,”b”,”c”,”d”).forEach( e -> System.out.println( e ) ); Arrays.asList(“a”,”b”,”c”,”d”).forEach( ( String str ) -> System.out.println( str ) ); Arrays.asList(“a”,”b”,”c”,”d”).forEach( ( String str ) -> {     System.out.println( str ) ;     System.out.println( str + ”,”) ; } ); Obviously lambda expression returns a value to but, it must not need to be declared, if not required. Arrays.asList(“a”,”b”,”c”,”d”).sort( ( ...

How to solve Gradle project sync failed error in Android Studio

Image
Before Android Studio I was using MotoDev an android IDE by Motorola. But, I found Android Studio which was developed on IDEA. Whenever we create a new project using Android Studio it develops on Gradle. A very common problem with Gradle that if we don't have internet then it fails building your project and gives an exception:   Gradle project sync failed error This error caused because it always try to find libraries over Internet and when it fails to find the dependencies then it fails. So, in order to execute you project offline you must need to fix this project setup. Click on Invalidate Caches/Restart from the File Menu Click on Invalidate and Restart Let it download all the Gradle stuff it needs once, Gradle build success ! Rebuild project. After successful build of the project you may able to build your project offline.

Read Multiple Rows from Android SQLite Helper

This blog is in continuity with my previous three posts which were related to creation of a database helper class , insertion of new data entry intothe table and selection of a record from the database . After creating database in android and open the connection we had to add entries into the database. And after that we have seen how to select a single record from the database. But now it's time to move to more advance level of retrieving records from the table. And now we must need to select multiple records from the table and populate it to the collection of POJO. ( PreferenceInfo.java ) In order to retrieve a stored record into database we had to provide an identity value which will search the record into table against that id. But, here we are planning to search all the records from the database. A List is a collection which maintains an ordering for its elements. Every element in the List has an index. Each element can thus be accessed by its index, with the...

Read One Record from SQLite Android Helper

This blog is in continuity with my previous two posts which was related to creation of a database helper class and insertion of new data entry into the table . After creating database in android and open the connection we had to add entries into the database. But, as we are already done with the insertion of records into the table. So, now it's time to search for the added record. So, here we will use  PreferenceInfo  POJO for assigning retrieved values to the object. in order to retrieve a stored record into database we must need to provide an identity value which will search the record into table against that id. public PreferenceInfo getUser(int id){ As I have already mentioned in my previous two blogs; we must need to get a readabledatabase object because here we only need to read a database. SQLiteDatabase db=null; // 1. get reference to readable DB try{ db = this.getReadableDatabase(); }catch (Exception e){ Toast.makeText(currentContext, "database...