Java SimpleDateFormat for YYYY-MM-DDThh:mm:ssTZD
Use JodaTime’s DateTimeFormat API with “yyyy-MM-dd’T’HH:mm:ssZ” date pattern
Use JodaTime’s DateTimeFormat API with “yyyy-MM-dd’T’HH:mm:ssZ” date pattern
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
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
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
Use StringBuilder class. It is more efficient at what you are trying to do.
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.
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.
The language specification is where null is defined, and it says There is also a special null type, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null … Read more
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
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