- 浏览: 183319 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
枫了的红叶儿:
事务与存储过程的区别 -
黄进宝与wys:
...
Mysql事务处理 -
youshenxuzuo:
您好, 我有个问题想请教一下。关于start方法启动线程,自动 ...
java thread: run方法和john方法 -
Leisurez:
[i][u]引用[list]
[*]
[/list][/u][ ...
Hibernate的查询方式 -
Leisurez:
[flash=200,200][/flash]
Hibernate的查询方式
1. What is immutable object? Can you write immutable object?
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 ?
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
发表评论
-
Java transient 关键字
2012-02-03 10:09 5641、transient关键字只能修饰变量,而不能修饰方法和类。 ... -
Java 序列化的问题
2012-01-17 17:39 1150【本文为转载,以做备忘,对其中的例子做了修改,原文地址:htt ... -
Java的参数传递
2012-01-16 11:41 1011有人说java 参数传递在对primitive类型的参 ... -
Java 异常知识点
2012-01-12 17:00 1942一、异常的继承结构 Java异常的基类为java ... -
java thread: run方法和john方法
2012-01-11 11:33 41531、要实现多线程 ... -
java 格式化输出 printf 总结
2012-01-09 18:17 24763通过一个具体实例说明: double d = 345.67 ... -
scjp 知识点
2012-01-05 22:03 961标识符 □标识 ... -
JAVA枚举类型入门
2011-05-20 09:41 991Java 代码的两个基本的构造块是类 和接口。 ... -
JAVA中的方法覆盖/覆写的十大原则
2011-05-19 14:32 4437什么是方法覆盖 如果在子类中定义的一个方法,其名称、返 ... -
Java Map 遍历方法
2011-04-26 16:34 902第一种: Map map = new HashMap ... -
【转】程序员必知:Java代码常见的十种错误(2)
2011-03-10 15:52 1075六、常见错误6:检查new 操作的结果是否为null ... -
【转】程序员必知:Java代码常见的十种错误(1)
2011-03-10 15:48 1027【IT168 技术】每一个程序员在编写代码的过程中都免不了 ... -
Java基础知识是刨根问底
2011-02-25 16:26 10531、类A实现了接口I,A能否改变I中定义的变量? 2、 ... -
Java编程题汇总备忘
2011-02-15 22:30 15901.从键盘输入一组数(用,分割),排序后输出 【分析】使用S ... -
JDK1.5/1.6新特性总结
2011-02-14 12:39 1224一、JDK1.5新特性 1、泛型(Generic) 可以在编 ... -
XML知识点备忘
2011-01-22 10:58 13211.xml名称空间通过一系 ... -
JDBC连接数据库的完整步骤
2011-01-22 00:13 8195JAVA连接数据库的方式有多种,根据所需要的不同数据库驱动分, ... -
Java IO 知识点备忘
2011-01-21 14:16 10271. java io 库采用Decorator设计模式 2. ... -
Java 试题备忘
2011-01-18 15:36 9101. Given the following class de ... -
java基础知识备忘拾遗
2011-01-17 23:21 1298一、接口 1.接口中的方法默认都是public和abstra ...
相关推荐
从国外网站上下载的Java面试题。可以看看国外公司的Java面试常用题,以及如何用英文回答。
本书《Java Coding Interview》旨在帮助读者在面试过程中取得优异的成绩,传授给求职者必要的面试准备知识。作者有着指导和面试过数百名软件工程师的经验,本书的面试题目是真实的,不仅来自于真实公司的面试问题,...
### IT面试问题与答案解析 #### 1. 如何描述自己? **优秀示例回答:** 我的背景至今一直围绕着成为一名最优秀的财务顾问而努力。让我具体介绍一下我是如何准备自己的。我是一名在______大学主修金融和会计的本科...
根据提供的文件信息,我们可以从中提炼出三个重要的面试问题及其回答策略。这不仅是对求职者面试技巧的考验,也是展示个人专业素养与职业态度的关键时刻。接下来,我们将详细解析这三个问题及如何给出恰当的回答。...
Haldane's Best Answers to Tough Interview Questions 面试常见问题应对
根据提供的文件信息,本文将对其中涉及的C++面试题目进行详细解析,并提供相应的答案,旨在帮助准备参加C++职位面试的求职者更好地理解和掌握相关的技术要点。 ### 1. C++基础知识 #### 1.1 什么是C++?...
### Java Interview Questions and Answers #### 1. 什么是 Java?解释其含义与定义。 Java 是当今最流行的编程语言之一,在 Web 应用程序、移动应用、软件开发、游戏系统以及服务器端技术等领域扮演着重要角色。...
一本介绍面试C程序员时的问题及解答的书籍。
4. **订单创建时弹出窗口(Popup in Order Creation)** 5. **比例价格条件(Scale Price Condition)** 6. **VPRS未复制到开票文档(VPRS Not Copied to Billing Document)** 7. **交付单中的序列号(Serial Numbers in ...
CISA Interview Questions and Answers学习文档手册.pdf
### SQL面试题与解答知识点详解 #### 一、关系型数据库管理系统(RDBMS) **定义:** 关系型数据库管理系统(Relational Database Management System,简称RDBMS)是一种用于存储和管理数据的软件系统,它将数据...
SAP ABAP Certification Review SAP ABAP Interview Questions, Answers, And Explanations.pdf
devops interview questions by tech interviews get it for devops interview
Vue.js 面试题和答案 Vue.js 是一个基于 Model-View-ViewModel(MVVM)的前端框架,广泛应用于-web 应用程序的开发。以下是 Vue.js 面试题和答案,涵盖了 Vue.js 的基础知识、组件通信、数据流、指令、生命周期等几...
本文将详细解析面向对象编程中的四大核心概念——抽象(Abstraction)、封装(Encapsulation)、继承(Inheritance)以及多态(Polymorphism),并探讨这些概念如何应用于Java语言中。 #### 抽象(Abstraction) *...
SAP Basis Interview Questions 在进行 SAP Basis 的面试准备时,面试官通常会关注应聘者对 SAP Basis 的基础知识和实践经验的理解。例如: - **问题示例**:“请简要介绍 SAP Basis 并解释它的主要功能。” - **...
This book covers useful Interview Questions and Answers on ASP.NET MVC. This book is appropriate for novice as well as for senior level professionals who wants to strengthen their skills before ...
本压缩包"Java_Interview_Questions.zip_answers"包含了针对Java面试的一系列问题和答案,旨在帮助准备面试的开发者深入理解Java的核心概念和技术。 1. **基础概念** - **Java是什么?** Java是一种广泛使用的面向...
115-Java-Interview-Questions-and-Answers, 115 Java访谈问题和答案- 终极列表 #115-Java-Interview-Questions-and-Answers我们将讨论关于Java面试中可以使用的各种问题,以便雇主在Java和面向对象编程方面测试你的...