2019 - CodeByAkram
undefined 201

Write a program to print first non repeated char in a string in Java.

We are using the HashMap to store the character as key and count of times it is repeated as value. package com.string.codebyakram; import java.util.HashMap; public class NonReapingCahr { public static void main(String[] args) { String string = "hello"; System.out.println(findNonReapingCahr(string)); } ...
undefined 201

How to create multiple log file using same log4j property file?

You can create multiple logs file by using same log4j properties file or you can send logs to multiple files by using same log4j file. Add this below to your log4j properties file. log4j.rootLogger=TRACE, stdout log4j.appender.dataLogs=org.apache.log4j.FileAppender log4j.appender.dataLogs.File=logs/logFile1.log log4j.appender.dataLogs.layout=org.apache.log4j.PatternLayout log4j.appender.dataLogs.layout.ConversionPattern=%d...
undefined 201

How to delete log4j/log file older than N number of days?

package com.avaya.deletelogs; import java.io.File; import java.io.FilenameFilter; import java.util.Arrays; import java.util.List; public class DeleteLogs { private String baseDir = "/opt/java/IVRLog"; private int daysBack = 4; public void invokeProcess() { getFolders(); } public void getFolders() { try...
undefined 201

What do you mean by Aspect, Join Point, Advice?

What’s the difference between @Component, @Controller, @Repository & @Service annotations in Spring? Pointcut: Pointcut are expressions that is matched with join points to determine whether advice needs to be executed or not. Pointcut uses different kinds of expressions that are matched with the join points...
undefined 201

What’s the difference between @Component, @Controller, @Repository & @Service annotations in Spring?

Spring 2.5 introduces further stereotype annotations: @Component, @Service, and @Controller. @Component is a generic stereotype for any Spring-managed component. @Repository, @Service, and @Controller are specializations of @Component for more specific use cases,...
undefined 201

Differentiate between constructor injection and setter injection

Partial Dependency In Setter Injection, partial dependency is possible, means if we have 4 dependencies as mentioned below, Then it is not necessary to inject all values if we are using setter injection. But in Constructor Injection, partial dependency is not possible because we are calling the constructor of that...
undefined 201

Java 8 Lambda Comparator

Lets se how we can sort the object by using java 8 lambda comparator. For this let take a Employee class. public class Employee { private String name; private int salary; // standard constructors, getters/setters, equals and hashcode } 1. Classic sort (without lambda) Comparator< Employee...
undefined 201

How to get keys and values from Map in Java?

As we know, map is based on key-value pair associations, so interviewer can ask you this question if you are a beginner or having less than 3 years of experience. So lets see how we can the key and values from a Map? In Java we have and Map.Entry method that returns a collection-view of map. Map< string string="">...
undefined 201

How to set connection timeout for RestTemplate in spring?

We can set the timeout for RestTemplate by doing some custom configuration for RestTemplate. First you need to create a class named as HttpClientConfig in this class we configure HttpClient because RestTemplate internally uses the HttpClient. package com.codebyakram; import org.apache.http.client.config.RequestConfig; import...
undefined 201

How to Sort a Stack using Merge Sort?

Interviewer may ask you this question if you have more than 3 years of experience in java development. So lets have a look, how to sort a stack using merge sort? Lets see sample input and output for better understanding: Algorithm For this we will follow these below two steps, 1. Break the stack into two parts...
undefined 201

Adjacency List in Java

An adjacency list represents a graph as an array of linked list. The index of the array represents a vertex and each element in its linked list represents the other vertices that form an edge with the vertex. Adjacency List representation A graph and its equivalent adjacency list representation is shown below. An...
undefined 201

Breadth first search in Java

Traversal meaning visiting all the nodes of a graph. Breadth first Search is also known as Breadth first traversal and is a recursive algorithm for searching all the nodes of a graph or tree data structure. BFS algorithm A standard BFS algorithm implementation puts each nodes of the graph or tree into one of two categories: Visited...
undefined 201

DFS algorithm in Java

Traversal meaning visiting all the nodes of a given graph. Depth first Search is also know as Depth first traversal. DFS is a recursive algorithm for searching all the vertices of a graph or tree. DFS algorithm A standard DFS implementation puts each vertex of the graph into one of two categories: 1.Visited 2. Not...
undefined 201

Heap Sort in Java

Before looking into Heap Sort, let's understand what is Heap and how it helps in sorting. What is Complete Binary Tree? A Complete binary tree is a binary tree in which every node other than the leaves has two children. In complete binary tree at every level, except possibly the last, is completely filled, and all nodes...
undefined 201

Merge sort in Java

Related questions: Sort Linked List using Merge Sort, Given a Linked list, Sort it using Merge Sort Algorithm. Merge sort is preferred algorithm for sorting a linked list, lets see why, The way linked list is structured which doesn't allow random access makes some other algorithms like Quicksort perform poorly,...
undefined 201

Insertion Sort in Java

Given a array of integers, Sort it using Insertion sort. Lets understand what is the input and the expected output. Example Assume 5 persons of different heights are visiting at your office each at 5 minutes interval and you need to make them stand according to their heights(smaller to higher). How you will do? Below...
undefined 201

How To deploy Spring Boot application on Tomcat?

How To deploy Spring Boot application on existing Tomcat? Related Questions:- Deploy a Spring Boot WAR into a Tomcat Server, Spring Boot – Deploy WAR file to Tomcat Spring boot is a framework that allow you to set up production ready setup of spring application and also Tomcat is one of the most popular...
undefined 201

How to use regular expressions with String methods in Java?

How to use regular expressions with String methods in Java? Strings in Java have built-in support for regular expressions.  Strings have 4 built-in methods for regular expressions, i.e., the matches(), split()), replaceFirst() and replaceAll() methods. Method ...
Page 1 of 61236Next