Sunday, September 15, 2019

AWS Server Less technology


AWS Server Less Technology (Boon for software  entrepreneur)

To overcome the server management issue and to eliminate the server configuration, we can use the AWS Lambda for compute, AWS web service for to provide server based environment and AWS S3 Bucket for Storage. It will help us to develop dynamic website.


  1. AWS Lambda – Compute (Overcome Server Management Problem)
  2. AWS API Gateway –Provides Server Environment (Overcome Server Management Problem)
  3. AWS Dynamo DB/ S3 Bucket - Storage (Enhance Storage and Fast Hosting)
  4. AWS Elastic Cache-Caching Mechanism for fast Retrieval. (Overcomes Server loading problem)

AWS Lambda:
  • AWS Lambda is a compute service that lets you run code without provisioning or managing servers.
  • It executes your code only when needed and scales automatically, from a few requests per day to thousands per second.
  • It runs your code on a high-availability compute infrastructure and performs all of the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, code monitoring and logging.
  • We need to code in one of the languages that AWS Lambda supports (currently Node.js, Java, C# and Python).
  • In java, it is a function implemented by Request Handler functional Interface, this interface is provided by AWS Java SDK.
AWS API Gateway:
  • Amazon API Gateway helps developers to create and manage APIs to back-end systems running on Amazon EC2, AWS Lambda, or any publicly addressable web service.
  • Amazon API Gateway to expose the Lambda function, This API will be accessible on the  internet with added security.
AWS Dynamo DB:
  • It is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale.
  • It is a fully managed cloud database and supports both document and key-value store models.
  • Amazon Dynamo DB Accelerator (DAX) is a fully managed, highly available, in-memory cache that can reduce Amazon Dynamo DB response times from milliseconds to microseconds, even at millions of requests per second.
AWS Elastic Cache:
  • It is a web service that makes it easy to deploy, operate, and scale an in-memory data store or cache in the cloud.
  • This service improves the performance of web applications by allowing you to retrieve information from fast, managed, in-memory data stores, instead of relying entirely on slower disk-based databases
  • In java, Jedis library is used to provide Elastic cache functionality.
  • It will cache the transaction data in terms of key and value pair.
Elastic cache Connection establishment code.
Conclusion:
This Services makes our project more scalable and flexible, it totally reduces server based configuration.
It increases server response time three times faster than earlier methodology.
It makes developer to concentrate only on business logic. In my next bog, I will explain about the sample POC about AWS Integration with Java

AWS Integration with Eclipse:
The AWS Toolkit for Eclipse is an open source plug-in for the Eclipse integrated development environment (IDE) that makes it easier for developers to develop, debug, and deploy Java applications that use Amazon Web Services.
Use this link for to add AWS plugin with eclipse



Tuesday, August 2, 2016

COMPARING TWO OBJECTS IN JAVA



                                             

OVERRIDING EQUALS METHOD


public class CompareData
{
     private String param1;
        private String param2;
       
public CompareData(String firstName,
                String lastName)
{
this.param1 = firstName;
this.param2 = lastName;
}

@Override
public boolean equals(Object obj)
{
    boolean isEqual = false;
    if (this.getClass() == obj.getClass())
    {
        System.out.println("Entered for equality check..");
        CompareData comp = (CompareData) obj;
        if ((comp.param1).equals(this.param1) &&
                (comp.param2).equals(this.param2))
        {
            isEqual = true;
        }
    }

    return isEqual;
}

       
    public static void main(String[] args)
    {
         CompareData obj1=new CompareData("Ram","Sita");
        CompareData obj2=new CompareData("Ram","Sita");
               if(obj1.equals(obj2))
        {
            System.out.println("Both the objects are equal");
        }
        else
        {
            System.out.println("Both the objects are not equal");
        }
       
    }

}


Monday, June 27, 2016

JAVAFX THREAD



JAVAFX THREAD TO CHANGE UI (USER INTERFACE) FORM DYNAMICALLY


import javafx.application.Platform;

Platform.setImplicitExit(false);
            Task task = new Task<Void>() {
                @Override
                public Void call() throws Exception {
                    int i = 0;
                    Thread.sleep(100);

                    Platform.runLater(new Runnable() {
                        public void run() {

                           
                            proViewContlr.getProView().getScroll()
                                    .setVvalue(0.70);
                        }
                    });

                    return null;

                }
            };
            Thread th = new Thread(task);
            th.setDaemon(true);
            th.start();

DESKTOP NOTIFICATION IN JAVA (SWING)

DESKTOP NOTIFICATION IN JAVA (SWING)



import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;


public class Notification
{
    public static void init()
    {
                String message ="ALL POWER IS WITH IN YOU ,YOU CAN DO ANYTHING AND EVERYTHING BELIVE IN THAT";
                String header = "NOTIFICATION MESSAGE";
                final JFrame frame = new JFrame();
                frame.setSize(300,125);
                frame.setUndecorated(true);
                frame.setLayout(new GridBagLayout());
                GridBagConstraints constraints = new GridBagConstraints();
                constraints.gridx = 0;
                constraints.gridy = 0;
                constraints.weightx = 1.0f;
                constraints.weighty = 1.0f;
                constraints.insets = new Insets(5, 5, 5, 5);
                constraints.fill = GridBagConstraints.BOTH;
                JLabel headingLabel = new JLabel(header);
                ImageIcon img=new ImageIcon("question_icon1.png");
                headingLabel .setIcon(img); // --- use image icon you want to be as heading image.
                headingLabel.setOpaque(false);
                frame.add(headingLabel, constraints);
                constraints.gridx++;
                constraints.weightx = 0f;
                constraints.weighty = 0f;
                constraints.fill = GridBagConstraints.NONE;
                constraints.anchor = GridBagConstraints.NORTH;
                JButton cloesButton = new JButton(new AbstractAction() {
              
                    public void actionPerformed(ActionEvent e) {
                        // TODO Auto-generated method stub
                        frame.dispose();
                      
                    }
            });
                cloesButton.setText("X");
                cloesButton.setMargin(new Insets(1, 4, 1, 4));
              
                cloesButton.setFocusable(false);
                frame.add(cloesButton, constraints);
                constraints.gridx = 0;
                constraints.gridy++;
                constraints.weightx = 1.0f;
                constraints.weighty = 1.0f;
                constraints.insets = new Insets(5, 5, 5, 5);
                constraints.fill = GridBagConstraints.BOTH;
                JLabel messageLabel = new JLabel("<HtMl>"+message);
                frame.add(messageLabel, constraints);
                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();// size of the screen
                Insets toolHeight = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());// height of the task bar
                frame.setLocation(scrSize.width - frame.getWidth(), scrSize.height - toolHeight.bottom - frame.getHeight());
                frame.setVisible(true);
    }
    public static void main(String args[])
    {
        init();
      
    }

}

