Skip to main content

Posts

Showing posts with the label Java

could not calculate build plan plugin maven-compiler-plugin

could not calculate build plan plugin maven-compiler-plugin Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Solution: remove the following folder and then try to re-run the mvn command and it will work. rm -rf ~/.m2/repository/org/apache/maven/plugins/maven-*

HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException

HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException If you get following error while connecting to your Database with Spring boot, try the suggested solution below: 2018 - 11 - 25 15 : 28 : 50.078 INFO 5335 --- [ main] o. h . e . j . e . i . LobCreatorBuilderImpl : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java. lang . reflect . InvocationTargetException java. lang . reflect . InvocationTargetException : null at sun. reflect . NativeMethodAccessorImpl . invoke0 (Native Method) ~[na: 1.8 . 0 _161] at sun. reflect . NativeMethodAccessorImpl . invoke (NativeMethodAccessorImpl. java : 62 ) ~[na: 1.8 . 0 _161] at sun. reflect . DelegatingMethodAccessorImpl . invoke (DelegatingMethodAccessorImpl. java : 43 ) ~[na: 1.8 . 0 _161] at java. lang . reflect . Method . invoke (Method. java : 498 ) ~[na: 1.8 . 0 _161] at org. hibernate . engin...

Best way to compare time in Eclipse RCP

Best way to compare time in Eclipse RCP Disadvantage of Using Date for Time comparison: First of all let's understand why java.util.Date is not effective to just compare time. If you are using java.util.Date and add two different time and if it exceed beyond 24 hours, it will add 1 day to the java.util.Date. e.g. Date date1 = new Date( 0 , 0 , 0 , 20 , 59 , 59 ); System. out . println ( "Date 1: " +date1); Date date2 = new Date( 0 , 0 , 0 , 5 , 1 , 1 ); System. out . println ( "Date 2: " +date2); Date additionDate = new Date(date2. getTime ()); additionDate. setHours (date2. getHours ()+ date1. getHours ()); additionDate. setMinutes (date2. getMinutes ()+ date1. getMinutes ()); additionDate. setSeconds (date2. getSeconds ()+ date1. getSeconds ()); System. out . println ( "Addition: " +additionDate); Output: Date 1 : Sun Dec 31 20 : 59 : 59 IST 1899 Date 2 : Sun Dec 31 05 : 01 : 01 IST 1899 Addition: Mon Jan 01 0...

[Brainshare] Singleton Design pattern

What is Singleton Design Pattern: A class has only SINGLE instance and provide a global access to it. Usage of Singleton Design Pattern: https://stackoverflow.com/a/3192124/4955676 Type of Singleton Design Pattern: [code] Singleton Class - READ MORE [code] Lazy Initialization - READ MORE [code] Thread Safe - READ MORE Singleton Design Pattern Video Book

Eclipse collections

Eclipse collections Eclipse Collections is advance Java collection framework. It has some additional data structures and features which is not available in Java Collection Framework. Eclipse Collections provides memory efficient implementation of Sets and Maps as well as primitive collections. Maven Dependency: < dependency >   < groupId > org.eclipse.collections </ groupId >   < artifactId > eclipse-collections- api </ artifactId >   < version > 9.2.0 </ version > </ dependency > < dependency >   < groupId > org.eclipse.collections </ groupId >   < artifactId > eclipse-collections </ artifactId >   < version > 9.2.0 </ version > </ dependency > Comparison  with Java ArrayList ( JDK ) List <String> comparison = new ArrayList <String>(); comparison .add( "Bangalore" ); comparison .add...

Spring Boot read file on heroku

Spring Boot read file on heroku Spring Boot will fail with "getResource()" method to read the file in as on heroku it probably inside of a JAR file, which means it is not a regular file, and must be read as an input stream: MyService. class .getClassLoader()                 .getResource(" FILENAME.txt" ); As a solution the file has to be read with "getResourceAsStream()": MyService. class .getClassLoader()                 .getResourceAsStream(" FILENAME.txt" );

Arrays.asList() throws java.lang.UnsupportedOperationException

Arrays.asList() throws java.lang.UnsupportedOperationException You might get the UnsupportedException when you tries to use the add() method in the List. If your code looks something similar to this : String[] data = new String[] {"hari","krushna"}; List<String> asList = Arrays.asList(data); asList.add("test"); Then you will see the following exception : java.lang.UnsupportedOperationException at java.util.AbstractList.add(Unknown Source) at java.util.AbstractList.add(Unknown Source) at ArrayConvert.trial(ArrayConvert.java:14) at ArrayConvert.main(ArrayConvert.java:8) Solution of the above problem is :  you need to create an ArrayList or LinkedList and add the objects to the newly created Array/LinkedList: String[] data = new String[] {"","",""}; List<String> asList = Arrays.asList(data); List<String> newList = new LinkedList<>(asList); newList.add("test"); Rea...

