Learn Java and Programming through articles, code examples, and tutorials for developers of all levels.
Thursday, April 25, 2024
Top 21 jQuery interview Questions and Answers
Sunday, April 14, 2024
Top 21 Maven Interview Questions Answers for Java Developers
Hello guys, for a Java developer, Maven in one of the essential tool and its used to build your Java application. Since most of the Java projects used Maven for building, it is expected from a Java developer that he knows Maven and knows it well. That's why Maven questions are quite common on Java developer interviews but I have seen many Java programmers coming to these interview unprepared and not able to answer most of the questions on tools like Maven, Gradle or even git. When I asked one candidate why don't you prepare for Maven before your Java interviews, he said, I wasn't able to find any list of Maven questions.
Thursday, April 11, 2024
How String concatenation works in Java?
You can concatenate multiple String using + operator in Java. Even though Java doesn't support operator overloading, + operator is special, it performs addition if given operands are numeric and does String concatenation if one of them is String. Why it's important to know how String concatenation works? Well, more often that you can live without this knowledge but if you want to master Java then why not know little more detail. Apart from that it also helps you to avoid a performance mistake, which many Java devleoper do, concatenating String inside loop. When you concate two String literal e.g. "abc" + "cde" then compiler do this concatenation at compile time and this doesn't involve StringBuilder.
Concatenating two String literal
Concatenating String literal and String variable.
Things to remember:
1) Don't concatenate String in loop because Java creates a new StringBuilder() every iteration.
2) If two String literal are concatenated i.e. "Java" + "Script" then it happens at compilation time
2) When you concatenate a String literal and a String object, or two String object then it happens at runtime.
That's all about how String concatenation works in Java.