Posts Tagged java

Serverless using Java

My colleague were just discussing about the new architecture serverless most of the time and out of curiosity I fiddle around with this term and learned what this really is? Then I found out that it is just a way to execute your normal functions and from URL and you do not need  your server to be online all the time which results in super cost effective unlike normal server where you pay for every month/hour/second of its availability. The term looks super easy to understand. Execute my function foo() when is called via HTTP protocol. The term serverless without any server is just for the developers but beneath this architecture there will still be a fully managed server who handles your request and warms up your code (jar file). So I came to think of demonstrating how to run your minimal functions as serverless . But before that lets learn some basics via image.


Serverless diagram

Java Serverless diagram

Long thing in short : If any POST request in /foo URI happen the Function handler will call to the appropriate function of a class which is predefined in serverless.yml. We developers do not have to worry about all those API endpoints handling because these are handled by serverless itself, this is the beauty of serverless. In an Amazon Web Service world serverless is handled from AWS Lambda service.

Now it is the time to catchup and write our very first and simple serverless project.



Create a new serverless maven  project


Edit some codes inside

You can directly override RequestHandler‘s handleRequest()method/function or you can create just simple method which is also supported for serverless function execution. The only difference is you have to use fully qualified Classname as well as the method name while mapping it to the URI in serverless.yml


Now there is one final piece of puzzle which is serverless.yml which will do the mappings of all functions to uri .

And it is just simple is that. You are ready for deploying your first serverless using simple Java class which will handle your HTTP request directly.  You can deploy your codes directly using your serverless command. But make sure you have proper AWS credentials and policy to deploy your code from commandline.

Once you deploy it the verbose log will look something like this.

Now it is time to do small testing from Postman .  As provided in the url : [POST]


AWS Lambda Serverless Endpoing test

AWS Lambda Serverless Endpoing test


It is quiet so easy isn’t it ? Just code what you want and deploy it. But there are some limitation of the serverless. It is not suitable for all kind of application and it definitely does not supersede the normal server deployment because of its nature and limits.

1. Maximum execution duration per request

We just cannot use request for long task like more than 5 minutes. AWS has a hard limit of 5 minutes for every request execution.


2. Memory resources limit

There are some limits of memory to be used by every single function . It is like 3008M in aws lambda as of now (2018-09-11).


3. Coldstart

Your function will actually sleep after unused for some minutes. When you request after the sleep time it need to warm up the server again which takes some seconds and it might not be good for those who wants to get the request instantly (realtime). There are some way which will keep your server warm all time described How to keep desired amount of AWS Lambda function containers warm


4. Payload size limit

You might not want to send a large data from your http request because there is a limit for request payload as well . As per AWS there is 6MB limit for payload however you can use event driven aws lambda execution for avoid sending payload directly to lambda.


5. Ephemeral disk capacity

You just cannot use your disk space more than 512 mb which is /tmp directory of server while you do any data processing or any process which involves usage of hard disk space.


After talking about the limitations I would still prefer this serverless for some of my application like generating the pdf invoices for customer, doing scheduled tasks and others. In next blog post I would talk about how to run serverless locally and we can discuss about the overall complication and solutions.

Stay cool , be happy and code  😉


Tags: , , , , ,

New Twitter Application on Desktop

A new Java-based Twitter Application launched on Feb 14 on Facebook for all the public user for free.

Any one can download the twitter application and they can easily tweet from their desktop and there is not need to open browser . Currently it has just facility of tweets delete, favourites, facebook friend’s tweets but soon there would be new facilities like language translator, Tweet search so let’s grab this application right now .

Download  from the application of Facebook:Twitter Desktop Application
Download this app to Desktop Directly: Twitter Desktop Application

Twitter Application for Desktop

Tags: , , , , ,

Making Simple JTable

The JTable is almost great component of Java Swing which is used to display records of any data.
Specially JTable are used for displaying records which are retrived from the database like MySQL, ORACLE ,Excel and other…

Simply JTable has it’s default model for displaying the records in format.
In this blog we would just demonstrate a simple JTable where all the data records are being assigned by developers.

Ok, here is a detail codes of Making simple JTable:

Read the rest of this entry »

Tags: , , , , ,


This JFrame is a class which is located at the java package javax.swing

JFrame helps to form applet , this class is one type of Container where different Components can be

added by getContentPane() and add() method of this class.


The JFrame is one of the static or predefined Frame where there is limitation of extending the Frame feature

All the classes of

package are predefined applet components. It’s design is also static on all

operating system. There is platform independent design of JButton,JLabel,JTextField bar and all things. Here we use JFrame for the

independent of the application.

Where as in the context of

The components like Button,Label all are platform indendent as well.

Tags: , , ,

Trick of Positioning the Containers of JFrame

Many developers want their own Layout Manager with user-defined so JAVA has provided a separate method for the every container of JFrame Component and that method is setBounds(). This method helps the developers to position the container as per their need .

About SetBounds() method:

This method consists four parameter

We can arrange the containers with the help of this method easily. Read the rest of this entry »

Tags: , , , , , , , , , ,