Factory Design Pattern - Java

Factory Design Pattern Factory Design Pattern works as per it's name. As one Factory can generate various types of items but of a specific category. Like, Car Factory ( Nissan Car Factory ) can create cars like, Micra, Sunny, Evalia but it can't create Duster. Because,Duster can be created by Renault Car Factory. So, with the same concept, A company can create a various types of Employees. Like, Developer, Admin , Developer Manager. But, only Developer can be Dev Manager. Here is the Complete example of creating the Company with all the Employee details. Class Company.java /** * Parent Class of all Class. Employee is Base class of all types of Employee. * * @author Hari * */ abstract class Employee { public abstract void getMyDetails(); } /** * Admin is child class of the Employee class. * * @author Hari */ class Admin extends Employee { public void getMyDetails() { System.out.println("I'm admin"); } } /** * Develo...

Singleton Design Pattern in Java

Singleton Design Pattern Singleton Design Pattern means able to create only one object of the class. When you want to restrict some class from being created multiple objects, this design pattern is being used. First step of creating the class singleton is to make it's constructor private so other class can't call it anytime and create and object of it. Then create a static method "getInstance" which will return the object of the same class . Here its SingletonExampleClass . This method (getInstance) is created static , because this class has private constructor so we won't have it's object with us to access this class first time. Synchronized block is used stop multiple threads to access the instantiation code block at the same time, else it will be able to create multiple objects. now assume that two thread are there T1 and T2. Not Thread T1 access this method first and acquire the lock. While Thread T1 was accessing the code inside Synchronized bl...

FileNotFoundException in Java

There are three  reason,for this java.io.FileNotFoundException to be thrown at run-time and the reasons are follows: Reason1:    "If the given file is not available in the specified location then this error will occur". As you see,this is the most obvious reason for this exception as indicated by the Exception itself. Example: import java.io.*; public class Example1{ public static void main(String[] args){ FileReader reader = new FileReader("c:/javaInterviewExam.txt"); BufferedReader br = new BufferedReader(reader); String strcontent =null; while ((strcontent = br.readLine()) != null){ System.out.println(strcontent); } br.close(); } } In the above code during the execution of the line BufferedReader br=new BufferedReader(reader); if the file exam.txt is not found in the given location then the following error message will appear. Error message: java.io.FileNotFoundException: c:\ javaInterviewExam .txt (The s...

Cannot complete the install because one or more required items could not be found.

Error While installing Maven in Eclipse Cannot complete the install because one or more required items could not be found.   Software being installed: m2e - Maven Integration for Eclipse 1.4.0.20130601-0317 (org.eclipse.m2e.feature. feature.group 1.4.0.20130601-0317)   Missing requirement: Maven POM XML Editor 1.4.0.20130601-0317 (org.eclipse.m2e.editor.xml 1.4.0.20130601-0317) requires 'bundle org.slf4j.api 1.6.2' but it could not be found   Cannot satisfy dependency:     From: Maven Integration for Eclipse (Editors) 1.4.0.20130601-0317 (org.eclipse.m2e.editor 1.4.0.20130601-0317)     To: bundle org.eclipse.m2e.editor.xml [1.4.0,1.5.0)   Cannot satisfy dependency:     From: m2e - Maven Integration for Eclipse 1.4.0.20130601-0317 (org.eclipse.m2e.feature. feature.group 1.4.0.20130601-0317)     To: org.eclipse.m2e.editor [1.4.0.20130601-0317] Solution : 1. Goto : Help -> Install New Software 2. Ad...

How to read a file in Java ?

package com.file.read; import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; public class ReadFileInJava { public static void main(String[] args) { BufferedReader buffRead = null; try { String eachLine; buffRead = new BufferedReader(new FileReader("C:\\readfile.txt")); while ((eachLine = buffRead.readLine()) != null) { System.out.println(eachLine); } } catch (Exception e) { e.printStackTrace(); } finally { try { /* * close the BufferReader if there is any exception. */ if (buffRead != null)buffRead.close(); } catch (IOException ex) { ex.printStackTrace(); } } } }