Syntax error on token “;”, { expected after this token in Random string creator

In Java, you cannot directly write the executable statements in class. You need to move your code in a method. Only variables declaration is allowed outside the method/blocks. Just for the sake of testing, ,move everthing to main method. Try this: Note: system.out.println(arrayList); will throw an error because there is no varaible called arrayList, i think it should … Read more

Sort ArrayList of custom Objects by property

Since Date implements Comparable, it has a compareTo method just like String does. So your custom Comparator could look like this: The compare() method must return an int, so you couldn’t directly return a boolean like you were planning to anyway. Your sorting code would be just about like you wrote: A slightly shorter way to write all this, if you don’t need to reuse your comparator, is to … Read more

How to synchronize or lock upon variables in Java?

That’s pretty easy: Note that I didn’t either make the methods themselves synchronized or synchronize on this. I firmly believe that it’s a good idea to only acquire locks on objects which only your code has access to, unless you’re deliberately exposing the lock. It makes it a lot easier to reassure yourself that nothing … Read more

How to import a jar in Eclipse

You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar. A quick demo here. The above solution is obviously a “Quick” one. However, if you are working on a project where you need … Read more

Deleting an object in java?

You should remove the references to it by assigning null or leaving the block where it was declared. After that, it will be automatically deleted by the garbage collector (not immediately, but eventually). Example 1: Example 2: Not something that you are currently looking for, but FYI: you can invoke the garbage collector with the … Read more

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