Java Using Nodes with LinkedList

You don’t actually need a separate LinkedList class; the ListNode class is a linked list. Or, to state it differently, a reference to the head of the list is a reference to the list. The use of head, tail, current, prev in the sample code you posted has come from a double-linked list which is a data … Read more

How do I use a PriorityQueue?

Use the constructor overload which takes a Comparator<? super E> comparator and pass in a comparator which compares in the appropriate way for your sort order. If you give an example of how you want to sort, we can provide some sample code to implement the comparator if you’re not sure. (It’s pretty straightforward though.) As has … Read more

com.atomikos.icatch.SysException: Error in init: Log already in use? tmlog in ./

I have a very big problem with my atomikos. I cant create bean because of below error: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘authenticatingSignInAdapter’: Unsatisfied dependency expressed through field ‘userRepoAutowired’: Error creating bean with name ‘userRepo’: Invocation of init method failed; nested exception is com.atomikos.icatch.SysException: Error in init: Log already in use? tmlog in ./; … Read more

Understanding Spring @Autowired usage

TL;DR The @Autowired annotation spares you the need to do the wiring by yourself in the XML file (or any other way) and just finds for you what needs to be injected where and does that for you. Full explanation The @Autowired annotation allows you to skip configurations elsewhere of what to inject and just does it for you. … Read more

Round a double to 2 decimal places

Here’s an utility that rounds (instead of truncating) a double to specified number of decimal places. For example: Original version; watch out with this This breaks down badly in corner cases with either a very high number of decimal places (e.g. round(1000.0d, 17)) or large integer part (e.g. round(90080070060.1d, 9)). Thanks to Sloin for pointing this out. I’ve been using the above to round … Read more

A long bigger than Long.MAX_VALUE

That method can’t return true. That’s the point of Long.MAX_VALUE. It would be really confusing if its name were… false. Then it should be just called Long.SOME_FAIRLY_LARGE_VALUE and have literally zero reasonable uses. Just use Android’s isUserAGoat, or you may roll your own function that always returns false. Note that a long in memory takes a fixed number of bytes. From Oracle: long: The long data type is a … Read more

A JNI error has occurred, please check your installation and try again in Eclipse x86 Windows 8.1

Short answer: Right-click on the class that contains the main method. Click on “Run As”. Click on “Java Application”. The keyboard shortcut is: Shift+Alt+X J (while holding Shift and Alt, press X; then release Shift and Alt and press J). Long answer: To be honest, I am not 100% sure why this problem happens. It might be … Read more

“Missing return statement” within if / for / while

If you put a return statement in the if, while or for statement then it may or may not return a value. If it will not go inside these statements then also that method should return some value (that could be null). To ensure that, compiler will force you to write this return statement which is after if, while or for. But if you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)