`

Top 20 Core Java Interview questions asked in Investment Bank

    博客分类:
  • Java
阅读更多

Top 20 Core Java Interview questions asked in Investment Bank


This is a new series of sharing core Java interview question on Finance domain and mostly on Big Investment bank. Anybody who is preparing for any Java developer Interview on any Investment bank can be benefited from these set of core Java Interview questions. I have collected these questions from my friends and I thought to share with you all.  I hope this will be helpful for both of us. Please share answers for unanswered question and let us know how good these interview questions are.


Recently I was looking at comments made on java interview questions given in this post and I found some of them quite useful to include into main post to benefit all.

Core Java Interview Questions Answers in Finance domain

1. What is immutable object? Can you write immutable object?
top core java interview questions
You need to make class final and all its member final so that once objects gets crated no one can modify its state. You can achieve same functionality by making member as non final but private and not modifying them except in constructor.

2. Does all property of immutable object needs to be final?
Not necessary as stated above you can achieve same functionality by making member as non final but private and not modifying them except in constructor.

3. What is the difference between creating String as new () and literal?
When we create string with new () it’s created in heap and not added into string pool while String created using literal are created in String pool itself which exists in Perm area of heap.


String s = new String("Test");
will put the object in String pool , it it does then why do one need String.intern() method which is used to put Strings into String pool explicitly. its only when you create String object as String literal e.g. String s = "Test" it put the String in pool.


4. How does substring () inside String works?
Another good question, I think answer is not sufficient but here it is “Substring creates new object out of string by taking a portion of original string”.


suggested by Anand and Anonymous


The substring() method is used to return a part (or substring) of the String used to invoke the method. The first argument represents the starting location (zero-based) of the substring. If the call has only one argument, the substring returned will include the characters to the end of the original String. If the call has two arguments, the substring returned will end with the character located in the nth position of the original String where n is the second argument. Unfortunately, the ending argument is not zero-based, so if the second argument is 7, the last character in the returned String will be in the original String’s 7 position, which is index 6. Let’s look at an example:
String x = "0123456789";

System.out.println( x.substring(5) ); // output is "56789"
System.out.println( x.substring(5, 8)); // output is "567"

The first example should be easy: start at index 5 and return the rest of the String. The second example should be read as follows: start at index 5 and return the characters up to and including the 8th position (index 7).



and @Anonymous pointed out some interesting fact:
omething important about String.substring() method, its implementation calls the following String(...) constructor :

// Package private constructor which shares value array for speed.
String(int offset, int count, char value[]) {
this.value = value;
this.offset = offset;
this.count = count;
}

That means the new String() object returned by substring(...) shares the same backing array (this.value) as the original string object.

Thus if your original string object is 1GB long, the substring object will always be 1GB long too!

You will probably want to trim the new array size to the substring range, this should do the job:

String veryLongString = readFromFile(file);
String tinyString = new String(veryLongString.substring(1,10));

The String(String) constructor is implemented that way:

public String(String original) {
...
if (originalValue.length > size) {
// The array representing the String is bigger than the new
// String itself. Perhaps this constructor is being called
// in order to trim the baggage, so make a copy of the array.
int off = original.offset;
v = Arrays.copyOfRange(originalValue, off, off+size);
}
...
}



5. Which two method you need to implement for key in hashMap ?
(equals and hashcode) read How HashMap works in Java for detailed explanation.

6. Where does these  two method comes in picture during get operation?
See here  How HashMap works in Java for detailed explanation.

7. How do you handle error condition while writing stored procedure or accessing stored procedure from java?
Open for all, my friend didn't know the answer so he didn't mind telling me.

8. What is difference between Executor.submit() and Executer.execute() method ?
(Former returns an object of Future which can be used to find result from worker thread)


@vinit Saini suggesed a very good point related to this core java interview question


There is a difference when looking at exception handling. If your tasks throws an exception and if it was submitted with execute this exception will go to the uncaught exception handler (when you don't have provided one explicitly, the default one will just print the stack trace to System.err). If you submitted the task with submit any thrown exception, checked or not, is then part of the task's return status. For a task that was submitted with submit and that terminates with an exception, the Future.get will rethrow this exception, wrapped in an ExecutionException.

9. What is the difference between factory and abstract factory pattern?
Open for all, he explains about factory pattern and how factory pattern saves maintenance time by encapsulating logic of object creation but didn't know exact answer


@Raj suggested
Abstract Factory provides one more level of abstraction. Consider different factories each extended from an Abstract Factory and responsible for creation of different hierarchies of objects based on the type of factory. E.g. AbstractFactory extended by AutomobileFactory, UserFactory, RoleFactory etc. Each individual factory would be responsible for creation of objects in that genre.


10. What is Singleton? is it better to make whole method synchronized or only critical section synchronized ?
see my article 10 Interview questions on Singleton Pattern in Java

11. Can you write Critical section code for singleton?
check here  10 Interview questions on Singleton Pattern in Java

12. Can you write code for iterating over hashmap in Java 4 and Java 5 ?
core java interview questions and answers beginners
Tricky one but he managed to write using while and for loop.

13. When do you override hashcode and equals() ?
Whenever necessary especially if you want to do equality check or want to use your object as key in HashMap. check this for writing equals method correctly 5 tips on equals in Java

14. What will be the problem if you don't override hashcode() method ?
You will not be able to recover your object from hash Map if that is used as key in HashMap.
See here  How HashMap works in Java for detailed explanation.

15. Is it better to synchronize critical section of getInstance() method or whole getInstance() method ?
Answer is critical section because if we lock whole method than every time some one call this method will have to wait even though we are not creating any object)

16. What is the difference when String is gets created using literal or new() operator ?
When we create string with new() its created in heap and not added into string pool while String created using literal are created in String pool itself which exists in Perm area of heap.

17. Does not overriding hashcode() method has any performance implication ?
This is a good question and open to all , as per my knowledge a poor hashcode function will result in frequent collision in HashMap which eventually increase time for adding an object into Hash Map.

18. What’s wrong using HashMap in multithreaded environment? When get() method go to infinite loop ?
Another good question. His answer was during concurrent access and re-sizing.


19. Give a simplest way to find out the time a method takes for execution without using any profiling tool?
this questions is suggested by @Mohit
Read the system time just before the method is invoked and immediately after method returns. Take the time difference, which will give you the time taken by a method for execution.

To put it in code…

long start = System.currentTimeMillis ();
method ();
long end = System.currentTimeMillis ();

System.out.println (“Time taken for execution is ” + (end – start));

Remember that if the time taken for execution is too small, it might show that it is taking zero milliseconds for execution. Try it on a method which is big enough, in the sense the one which is doing considerable amout of processing


Read more: http://javarevisited.blogspot.com/2011/04/top-20-core-java-interview-questions.html#ixzz1sqNahoza
分享到:
评论

相关推荐

    Top 20 Core Java Interview Questions and Answers

    从国外网站上下载的Java面试题。可以看看国外公司的Java面试常用题,以及如何用英文回答。

    Interview Questions in Core Java

    Interview Questions in Core Java 1.what is a transient variable? A transient variable is a variable that may not be serialized.

    Core-Java-Interview-Questions.rar_core java interview

    "Core Java Interview Questions"这个资源集锦了面试中可能会遇到的一些关键问题,旨在帮助求职者更好地准备Java核心技术的面试。以下是根据描述和标签提炼出的一些核心Java知识点: 1. **Java基础** - 类与对象:...

    Core Java Interview Question Page 1.doc

    Core Java Interview Question Page 1

    CoreJava_Bank

    《CoreJava_Bank》项目是基于Java核心技术实现的一个银行管理系统的示例,它模拟了自动取款机(ATM)的存取款功能,并涵盖了银行系统的一些基础操作。这个项目旨在帮助开发者熟悉Java编程语言,了解面向对象设计原则...

    Android代码-Android Interview Questions

    Android Interview Questions > Android Interview Questions - Your Cheat Sheet For Android Interview We will be adding answers to the more questions on our MindOrks website. Prepared and maintained ...

    Core Java Interview

    这本书名为《Core Java Interview》,其内容是关于Java面试的,英文版本,是一本适合想要面试Java职位的求职者的实用指南。它由Sam Atkinson撰写,并在Leanpub网站上出售,于2016年5月21日发布。Leanpub是一种轻量级...

    Java.Interview.Guide.How.to.Build.Confidence.With.pdf

    Java.Interview.Guide.How.to.Build.Confidence.With.a.Solid.Understanding.of.Core.Java.Principles.B015HF9SJQ.pdf Java.Interview.Guide.How.to.Build.Confidence.With.a.Solid.Understanding.of.Core.Java....

    CoreJava全套详细笔记资料.pdf

    CoreJava全套详细笔记资料.pdf CoreJava是Java编程语言的核心部分,涵盖了Java语言的基础知识和高级应用。以下是对给定文件的详细解读和知识点总结: 一、原码、反码、补码 * 原码是指一个数的二进制表示形式,...

    达内Java培训-CoreJava全程笔记(WORD唐亮版)

    CoreJava DAY01 Java概述 1 CoreJava DAY02 数据类型和控制结构 6 CoreJava DAY03 数组 11 CoreJava DAY04 15 CoreJava DAY05 面向对象 17 CoreJava DAY06 类的加载过程、实例化、继承、多态 20 CoreJava DAY07修饰...

    core_java_career_essentials.pdf

    If you have a java interview coming up in a few days or you want to impress your peers and superiors with your technical strengths during code review sessions, team meetings, and stand-ups, and ...

    Core Java

    【Core Java】是Java编程的基础教程,主要涵盖了Java语言的核心概念和使用方法。在学习Core Java时,首先要理解以下几个关键知识点: 1. **类与对象**:类是面向对象编程的基础,是描述某一类事物共性的抽象,而...

    达内 CoreJava老师笔记汇总

    CoreJava DAY03 数组 20 CoreJava DAY04 27 CoreJava DAY05 面向对象 31 CoreJava DAY06 类的加载过程、实例化、继承、多态 37 CoreJava DAY07修饰符 50 CoreJava DAY08 常用类 56 CoreJava DAY09 高级语言特征 58 ...

    java\CoreJava笔记\CoreJAVA_day01

    CoreJava是Java的基础,涵盖了Java Standard Edition (J2SE)的主要内容,包括基本语法、面向对象编程(OO)原则、核心类库的使用等。在学习CoreJava时,我们需要掌握以下几个关键知识点: 1. **编程思想**: - ...

    Java 核心技术 第八版-第1和2卷+源代码【Core Java 8th Edition】

    Java 核心技术 第八版-第1和2卷+源代码【Core Java 8th Edition】内附资源: Core Java. Volume I. Fundamentals, 8th Edition.pdf ; Core Java. Volume II. Advanced Features, 8th Edition.chm ; Core Java 8th ...

    Core Java Volume II Advanced Features__10th edition

    Now, Core Java®, Volume II—Advanced Features, Tenth Edition, has been extensively updated to reflect the most eagerly awaited and innovative version of Java in years: Java SE 8. Rewritten and ...

    Core Java.JAVA核心技术(中文版)

    《Core Java.JAVA核心技术(中文版)》是学习Java编程的重要参考资料,主要涵盖了Java语言的基础以及进阶知识。这本书深入浅出地讲解了Java的核心概念和技术,为读者提供了全面而细致的学习路径。以下是对该书内容的...

    Core Java( Java 核心) PDF 教材

    《Core Java》是由Sun Microsystems公司出版的一本权威的Java编程教材,它全面深入地介绍了Java语言的核心概念和技术。这本书是Java开发者的重要参考资料,对于初学者和有经验的开发者都具有很高的学习价值。以下是...

Global site tag (gtag.js) - Google Analytics