Friday, May 17, 2019

Algorithm to find if String contains only Unique characters without using any additional data structure

The string is one of the most asked questions in the Interview of Java developers.


Today we will see one of the most asked questions as to how will you find if String does not contain any duplicate characters.



There are different ways to check them, But we will only discuss the most efficient way to implement this algorithm.

Logic.

We know that characters have only 256 ascii values and there are only 128 values for alphabet characters. 
So what we will do is we will create one array of boolean of size 128 and we will update the index of array as true whenever we find the char value in the string , else if we get the same value in the string , the already true value will make the loop as false.
Also read - Find Longest Common Ancestor(LCA) Program in java

Time Complexity - O(n)
Space Complexity - O(1)

Code -



public class ArraysAndStringDemo {
 
 public static void main(String[] args) {
  
  String str = "programinjava";
  
  System.out.println(isUnique(str));
  
 }
 
 public static boolean isUnique(String str) {
  boolean[] char_set = new boolean[128];
  for(int i =0;i<str.length();i++) {
     int value =str.charAt(i); //getting the ascii value of character
   
     if(char_set[value])     // checking if it is already in the array
   return false;
   
     char_set[value] = true;
  
   
  }
  return true;
 }

}

If you have any issue in understanding the same , Please leave us a comment. Happy to help

Thanks for reading
Noeik

Saturday, March 9, 2019

Real time Logs of AWS Elastic Beanstalk by Command Prompt

Many of us know that one of the most important services of AWS is Elastic beanstalks. We deployed our application on Beanstalk and AWS itself manage most of the thing in it. One of them is Logs of Applications.


People usually were not able to see the tail of the logs of the application what they need to do is to go to the beanstalk and under logs, they ask for the last 100 lines of logs or full logs (which include the of the application along with the other logs ).



Today we will learn how to connect with the beanstalk application through EB CLI and see the logs.


let's follow the below steps.
  1. Install the Python Once installed run below commands
  2. python --version
  3. pip --version
  4. pip install awsebcli --upgrade --user
  5. once ebcli installed successfully, you can check by 
  6. eb --version
  7. define the Python Home in your Environment Variable.
  8. Now Run your command prompt as Administrator  and write 
eb init --interactive
You will see the below image.
  • Now select the region you have deployed your application.
  • After that, you will be asked to Create a new Application 
  • Once your application will be created you will see below screen.
  • You need to select the appropriate platform you have used for your application.
  • Now Once you do it you will be asked to create the SSH 
Select Yes 
  • Then they will ask you to create the keypair 


  • Provide your password  and then you will see the below image 
  • Now you have successfully created your SSH and it is uploaded to your beanstalk as well.
  • you need to attach the SSH with the Application.

Follow below steps 

eb ssh <Application-name> --settings

  • You will get the list of options then it will ask for the keypair which you need to attach.
  • Select the appropraite one.
  • After selecting the one you will be asked to enter the password set earlier.
  • You will then have the Applicaiton connected.
  • Once connected successfully you will be getting below image.
Now go to 
/var/log/tomcat8 ( to see the application logs, if your application is deployed on tomcat)

I Hope you will be able to connect your local machine to EB , If you have any issue  ,Please leave us a comment we will look into it.

Also Read:
  1. Spring Boot and Hibernate Tutorials - Application using Spring Boot
  2. What is Spring boot ?
  3. How to read value from property file in spring boot ?
  4. First Rest API Application - Top Spring Framework Interview Questions
  5. Implementation of Swagger in Spring boot
  6. How to use h2 database in spring boot

Thanks for reading.



Saturday, February 16, 2019

Database Timezone issue -Solution in java

We have at least once in our development has encountered one issue with database and client location is Timezone difference. 



In most of the cases, Our Backend /Application server is in a different timezone and our client server is in a different timezone. So what actually the problem happens is the difference in data time because of Timezone.