Hello!, I just tried to create my work desk using CSS and HTML. Here all I used is<div>.
CSS :
HTML:
OUTPUT:
Blog about Java, Spring Boot, Hibernate, CSS, HTML, Interview questions and Programming
Hello!, I just tried to create my work desk using CSS and HTML. Here all I used is<div>.
CSS :
HTML:
OUTPUT:
Error creating bean with name 'conversionServicePostProcessor' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.beans.factory.config.BeanFactoryPostProcessor]: Factory method 'conversionServicePostProcessor' threw exception; nested
The same code working other for my team, so I just googled the error and find some suggestion,
spring.main.allow-bean-definition-overriding=true
But this same already available in my application.properties.
spring.main.allow-bean-definition-overriding=true
So I have no clue to solve this issue, I tried many suggestion nothing works for me. Then I remember one, what if I try to
Reimport All Maven Projects in my IDE, I am using IntelliJ. If you are using Eclipse just refresh the dependencies.
After all the jar loading done, I retried to start the server. Finally it works for me.
If you have some problem initializing spring boot bean after successful mvn install, just try reimport your jars on your IDE.
Because sometime your IDE need manual call to get refresh the dependencies.
In Spring Boot, Actuator allows you to monitor your application, by just adding a dependency in you pom.xml. By adding this dependency we can able to track health check of the application. This will help on production environment, to check the application is running or not?.
Let see how to implement this,
Create a spring boot application using Spring initializr . To test actuator we need to select spring-boot-starter-actuator along with spring-boot-starter-web(without this we cannot start the server).
Here my project specification, Using java 8, Maven Project .
To Start application we need to do mvn clean install. Once that done we are good to start the server.
While starting the server we will see following log that confirm that we are enabling the actuator.
Add below code in your application.properties to expose all the monitoring method.
management.endpoints.web.exposure.include=*
Here let check server log after exposing all the monitoring methods,
We can see 14 endpoints exposed. Here output is like below,
I captured part of the output.
This will enable expose all the method available in spring boot monitoring.
Or we can add specific property by using below,
management.endpoint.health.enabled=true
management.endpoint.loggers.enabled=true
And let see what we can see by calling endpoint actuator/health
by calling http://localhost:8081/actuator/beans we can see what are the bean
initialized on server start of the this application.
Here I created a coffee cup using css Coffee cup . Added new style to display logo in the cup.
I am using my previous employer logo. The same cup the given me on my first day of joining.
Here css changes
HTML changes:
Output:
Need to add more style to look like exact coffee cup with their logo. Working on it....!Today we faced a issue in dev environment, the same code works perfectly in local. We have no clue what happens in prod, we thought of data is problem in dev environment. While comparing data between environment we find the empId (Long Type is problem), which mean the type is not a problem, the way compare the Long variable makes the problem in different environment.
Here code snippet of problematic code.
Boolean isEmployee = employee.getEmpId() == emp.getEmpId();
Since in local we have limited data might be around 50 data max, so empId is might max 50.
Let see what happen in dev environment.
Dev environment we have lot of data for this particular table. approximately 10000+ records.
What is the fix for our problem??
We need to use .equals instead of ==. Fix is employee.getEmpId().equals(emp.getEmpId()) or employee.getEmpId().longValue() == emp.getEmpId().longValue().
Here is two example of < 127 and > 127.
public static void main(String[] args) {
Employee employee = new Employee("B", 1, 128L);
Employee emp = new Employee("B", 1, 128L);
Boolean isEmployee = employee.getEmpId() == emp.getEmpId();
if(isEmployee){
//Logic here.
System.out.println("Same Employee");
}else{
System.out.println("Different Employee");
}
System.out.println(employee.getEmpId() == emp.getEmpId());
System.out.println(employee.getEmpId().equals(emp.getEmpId()));
}
Output:
private static void sayHello(){
System.out.println("Hello !");
return sayHello();
}
If you execute this method we will end up with stackoverflow exception. The exception will
be thrown after jvm stack overloaded,
......... here is lot of Hello ! printed.
Hello !
Hello !
Hello !
Hello !
Exception in thread "main" java.lang.StackOverflowError
at sun.nio.cs.UTF_8$Encoder.encodeLoop(UTF_8.java:691)
at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:579)
Because in this method we don't have any base condition to return this recursion stack trace.
This is very important when you go for recursion we need to have base condition at
first in you implementation.
private static void sayHello(int n){
if(n<1){
return ;
}
System.out.println("Hello !");
sayHello(n-1);
}Here if condition check n is less than 1, this is our base condition. So now you will get
some idea about how recursion works in java. Let we get in our fibonacci program,private static long printFibonacci(int n){
if(n<=1){
return n;
}
return printFibonacci(n-1) + printFibonacci(n-2);
}If user input n is 5 then this program will print 5(0,1,1,2,3,5) the number is start with 0
so we will get 5.
Explanation for printFibonacci() is loading...
Multithreading provider ability to execute multiple different path of code in same time
Normally java run into only one thread, but we have the ability to break off into multiple thread and do multiple things at once.
There are two main way to create thread.
1. Class extends Thread class, we need to override the run method from thread class, which is extends from Runnable interface.
public class MyThread extends Thread {
@Override
public void run(){
for(int i = 0; i < 5; i++){
System.out.println("Count : " + i + " Thread name : " + Thread.currentThread());
}
}
}
public class ThreadTester {
public static void main(String[] args) {
MyThread myThread = new MyThread();
myThread.start();
}
}
Here the test file to run the thread and we are printing currently running thread. Below console log,
2. Implements Runnable interface, override run method from Runnable interface. While using implement we need to create Thread instance explicitly to call start() or run().
public class MyRunnable implements Runnable {
@Override
public void run() {
for(int i = 0; i < 5; i++){
System.out.println("Thread is running with: " + i + " " + Thread.currentThread());
}
}
}
public class ThreadTester {
public static void main(String[] args) {
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable);
thread.start();
}
}Above tester class we are instantiate thread object with name of MyRunnable class.And console log is below
If you notice we are override run() method from Runnable interface, but we called start()from Thread class.What will happen if we call run() instead of start(). Let me explain about start() and run().Start():Calling start() will create a new thread from existing thread then run() will be execute,
and its enables multithreading.
From above two coding example, we are seeing that Tread-0 is created from main thread.
[Thread-0,5,main]
run(): Calling run() will not create new thread, it execute as normal method with existing
thread, no multithreading will be enabled.
let see example of calling run()
public class ThreadTester {public static void main(String[] args) {
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable);
thread.run();
}
}Let see from output,
From above console the run method is called as a method in main thread [main,5,main].Now let see how the multiple thread running in java, here I will create two object ofMyThread class and call start() of created instance.public class ThreadTester {
public static void main(String[] args) {
MyThread myThread = new MyThread();
MyThread myThread1 = new MyThread();
myThread.start();
myThread1.start();
}
}From below console, we are able to see the both thread executed 5times and creating new thread,but execution order is not maintained in jvm.order of execution is changed from highlighted log line.We can ensure that currently running thread to complete its action until we can hold theexecution of other thread by calling join()public class ThreadTester {
public static void main(String[] args) {
MyThread myThread = new MyThread();
MyThread myThread1 = new MyThread();
myThread.start();
try {
myThread.join(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
myThread1.start();
}
}Here I called myThread.join(mills), this will ensure that myThread is complete this actionand allows myThread1.start() to run.Below logs we can see Thread-0 is executed before Thread-1 start().