`
cywhoyi
  • 浏览: 418188 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Core Java Interview Questions Answers in Finance domain Read more: http://javar

 
阅读更多
1. What is immutable object? Can you write immutable object?
top core java interview questions
Immutable classes are Java classes whose objects can not be modified once created. Any modification in Immutable object result in new object. For example is String is immutable in Java. Mostly Immutable are also final in Java, in order to prevent sub class from overriding methods in Java which can compromise Immutability. 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() Operator, 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 PermGen area of heap.
 

String s = new String("Test");
 

does not  put the object in String pool , we need to call String.intern() method which is used to put  them into String pool explicitly. its only when you create String object as String literal e.g. String s = "Test" Java automatically put that into String pool.

 
4. How does substring () inside String works?
Another good Java interview question, I think answer is not sufficient but here it is “Substring creates new object out of source string by taking a portion of original string”. see my post How SubString works in Java for detailed answer of this Java question.
 

 

 
5. Which two method you need to implement for key Object in HashMap ?
In order to use any object as Key in HashMap, it must implements equals and hashcode method in Java. Read How HashMap works in Java for detailed explanation on how equals and hashcode method is used to put and get object from HashMap. You can also see my post 5 tips to correctly override equals in Java to learn more about equals.
 
6. Where does these  two method comes in picture during get operation?
This core Java interview question is follow-up of previous Java question and candidate should know that once you mention hashCode, people are most likely ask How its used in HashMap. See 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?
This is one of the tough Java interview question and its open for all, my friend didn't know the answer so he didn't mind telling me. my take is that stored procedure should return error code if some operation fails but if stored procedure itself fail than catching SQLException is only choice.
 
8. What is difference between Executor.submit() and Executer.execute() method ?
This Java interview question is from my list of Top 15 Java multi-threading question answers, Its getting popular day by day because of huge demand of Java developer with good concurrency skill. Answer of this Java interview question is that former returns an object of Future which can be used to find result from worker thread)
 
By the way @vinit Saini suggested 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 exception 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 re-throw this exception, wrapped in an ExecutionException.

 

 
9. What is the difference between factory and abstract factory pattern?
This Java interview question is from my list of 20 Java design pattern interview question and its open for all of you to 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 AutomobileFactoryUserFactoryRoleFactory etc. Each individual factory would be responsible for creation of objects in that genre.
You can also refer What is Factory method design pattern in Java to know more details.
 
10. What is Singleton? is it better to make whole method synchronized or only critical section synchronized ?
Singleton in Java is a class with just one instance in whole Java application, for example java.lang.Runtime is a Singleton class. Creating Singleton was tricky prior Java 4 but once Java 5 introduced Enum its very easy. see my article How to create thread-safe Singleton in Java for more details on writing Singleton using enum and double checked locking which is purpose of this Javainterview question.
 
 
11. Can you write critical section code for singleton?
This core Java question is followup of previous question and expecting candidate to write Java singleton using double checked locking. Remember to use volatile variable to make Singleton thread-safe. check 10 Interview questions on Singleton Pattern in Java for more details and questions answers


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



 
Recommended Books to prepare Java Interviews
Apart from blogs and articles, you can also take help of some books, which are especially written to help with programming interviews, covering wide range of questions starting from object oriented design, coding,  Java basic concepts, networking, database, SQL, XML and problem solving skills. Following books are from my personal collection, which I often used to revise before going for any interview.



Read more: http://javarevisited.blogspot.com/2011/04/top-20-core-java-interview-questions.html#ixzz2fsjk9vby

分享到:
评论

相关推荐

    Top 20 Core Java Interview Questions and Answers

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

    opencv-4.7.0-android-sdk.zip

    previous forum (read only): http://answers.opencv.org Issue tracking: https://github.com/opencv/opencv/issues Additional OpenCV functionality: https://github.com/opencv/opencv_contrib

    opencv-4.7.0-ios-framework.zip

    previous forum (read only): http://answers.opencv.org Issue tracking: https://github.com/opencv/opencv/issues Additional OpenCV functionality: https://github.com/opencv/opencv_contrib

    C++ interview questions and answers

    根据提供的文件信息,本文将对其中涉及的C++面试题目进行详细解析,并提供相应的答案,旨在帮助准备参加C++职位面试的求职者更好地理解和掌握相关的技术要点。 ### 1. C++基础知识 #### 1.1 什么是C++?...

    java interview questions Top 20 java interview programs and answers.2017

    本书《Java Coding Interview》旨在帮助读者在面试过程中取得优异的成绩,传授给求职者必要的面试准备知识。作者有着指导和面试过数百名软件工程师的经验,本书的面试题目是真实的,不仅来自于真实公司的面试问题,...

    interview questions 12 with answers.pdf

    ### IT面试问题与答案解析 #### 1. 如何描述自己? **优秀示例回答:** 我的背景至今一直围绕着成为一名最优秀的财务顾问而努力。让我具体介绍一下我是如何准备自己的。我是一名在______大学主修金融和会计的本科...

    115-Java-Interview-Questions-and-Answers, 115 Java访谈问题和答案- 终极列表.zip

    115-Java-Interview-Questions-and-Answers, 115 Java访谈问题和答案- 终极列表 #115-Java-Interview-Questions-and-Answers我们将讨论关于Java面试中可以使用的各种问题,以便雇主在Java和面向对象编程方面测试你的...

    Java并发编程面试题--共87题

    不管你是新程序员还是...注:本文档根据http://www.importnew.com/12773.html 和http://ifeve.com/java-multi-threading-concurrency-interview-questions-with-answers/ 这两个网站的并发编程试题集整理得到的文档,

    15 Toughest Interview Questions and Answers

    根据提供的文件信息,我们可以从中提炼出三个重要的面试问题及其回答策略。这不仅是对求职者面试技巧的考验,也是展示个人专业素养与职业态度的关键时刻。接下来,我们将详细解析这三个问题及如何给出恰当的回答。...

    面试宝典(Haldane's Best Answers to Tough Interview Questions)

    Haldane's Best Answers to Tough Interview Questions 面试常见问题应对

    Java-Interview-Questions-and-Answers

    ### Java Interview Questions and Answers #### 1. 什么是 Java?解释其含义与定义。 Java 是当今最流行的编程语言之一,在 Web 应用程序、移动应用、软件开发、游戏系统以及服务器端技术等领域扮演着重要角色。...

    SAP+SD+Interview+Questions+Answers+and+Explanations

    4. **订单创建时弹出窗口(Popup in Order Creation)** 5. **比例价格条件(Scale Price Condition)** 6. **VPRS未复制到开票文档(VPRS Not Copied to Billing Document)** 7. **交付单中的序列号(Serial Numbers in ...

    linux libxml2-2.6.26

    All technical answers asked privately will be automatically answered on the list and archived for public access unless pricacy is explicitely required and justified. Daniel Veillard $Id: README,v ...

    sap-basis-certification-questions-sap-basis-interview-questions-answers-and-explanations

    SAP Basis Interview Questions 在进行 SAP Basis 的面试准备时,面试官通常会关注应聘者对 SAP Basis 的基础知识和实践经验的理解。例如: - **问题示例**:“请简要介绍 SAP Basis 并解释它的主要功能。” - **...

    Java-Spring-Boot-Interview-Questions-and-Answers:最受欢迎的Java面试问答

    本资料“Java-Spring-Boot-Interview-Questions-and-Answers”集合了最受欢迎的Java及Spring Boot面试问题,帮助求职者准备相关面试。 一、Java基础 1. 讲解Java内存模型(JVM)的结构,包括堆内存、栈内存、方法区...

    SQL Interview Questions with Answers

    ### SQL面试题与解答知识点详解 #### 一、关系型数据库管理系统(RDBMS) **定义:** 关系型数据库管理系统(Relational Database Management System,简称RDBMS)是一种用于存储和管理数据的软件系统,它将数据...

    Java_Interview_Questions.zip_answers

    本压缩包"Java_Interview_Questions.zip_answers"包含了针对Java面试的一系列问题和答案,旨在帮助准备面试的开发者深入理解Java的核心概念和技术。 1. **基础概念** - **Java是什么?** Java是一种广泛使用的面向...

    mean_questions:MEAN堆栈问答应用

    平均问题(和答案) 今天,我们将首次体验MEAN堆栈:猫鼬,Express,Angular,Node。 我们已经完成了服务器端Mongo / Express / Node和客户端Angular。.../api/questions/:questionId/answers/:id 更新

    Chegg-Discord-BOT-main_chegg_源码

    【描述】"chegg discord bot free cheg hack answers" 描述了这个机器人的一项功能,即免费获取Chegg上的答案。"hack"在这里可能是指通过非官方或非正常途径获取信息,但请注意,任何未经授权的破解行为都违反Chegg...

Global site tag (gtag.js) - Google Analytics