Postingan

Menampilkan postingan dengan label core java interview question

10 Differences between StringBuffer and StringBuilder in Java

Gambar
Both StringBuffer and StringBuilder are two important classes in Java which represents mutable String i.e. the String object, whose value can be changed. Since String is Immutable in Java, any change or operation on String object e.g. converting it to upper or lower case, adding character, removing a character, or getting a substring, all results in a new String object. This can put a lot of pressure on Garbage collector if your application generates lots of throws away String instances. To avoid this issue, Java designer presented initially StringBuffer class and later StringBuilder as mutable String. That's the main difference between String vs StringBuffer and StringBuilder and also one of the frequently asked Java questions for beginners. Anyway, when StringBuffer was introduced it has its own problem e.g. it was synchronized, methods like append have synchronized and hence they were slower. Even if you use them by just one thread and don't share with other threads, the cos...

Top 22 Spring Interview Questions Answers for Java JEE Developers

Gambar
Spring framework interview questions are on the rise on Java EE and core Java interviews Spring, which is obvious given Spring is the best framework available for Java application development and now Spring IOC container and Spring MVC framework are used as a de-facto framework for all new Java development. Because of its popularity,  interview questions from spring framework are top on any list of Core Java Interview questions. I thought to put together some spring interview questions and answers which have appeared on many Java and J2EE interviews and useful for practicing before appearing on any Java Job interview. I first wrote this article a long back and even its content is still relevant I thought to update it, especially after finishing my list of Spring Boot Interview Questions recently. This list of Spring interview questions and answers contains questions from Spring fundamentals e.g. Spring IOC and Dependency Injection, Spring MVC Framework , Spring Security, Spri...

Top 15 Java Multithreading, Concurrency Interview Questions Answers asked in Investment banks

Gambar
Multi-threading and concurrency questions are an essential part of any Java interview. If you are going for any Java interview on any Investment bank e.g. Barclays, Citibank, Morgan Stanley etc for Cash Equities Front Office Java Developer position, you can expect a lot of multi-threading interview questions on your way. Multi-threading and concurrency are favorite topics on Investment banking interviews,  especially on electronic trading development jobs and they grill candidate on many tricky java thread interview questions. They just want to ensure that the guy has solid knowledge of multi-threading and concurrent programming in Java because most of them are in the business of performance which provides them a competitive advantage and it's hard to write correct and robust concurrent code. For example, high volume and low latency Electronic Trading Systems which are used for Direct to Market (DMA) trading are usually concurrent in nature.  Most of the time the focus on micr...

Top 30 Java Phone Interview Questions Answers for Freshers, 1 to 2 Years Experienced

Gambar
Hello guys and ladies, in this article, I am sharing 30 core Java technical questions, from screening and phone round of interviews. In telephonic interviews, questions are short, fact-based and Interviewer expects a to-the-point reply and some keywords in answers. Accordingly, I have given very short answers of all these questions, only the main points; just to make this a revision post and not the main source for preparation. For thorough preparation, my master list of 140+ Java questions is a better one to start with. I am also expecting every Java programmer to know answers to all these Java technical questions if he has more than 4 to 5 years experience. It's only freshers and junior developers who need to do a bit of research to understand topics well. I have tried to include all classical and hugely popular, frequently asked questions from different topics like String, multi-threading, collection, design patterns, object-oriented concepts, garbage collection, generics, and a...

How to write a C like Sizeof function in Java?

Gambar
If you have just started learning Java and came from C background then you might have noticed some difference between Java and C programming language, e.g., String is an object in Java and not a NULL-terminated character array. Similarly, there is is no sizeof() operator in Java. All primitive values have predefined size, e.g., int is 4 bytes, char is 2 byte, short is 2 byte, long and float is 8 byte and so on. But if you are missing sizeOf operator then why not let's make it a coding task? If you are Ok, then your next job is to write a method in Java, which can behave like sizeOf() operator/function of C and returns the size in bytes for each primitive numeric types, i.e. all primitive types except boolean. Many of you think, why we are not including boolean? Isn't that it just need 1 bit to represent true and false value? Well, I am nog, including boolean in this exercise because the size of boolean is not strictly defined in Java specification and varies between different ...

What is happens-before in Java Concurrency? An example

Gambar
A couple of days ago, one of my readers messaged me on LinkedIn about a Java interview question he has recently faced - what is the happens-before relationship in Java concurrency? What is the benefit of it, and how exactly it works? He kind of has some ideas about that its related to the Java Memory Model and provides some sort of visibility guaranteed but couldn't explain with conviction to his interviewer, particularly with a code example and was a bit disappointed. He then asked me if I can write an article about it. I said you should have read the Java concurrency in Practice book before the interview, that would have helped, but nonetheless, I liked the idea to just provide a quick overview of what is the happens-before relationship between threads in Java. To understand the happens-before relationship, you need to first understand what problems can occur if the same variable is accessed by multiple threads? particularly if one thread writes into the variable, and one thr...

Top 15 Data Structures and Algorithm Interview Questions for Java Programmer - Answers

Gambar
Data structures and algorithm questions are an important part of any programming job interview, be it a Java interview, C++ interview or any other programming language. Since data structures are core programming concepts, it's mandatory for all programmers, to know basic data structures like the stack, linked list, queue, array, tree, and graph. Though trees and graphs are on the tougher side, I still see programmers get familiar will all these. Any list of programming job interview questions is incomplete without questions from data structures and algorithms. Similarly, while going on questions from data structure you may get some programming exercise as well e.g. swapping numbers without temp variable. The li nked list and array are favorite topics in any data structure interview, questions like reversing a linked list, traversing a linked list or deleting nodes from the linked list, which involves algorithm and data structures that are quite common. Similarly, finding duplicates...

Difference between Dependency Injection and Factory Design Pattern in Java Spring

Gambar
Learning a Programming language like Java or Python is easy, but writing production-quality code is difficult. Coding is as much art the Science behind it. To write good code, you need to carefully design your classes, their dependency, and how to use that. This is important so that it can survive the constant change throughout his lifetime. If you have been coding for some time, then you know that SOLID principles and Design Patterns help you to write better code. This is obvious because they are proven the solution to some common problems software developers face all around the world. But, knowing just the design pattern is not enough, you also need to learn using the right design pattern in the right place. In this article, we are going to look at two design patterns, the Factory pattern and Dependency Injection and learn the difference between them so that you can develop the coding sense for their effective use. Btw, if you are here to know the answer of dependency injection vs....

50+ Java Collection and Generics Interview Questions with Answers

Gambar
Hello guys, If you are preparing for Java interviews then you may know that Java Generics and Collections are two of the most important topics, particularly Generics where some of the trickiest Java questions can be asked. They are also used to gauge your experience and depth of your Java knowledge, hence it's imperative for both beginners and experienced Java programmers to prepare this topic well. While Java Collection framework provides an implementation of some command data structures like List, Set, Array, Hash table, Queue, Stack, PriorityQueue, etc, Generics provides Type safety. Generics was not part of the original Java release, in fact, it was introduced later at Java 5 release but since then it has become an integral part of Java code. I haven't written a single line of code where I have used Collections but not Generics. It's natural because Java has been promoting the use of generics and provides compile-time safety with common errors like storing string into...