Skip to main content

Posts

Showing posts with the label Java

GenAI App using Spring Boot and Amazon Bedrock - Part 2

This is part of a series of articles to introduce Generative AI and step-by-step process with code sample to build GenAI Application; Part-1 ( GenAI Introduction ), Part-2 ( Building GenAI App using Spring Boot and Amazon Bedrock ) and Part-3 ( Building GenAI App with Proprietary data ). Previous article ( Introduction to GenAI ) explains important concepts of GenAI, Model Architecture and Vector Database. In this article, we are going to develop a simple GenAI based ChatBot using Spring Boot and Amazon Bedrock. Here we'll explore AWS SDK and REST API based Integration rather than Spring AI framework. Also, going to share troubleshooting scenarios which you may face while building this application. Prerequisites Spring Boot v3, JDK 17 AWS SDK v2.x AWS IAM account access and API credentials. Make sure that "AmazonBedRockFullAccess" permission is granted. Amazon Bedrock FM ( Anthropic Claude 3 Haiku ). This Model helps with Image to Text, Chat, Conversation features. En...

Java Reflection as Android API

Have you ever tried or wished to re-use or access source code which is part of a different Android APK ? If "Yes", then this article is for you. Well, I must agree its not a very common use case and when it comes to API in Android, we rather prefer JAR or Remote Service to expose functionalists. Java Reflection can be an alternate and useful API approach to expose functionalists from an APK or Application. Here I'm going to explain a design approach where we can define API for Android using Java Reflection. For this example, Host.apk is an Application which hosts one API method which we are going to access from another application Client.apk . Host.apk includes- HostApi.java which defines API method getMeta() . This method returns some pre-defined Text appended to calling Application's Package name. package com.pras.host; import android.content.Context; public class HostApi {      Context mContext;      public HostApi(Context context) {  ...

Bulk Email Sender

Few months back I had a requirement to have some kind of Tool which would help me to send emails to list of hundreds of recipients for Online or Email based product promotion. So, developed a small Auto-Mail sender tool which helps to send bulk emails with custom Subject line and HTML enabled message. This helped me a lot to do Email based product promotion. This would help people who are doing Online or Email marketing to promote their product/service. Please download the tool- Auto-Mail and share your experience.

Its about Bytes in Java

I have seen people struggle in handling data in Java when it reaches at the byte level. As Java doesn't support any concept of Un-signed data type, so it makes things more complex. So thought lets share my understanding. Java stores negative values in 2's complement format and to get absolute value of any negative number you need to type cast variable with higher byte value datatype. In simple word, to get absolute value of -ve byte data type variable it need to type cast/upgrade to some other date type (e.g. short/int) having more number of bytes and. Example, byte mSample = 142 ; If you print its value, it will show -114 . So, why does the JVM shows -114 ? Binary of 142 : 1 0 0 0 1 1 1 0 . The left most bit is Signed bit, so JVM considers this number as -ve value and converts it into 2's Complement, which means, 0 1 1 1 0 0 1 0 = - 114. So, its simple, right ? So, to get absolute value of mSample , we need to type cast it to higher byte enabled data type ...

Excel Column Sequence Algorithm

One of my friend came up with a question..."How do you find out the sequence of MS Excel column ?", lets put this in an another way, If I tell you one Excel Sheet column sequence e.g. ABA how do you find out the index of the column e.g. AA is 27th column, AB is 28th column. So, I thought to put this as an Algo; with this if you have any sequence, you will be able to compute the column number- Column Number = Alphabet Seq Number (right most) + Alphabet Seq Number * 26 + Alphabet Seq Number * (26*26) + .......... + Alphabet Seq Number (left most) * (p-1 times multiplication of 26) Where, Alphabet Seq Number = 1-26, (A = 1 and Z = 26) p = number of Alphabets in the Column Sequence e.g. for "ABC", p = 3. Here  is C at position 1, B at 2 and A at 3. So, with the above formula, Column number for ABC = C + B * 26 + A * (26 * 26)   = 3 + 2 * 26 + 1* (26*26) = 731 So, what about doing the reverse i.e. generate the sequence from column number. To...

Multi-Threaded Execution Control

In this tutorial I'll explain mechanism to control multiple thread execution sequence. To explain the concept, I'll consider a sample execution scenario where a set of operations execute in sequence, but each operation runs in different threads. Lets consider content download scenario, Login to the Content Server -> Browse Content -> Download Content. 3 Threads will execute each of these operations and these operations are inter dependent and will follow the order, login - browse - download . Let's jump into the implementation, we'll have Synchronized blocks for 3 different functions and we'll do thread execution control using wait()/notifyAll() methods. To determine the order of execution we'll use one variable state which can hold 3 different values- Login , Browse and Download . Synchronization blocks will be locked with a Private Object lock. This is more effective and fail pro...