Tuesday, June 14, 2016

ANDROID TAB NAVIGATION




ANDROID TAB NAVIGATION


 
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;


public class AndroidTabLayoutActivity extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_android_tab_layout);
        TabHost tabHost = getTabHost();
       
        // Tab for Insert new Element
        TabSpec photospec = tabHost.newTabSpec("Insert");
        // setting Title and Icon for the Tab
        photospec.setIndicator("Insert", getResources().getDrawable(R.drawable.tick_icon));
        Intent photosIntent = new Intent(this, PhotosActivity.class);
        photospec.setContent(photosIntent);
        
        // Tab For to view
        TabSpec songspec = tabHost.newTabSpec("View");       
        songspec.setIndicator("View", getResources().getDrawable(R.drawable.minutes_icon1));
        Intent songsIntent = new Intent(this, SongsActivity.class);
        songspec.setContent(songsIntent);
        
        // Tab for delete
        TabSpec videospec = tabHost.newTabSpec("Delete");
        videospec.setIndicator("Delete", getResources().getDrawable(R.drawable.question_icon1));
        Intent videosIntent = new Intent(this, VideosActivity.class);
        videospec.setContent(videosIntent);
        
        // Adding all TabSpec to TabHost
        tabHost.addTab(photospec); // Adding photos tab
        tabHost.addTab(songspec); // Adding songs tab
        tabHost.addTab(videospec); // Adding videos tab
       
    }



}

Wednesday, May 25, 2016

TELEPHONY BROADCAST RECEIVER IN ANDROID

                                  TELEPHONY BROADCAST RECEIVERS IN ANDROID

 

INCOMING CALL BROADCAST RECEIVER:

 

package com.dat.spy.spyroid;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class MyPhoneReceiver extends BroadcastReceiver {



    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            String state = extras.getString(TelephonyManager.EXTRA_STATE);
            Log.w("MY_DEBUG_TAG", state);
            if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                String phoneNumber = extras
                        .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
                Log.w("MY_DEBUG_TAG", phoneNumber);
                Toast.makeText(context,"Call action no.."+phoneNumber,Toast.LENGTH_LONG).show();
            }
        }
    }
}

OUTGOING CALL BROADCAST RECEIVER:


package com.dat.spy.spyroid;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;



public class OutgoingCallReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {

        String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        Log.d(OutgoingCallReceiver.class.getSimpleName(), intent.toString() + ", call to: " + phoneNumber);
        Toast.makeText(context, "Outgoing call catched: " + phoneNumber, Toast.LENGTH_LONG).show();

    }
}


MESSAGE RECEVING BROADCAST RECEIVER:

 

package com.dat.spy.spyroid;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SmsBroadcastReceiver extends BroadcastReceiver {

    public static final String SMS_BUNDLE = "pdus";

    public void onReceive(Context context, Intent intent) {
        Bundle intentExtras = intent.getExtras();
        if (intentExtras != null)
        {
            Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
            String smsMessageStr = "";
            for (int i = 0; i < sms.length; ++i) {
                SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);

                String smsBody = smsMessage.getMessageBody().toString();
                String address = smsMessage.getOriginatingAddress();

                smsMessageStr += "SMS From: " + address + "\n";
                smsMessageStr += smsBody + "\n";
            }
            Toast.makeText(context, smsMessageStr, Toast.LENGTH_LONG).show();

         
        }
    }
}

AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dat.spy.spyroid">
    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".SpyActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name=".SmsBroadcastReceiver" android:exported="true" >
        <intent-filter android:priority="999" >
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
        </receiver>

        <receiver android:name="MyPhoneReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" >
                </action>
            </intent-filter>
        </receiver>

        <receiver android:name=".OutgoingCallReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
            </intent-filter>
        </receiver>



    </application>

</manifest>