what does Dead Code mean under Eclipse IDE Problems Section

In Eclipse, “dead code” is code that will never be executed. Usually it’s in a conditional branch that logically will never be entered. A trivial example would be the following: It’s not an error, because it’s still valid java, but it’s a useful warning, especially if the logical conditions are complex, and where it may … Read more

What does Scanner input = new Scanner(System.in) actually mean?

Alright, let’s elaborate with some simplified explanation about the Scanner class. It is a standard Oracle class which you can use by calling the import java.util.Scanner. So let’s make a basic example of the class: Now when you call Scanner input = new Scanner(System.in); you make a new object of the Scanner class (so you make a new “Scanner”) and you store … Read more

Convert .class to .java

Invoking javap to read the bytecode The javap command takes class-names without the .class extension. Try Converting .class files back to .java files javap will however not give you the implementations of the methods in java-syntax. It will at most give it to you in JVM bytecode format. To actually decompile (i.e., do the reverse of javac) you will have to use proper decompiler. See … Read more

What does .class mean in Java?

When you write .class after a class name, it references the class literal – java.lang.Class object that represents information about given class. For example, if your class is Print, then Print.class is an object that represents the class Print on runtime. It is the same object that is returned by the getClass() method of any (direct) instance of Print.

How do you make a deep copy of an object?

A safe way is to serialize the object, then deserialize. This ensures everything is a brand new reference. Here’s an article about how to do this efficiently. Caveats: It’s possible for classes to override serialization such that new instances are not created, e.g. for singletons. Also this of course doesn’t work if your classes aren’t Serializable.

Java compressing Strings

I need to create a method that receives a String and also returns a String. Ex input: AAABBBBCC Ex output: 3A4B2C Well, this is quite embarrassing and I couldn’t manage to do it on the interview that I had today ( I was applying for a Junior position ), now, trying at home I made … Read more

How to master Java?

I think most programmers have about average college graduate intelligence, including myself. What we do have a lot of though is patience. That said, there are efficient ways to learn and inefficient ways to learn. If you’re stuck on one tutorial/book, try another book. Once you’re done with the basics, there really is no “correct” … Read more

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