Posts

Showing posts from October, 2021

Mask all the characters except last 4 digit/character

  Questions: WAP to mask all the character of string except last 4 characters Eg: 12324324234354            ########## 4354        1213                                                               1223          1                                                                      1     spotify                                      ###tify Solution:           ...

Get first non-repeating Letter

import java.util.HashMap ; import java.util.LinkedHashMap ; import java.util.Map ; import java.util.HashMap ; import java.util.LinkedHashMap ; import java.util.Map ; public class Check { public static String firstNonRepeatingLetter ( String str) { String val= null ; char [] var =str.toCharArray(); LinkedHashMap < Character , Integer > map = new LinkedHashMap<>(); for ( int i= 0 ;i< var . length ;i++){ if ( map .containsKey( var [i])){ map .put( var [i], map .get( var [i])+ 1 );} else { map .put( var [i], 1 ); } } for ( Map . Entry < Character , Integer > entry : map .entrySet()){ if ( entry .getValue()== 1 ) { val = Character . toString ( entry .getKey()); break ; } } return val; } public static void main ( String [] args) { System . out .println( firstNonRepea...

Docker commands

List all images in docker-engine docker ps -a Delete image from the local image store docker image rm alpine:3.4 Run a container from the Alpine docker container run --name web -p 5000:80 alpine:3.9 Stop a running container through SIGTERM docker container stop web Stop a running container through SIGKILL docker container kill web List the running containers  docker container ls Print the last 100 lines of a container’s logs docker container logs --tail 100 web(container name) List the networks docker network ls   

Maven multi module projects

A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom. Now, the submodules are regular Maven projects, and they can be built separately or through the aggregator POM. By building the project through the aggregator POM, each project that has a packaging type different than pom will result in a built archive file. Parent POM Maven supports inheritance in a way that each pom.xml file has the implicit parent POM, it's called Super POM and can be located in the Maven binaries. These two files are merged by Maven and form the Effective POM. Hence, we can create our own pom.xml file which will serve us as the parent project. Then, we can include there all configurations with dependencies and set this as the parent of our child modules, so they'll inherit from it. Besides the inheritance, Maven provides the notion of aggregation. Parent ...

Kafka commands

 Producer console ./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic --partition 0 Consumer console ./bin/kafka-console-consumer.sh --broker-list localhost:9092 --topic testTopic --partition 0 Describe a topic ./bin/kafka-topic.sh --describe --zookeeper localhost:2181 --topic <topicName> Broker Version ./bin/kafka-broker-api-versions --bootstrap-server localhost:9092 --version Create a topic  /bin/kafka-topics.sh --zookeeper $ZK_HOSTS --create --topic $TOPIC_NAME --partitions 3 --replication-factor 3 Create a topic if it doesn't exist /bin/kafka-topics.sh --zookeeper $ZK_HOSTS --create --topic $TOPIC_NAME --partitions 3 --replication-factor 3 --if-not-exists List brokers ./usr/bin/kafka-topics --zookeeper zookeeper:2181 --list Show Kafka topic details ./usr/bin/kafka-topics --zookeeper zookeeper:2181 --topic my-first-topic --describe Increase partitions in the topic ./usr/bin/kafka-topics --zookeeper zookeeper:2181 --alter --topic my-first-top...

Check string is Palindrome

  Recursive Technique public class RecursionPalindrome { public static void main ( String [] args) { String str = "madada" ; System . out .println( new RecursionPalindrome().recursivePalindrome( str , 0 , str .length()- 1 )); } public boolean recursivePalindrome ( String txt, int front, int back){ if (front==back) return true ; if (txt.charAt(front)!=txt.charAt(back)) return false ; if (front<back+ 1 ) return recursivePalindrome(txt,front+ 1 ,back- 1 ); return false ; } } Using Loop public class Palindrome { public boolean isPalindrome ( String str){ int l =str.length()- 1 ; for ( int i= 0 ;i<str.length()- 1 ;i++){ if (str.charAt(i)!=str.charAt( l -i)) return false ; } return true ; } public static void main ( String [] args) { System . out .println( new Palindrome().isPalindrome( "malayala...

Maven Intro

Image
  Maven Maven is a build automation tool used primarily for Java projects. Maven builds a project using its project object model (POM) and a set of plugins. Maven’s primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal, Maven deals with several areas of concern: Making the build process easy Providing a uniform build system Providing quality project information Encouraging better development practices Maven provides useful project information that is in part taken from your POM and in part generated from your project’s sources. For example, Maven can provide: Change log created directly from source control Cross-referenced sources Mailing lists managed by the project Dependencies used by the project Unit test reports including coverage Third-party code analysis products also provide Maven plugins that add their reports to the standard information given by Maven. Maven Archetype...