- Goto Run > Edit Configuration
- Choose the configuration you want to edit, in the left under Application.
- On the right side > Under Environment Variable, update
spring.profiles.active=<your profile name>
examplespring.profiles.active=dev
(observer:- the variable should be without -D flag) - Save the changes and Run the Spring boot app with the same configuration.
Vikash Java Blogs and UI Development
It's my passion to learn java and want to share my knowledge with java programmers.
Wednesday, 15 November 2023
Profiles setting in intellij Springboot
Friday, 2 April 2021
Java8 Features and interview questions
JAVA 8 INTERVIEW QUESTION AND ANSWER (Experienced)
Significant reason for introducing java8 was to introduce Conciseness in the code.
JAVA bring in Functional programming which is enabled by Lambda expression ( a powerful tool to create concise code base.)
Q) What are new features which got introduced in java8?
1. Lambda Expression
2.Stream API
3. Default method in the Interface
4. Static method
5. Functional Interface
6. Optional
7. Date
8. Nashron, Javascript Engine
9. Method reference
Q) What are main advantages of using Java 8?
Main advantages
Compact cod ( Less boiler plate code)
More readable and reusable code.
More testable code
Parallel operations
Q. What is Lambda Expression?
Lambda expression is an anonymous function (without name, return type and access modifier and having on lambda (->) symbol.
Q. What is Functional Interface?
Functional interfaces are those interface which can have only one abstract method.
It can have any number of static method, default method.
There are many functional interfaces already present in java such as Comparable and Runnable.
A Functional Interface can be used as a reference for Lambda expression.
Sunday, 14 July 2019
Java Sorting Algorithm How to find the duplicates elements in array
I am giving examples of finding the duplicate elements in java.
Best way to find the duplicate elements in java is to use the sort the elements of the array and compare each element with their next element.
I have commented some of the method, if you remove the comment before the function call then you can check one by one. I found this is very useful in real time scenario and solving the interview question.
Using this sorting technique we can perform String manipulation as well, because String is nothing but it's also built up with array. You can be able to check the duplicate character in string as well.
Example:
package com.vikash.java8;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class ArrayDuplicate {
public static void main(String args[]) {
int array[] = { 5, 5, 3, 8, 2, 1, 8, 3, 3, 1 };
ArrayDuplicate dup = new ArrayDuplicate();
// dup.myFunction(array);
System.out.println();
// dup.withoutSorting(array);
// dup.bubbleSort(array);
dup.findDuplicateUsingMap(array);
}
public void myFunction(int array[]) {
Arrays.sort(array);
System.out.println("After Sorting the elements");
for (int a : array) {
System.out.print(a + " ");
}
System.out.println();
for (int i = 0; i < array.length - 1; i++) {
if (array[i] == array[i + 1]) {
System.out.println("Duplicate found::" + array[i] + ":::" + array[i + 1]);
}
}
}
public void withoutSorting(int[] array) {
for (int i = 1; i < array.length; i++) {
for (int j = 0; j < i; j++) {
if (array[j] == array[i]) {
System.out.println("Duplicate Found::" + array[j] + "::" + array[i]);
}
}
}
}
public void bubbleSort(int[] array) {
int temp;
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array.length - 1; j++) {
if (array[j] > array[j + 1]) {
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
for (int e = 0; e < array.length - 1; e++) {
if (array[e] == array[e + 1]) {
System.out.println("Duplicate Found::" + array[e]);
}
}
}
public void findDuplicateUsingMap(int[] array) {
Map<Integer, Integer> myMap = new HashMap();
for (int i = 0; i < array.length; i++) {
if (myMap.containsKey(i)) {
myMap.put(array[i], myMap.get(i) + 1);
} else {
myMap.put(array[i], 1);
}
}
for (Map.Entry<Integer, Integer> itr : myMap.entrySet()) {
System.out.println(itr.getKey() + " " + itr.getValue());
}
}
}
Thursday, 18 December 2014
Controller in AngularJS
Controller should be straight forward and simply contain the business logic needed for a view.
There are many ways to define a controller in Angular js.
Examples are as follows:
<div ng-controller="myCtrl">
<p>{{name}}</p>
</div>
function myCtrl($scope)
{
$scope.name="vikash Angular Solution";
}
Thursday, 5 June 2014
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
</head>
<body ng-app="myapp">
<div ng-controller="HelloController" >
<h2>Hello {{helloTo.title}} !</h2>
</div>
<script>
angular.module("myapp", [])
.controller("HelloController", function($scope) {
$scope.helloTo = {};
$scope.helloTo.title = "World, AngularJS";
} );
</script>
</p>
</body>
</html>
What is Angular.js with example
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
</head>
<body ng-app="myapp">
<div ng-controller="HelloController" >
<h2>Hello {{helloTo.title}} !</h2>
</div>
<script>
angular.module("myapp", [])
.controller("HelloController", function($scope) {
$scope.helloTo = {};
$scope.helloTo.title = "World, AngularJS";
} );
</script>
</p>
</body>
</html>
Thursday, 15 May 2014
Difference Between Comparable and Comparator
1. Comparable belongs to java.lang.package
2. Comparable is by default uses by java collections to sort their element in sorted element.
3. Comparable has the method named compareTo which is use to compare two object and returns -1, +1
and o zero.
4. If we want to use comparable interface then the class
public int Object1.compareTo(Object2) ;
If object1 is less than object2 it will return -1, and if the object1 is greater than object2 then it will teturn +1 and if both are equal then it will return 0.
5. Suppose we have a class Employee and the employee has many details. But if we want to sort the Employee details according to their age using the collections then we have to implement the comparable in he employee class and override the compareTo method there. Means a class which want to be sorted using collections using comparable it must have to implement Comparable interface.
6. But using comparator we not need to implement the Comparator interface instead of this we can create an different java class that will help to sort the class (Employee)