当前位置:文档之家› 【java 专业】最全 JAVA面试题

【java 专业】最全 JAVA面试题

【java 专业】最全 JAVA面试题
【java 专业】最全 JAVA面试题

【Java面试的难题】

日前在一家公司面试,题目范围出的比较广,多数题目答不上来,因此把面试题抄录下来,向大家求解!难题如下:

1、freemark中,怎样判断一个参数的值是否为null?叙述你在用Freemark过程中遇到一些问题及解决方法。

2、Hibernate 3.0 中,执行"from persion p where https://www.doczj.com/doc/146852706.html, = "上海""时候,上海这条hsql转成sql时变成乱码,数据库字符集是utf-8,请问如何解决。

3、简述uml时序图和状态图的概念及它们的侧重点。

4、简述关联、聚合以及组合的概念,说明在uml中的图形和区别。

5、你最喜欢的软件架构是什么?详细说明这个架构的优点,缺点,最好有架构图例说明。

6、Linux中,查找/tmp/sure目录下,且包含password字符的所有文件,并删除它们。

7、Linux,test.txt文件中有多条记录,找出这个文件中没有重复行的记录。

【群硕笔试题(java,c++)】

群硕的笔试在语言方面主要是Java和C++,夹了一道C#题,趁记忆犹新的时候记下来

一、给了一棵二叉树的前序遍历和中序遍历,要求写出后序遍历。

看一下数据结构就行了,很easy。提示:前序遍历的第一个节点为根结点,在中序遍历中根结点的左边节点是左子树,右边节点是右子树,如此递归。

二、什么是物理内存和虚拟内存,OS中为什么要使用虚拟内存?

看OS的书。

三、解释一下C#中的“delegate”。

原先不清楚的,然后在技术面试的时候问了一下面试官,原来类似于一个队列,队列中存的是函数指针(托管函数),运行时队列中的函数会在一个线程中被依次执行。

四、与子程序传递参数有哪些方法?

汇编题,我想起来三个:参数压栈、参数存寄存器、参数存数据段。

五、解释一下Java中的String和StringBuffer,什么时候需要使用StringBuffer?

核心是String对象是不变对象,连接、取子串等操作会生成新的对象,旧对象可能会被回收。StringBuufer则是可变对象,上述操作将在原对象上进行。

六、Java中哪些容器的默认布局器(layout)是BorderLayout?

这个不是那得很准,就写了JFrame及其子类,Frame及其子类。

七、一个C++的函数:

int operation(int numberA,int numberB){

return numberA + numberB;

}

然后声明了三个变量:

int a = 2;

int result1 = operation(5, a++);

int result2 = operation(5+a, ++a);

问result1和result2的值。

原先以为考得是传值、传引用的问题,结果仔细一看考得是a++和++a的问题,这就简单了。

result1 = 7, result2 = 12

八、如果父类的析构函数没有声明为虚函数的话在父类的指针上调用析构函数会有什么后果?

屏蔽多态,子类申请的资源将不被释放。

九、定义了一个类:

class Something{

pulic:

Something();

void setValue(int val){

value = val;

}

private:

int value;

}

以及一个函数:

void doSomething(int val){

Something* sth = new Something(); // Line 1

sth->setValue(val); // Line 2

}

问Line 2如果是doSomething()的最后一行的话会有什问题?

doSomething执行完后sth没有被销毁,内存泄漏。

十、写一个程序将输入的16进制转为10进制。

基础

十一、设计一个微波炉的控制程序(OO)。

这道题有点意思,我主要用Observer模式设计了一个定时器,然后把微波炉烹饪的对象抽象为Cookable。

十二、逻辑题,一列火车以15 mph的速度从北京开往上海,另一列火车以20 mph 的速度从上海开往北京,一只鸟(比较笨)速度25 mph,在两列火车之间来回飞,相遇即折回。问到两列火车相遇这只笨鸟一共飞了多远?

很简单,因为鸟一直在飞,所以一共飞了s/(15 + 20),s为上海到北京之间的距离,那么它一共飞了s/(15 + 20) * 25 mile。

【IBM java 英文面试题(附参考答案)】

1.what is oracle.

2.what is major differenece oracle8i and oracle9i.

4.tell me some thing ur self.

5.please tell me about oops.

6.what is single inheritance.

7.what is multiple inheritance.

8.can java support multiple inheritance.

9.what is interface.

10.what is differenec between abstract class and interface.

11.how to u prove that abstrace class cannot instantiate directly.

12.what is differenece between string and stringbuffer.

13.what is immutable

14.how to write a program using sort program.

15 how to write a program using unsort program.

16.what is legacy.

17.what is legacy api

18.what is legacy interface.

19.what is main difference hashmap and hastable

20.what is main difference between arraylist and vector.

21.what is struts framework.

22.what are distributed techonologies.

23.what is advantage and disadvantage of distributed techonologies.

24.what is main difference between jsp and servlets.

25.what is difference between procedure and functions.

26.what is jdbc.

27.what are type of drivers.

28.what is type 4 driver.

29.how to collect requuirements form u r client.

30.which process use in ur project.

31.what is deployment descriptor.

32.what is heirarchy of files in struts.

33.please draw struts frame wrok.

34.please draw j2ee architecture.

35.please draw mvc-2 architecture.

36.please draw that how design op module.

37.how to find a file on linux.

38.how to configure weblogic8.1 on linux.

39.why you use struts framework in ur project.

40.what is platfrom independent

41.what is awt and swing.

42.what is heavy wieght components.

43.what is feature of weblgoic8.1.

44.why you choose application server on linux and database server on aix.

45.please tell me about ur project.

46.what is major concepts in oops.

47.why u choose mvc-2 architecture.

48.what is implicit object.

49.how many implicit objects in jsp

50.why choose weblogic8.1 other than any applicationserver.

51.what is water fall model vs sdlc

52.what is use of dataflowdiagrams

53.wha t is ip in ur project.

54.what about reception module

—————————————————————————————————————————————————————————

1. Oracle is an RDBMS product with DDL and DML from a company called Oracle Inc.

2. Difference between 8i and 9i is given in the Oracle site

3. Question not available

4. Something

5. oops is Object Oriented Programming

6.what is single inheritance.

ans:one class is inherited by only other one class

7.what is multiple inheritance.

ans:One class inheriting more than one class at atime

8.can java support multiple inheritance.

ans:No

9.what is interface.

ans:Interface has only method declarations but no defn

10.what is differenec between abstract class and interface.

ans:In abstract class some methods may contain definition,but in interface every method should be abstract

11.how to u prove that abstrace class cannot instantiate directly. ans:As they dont have constructor they cant be instantiated

12.what is differenece between string and stringbuffer.

ans:Strings are immutable where as string buffer can be modified 13.what is immutable

ans:Which cant be changed

14.how to write a program using sort program.

15 how to write a program using unsort program.

ans: Both can be done using javascript

This is for Sort

function SelectTextSort(obj) { // sort by text

var N=obj.options.length;

for (var i=0;i

for (var j=i+1;j

if ( obj.options[i].text > obj.options[j].text ) {

var i1= (obj.options[i].selected == true ) ? true : false var j1= (obj.options[j].selected == true ) ? true : false var q1 = obj.options[j].text;

var q2 = obj.options[j].value;

obj.options[j].text = obj.options[i].text;

obj.options[j].value = obj.options[i].value;

obj.options[i].text = q1;

obj.options[i].value = q2;

obj.options[i].selected = (j1 && true ) ? true : false

obj.options[j].selected = (i1 && true ) ? true : false

}

}

}

return true

}

16.what is legacy.

17.what is legacy api

18.what is legacy interface.

ans: legacy is something that is old in terms of technology/ system

19.what is main difference hashmap and hastable

ans:Hash table is synchronised

20.what is main difference between arraylist and vector.

ans:Vector is synchronised

21.what is struts framework.

22.what are distributed techonologies.

distributed technologies means any technology / s/w program that are having many components in multiple environments that interact with each other depending on the functional requirements and design.

23.what is advantage and disadvantage of distributed techonologies.

overdependance on single platform / single language is avoided. Application can be built flexible to meet requirements. Division of labour is possible. Best of all the technologies and platforms can be optimally utilized. Complexity of requirements can be reduced.

25.what is difference between procedure and functions.'

ans:Fuctions can return value ,procedures cant return value

26.what is jdbc.

ans:Connecting to DB from java program requires JDBC

27.what are type of drivers.

type1,2,3,4

29.how to collect requuirements form u r client.

is not a job of a technical person. It is better for a BA to do it.

30.which process use in ur project.

Generally u can say:

Project related process: Analysis, Design, Sign-off Documents, Implementation, Integration, Testing, UAT

Work related process:

Technical Design, Work Allocation, Code Review Checklist, Unit Test Form will be prepared by the Project Lead and given to the developer.

Developer prepares the Unit Test Case

Implements Code, Performs Test

Submits Code through CVS / VSS

Submits documents along with Release Checklist to the tester / leader.

31.what is deployment descriptor.

ans:Which contains the infrnmation like which file to be used

40.what is platfrom independent

ans:A language is said to be platform independent if it can be run on any machine with out modifying code

41.what is awt and swing.

ans:AWT are heavy weight components and swings are light weight components

46.what is major concepts in oops.

ans:Abstraction,polymorphism,encapsulation,inheritance

47.why u choose mvc-2 architecture.

ans:In MVC-2 controller is servlet rather than JSP which makes it efficient

48.what is implicit object.

ans:Implicit objects are a set of Java objects that the JSP Container makes available to developers in each page

49.how many implicit objects in jsp

ans:out,page,session,request,response,application,page context,config

【IBM、SUN公司的Java面试题】

第一,谈谈final, finally, finalize的区别。

最常被问到。

第二,Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)?

第三,Static Nested Class 和 Inner Class的不同,说得越多越好(面试题有的很笼统)。

第四,&和&&的区别。

这个问得很少。

第五,HashMap和Hashtable的区别。

常问。

第六,Collection 和 Collections的区别。

你千万别说一个是单数一个是复数。

第七,什么时候用assert。

API级的技术人员有可能会问这个。

第八,GC是什么? 为什么要有GC?

基础。

第九,String s = new String(xyz);创建了几个String Object?

第十,Math.round(11.5)等於多少? Math.round(-11.5)等於多少?

第十一,short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错?

面试题都是很变态的,要做好受虐的准备。

第十二,sleep() 和 wait() 有什么区别?

搞线程的最爱。

第十三,Java有没有goto?

很十三的问题,如果哪个面试的问到这个问题,我劝你还是别进这家公司。【30道英文Java面试题】

* Q1. How could Java classes direct program messages to the system console, but error messages, say to a file?.

The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:

Stream st = new Stream(new FileOutputStream("output.txt"));

System.setErr(st); System.setOut(st);

* Q2. What's the difference between an interface and an abstract class?

A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

* Q3. Why would you use a synchronized block vs. synchronized method?

A. Synchronized blocks place locks for shorter periods than synchronized methods.

* Q4. Explain the usage of the keyword transient?

A. This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).

* Q5. How can you force garbage collection?

A. You can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.

* Q6. How do you know if an explicit object casting is needed?

A. If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example:

Object a; Customer b; b = (Customer) a;

When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.

* Q7. What's the difference between the methods sleep() and wait()

A. The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.

* Q8. Can you write a Java class that could be used both as an applet as well as an application?

A. Yes. Add a main() method to the applet.

* Q9. What's the difference between constructors and other methods?

A. Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.

* Q10. Can you call one constructor from another if a class has multiple constructors

A. Yes. Use this() syntax.

* Q11. Explain the usage of Java packages.

A. This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.

* Q12. If a class is located in a package, what do you need to change in the OS environment to be able to use it?

A. You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let's say a class Employee belongs to a package com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.java. In this case, you'd need to add c:\dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:

c:\>java com.xyz.hr.Employee

* Q13. What's the difference between J2SDK 1.5 and J2SDK 5.0?

A.There's no difference, Sun Microsystems just re-branded this version.

* Q14. What would you use to compare two String variables - the operator == or the method equals()?

A. I'd use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.

* Q15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?

A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.

【英文Java面试题(核心知识)】

Question: What is transient variable?

Answer: Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.

Question: Name the containers which uses Border Layout as their default layout?

Answer: Containers which uses Border Layout as their default are: window, Frame and Dialog classes.

Question: What do you understand by Synchronization?

Answer: Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption.

E.g. Synchronizing a function:

public synchronized void Method1 () {

// Appropriate method-related code.

}

E.g. Synchronizing a block of code inside a function:

public myFunction (){

synchronized (this) {

// Synchronized code here.

}

}

Question: What is Collection API?

Answer: The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.

Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.

Example of interfaces: Collection, Set, List and Map.

Question: Is Iterator a Class or Interface? What is its use?

Answer: Iterator is an interface which is used to step through the elements of a Collection.

Question: What is similarities/difference between an Abstract class and Interface?

Answer: Differences are as follows:

Interfaces provide a form of multiple inheritance. A class can extend only one other class.

Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.

A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.

Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast. Similarities:

Neither Abstract classes or Interface can be instantiated.

Question: How to define an Abstract class?

Answer: A class containing abstract method is called Abstract class. An Abstract class can't be instantiated.

Example of Abstract class:

abstract class testAbstractClass {

protected String myString;

public String getMyString() {

return myString;

}

public abstract string anyAbstractFunction();

}

Question: How to define an Interface?

Answer: In Java Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces

is bound to implement all the methods defined in Interface.

Emaple of Interface:

public interface sampleInterface {

public void functionOne();

public long CONSTANT_ONE = 1000;

}

Question: Explain the user defined Exceptions?

Answer: User defined Exceptions are the separate Exception classes defined by the user for specific purposed. An user defined can created by simply sub-classing it to the Exception class. This allows custom exceptions to be generated (using throw) and caught in the same way as normal exceptions.

Example:

class myCustomException extends Exception {

// The class simply has to exist to be an exception

}

Question: Explain the new Features of JDBC 2.0 Core API?

Answer: The JDBC 2.0 API includes the complete JDBC API, which includes both core and Optional Package API, and provides inductrial-strength database computing capabilities.

New Features in JDBC 2.0 Core API:

Scrollable result sets- using new methods in the ResultSet interface allows programmatically move the to particular row or to a position relative to its current position

JDBC 2.0 Core API provides the Batch Updates functionality to the java applications.

Java applications can now use the ResultSet.updateXXX methods.

New data types - interfaces mapping the SQL3 data types

Custom mapping of user-defined types (UTDs)

Miscellaneous features, including performance hints, the use of character streams, full precision for java.math.BigDecimal values, additional security, and support for time zones in date, time, and timestamp values.

Question: Explain garbage collection?

Answer: Garbage collection is one of the most important feature of Java. Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. User program cann't directly free the object from memory, instead it is the job of the garbage collector to automatically free the objects that are no longer referenced by a program. Every class inherits finalize() method from https://www.doczj.com/doc/146852706.html,ng.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists. In Java, it is good idea to explicitly assign null into a variable when no more in use. I Java on calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected.

Question: How you can force the garbage collection?

Answer: Garbage collection automatic process and can't be forced.

Question: What is OOPS?

Answer: OOP is the common abbreviation for Object-Oriented Programming.

Question: Describe the principles of OOPS.

Answer: There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation.

Question: Explain the Encapsulation principle.

Answer: Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.

Question: Explain the Inheritance principle.

Answer: Inheritance is the process by which one object acquires the properties of another object.

Question: Explain the Polymorphism principle.

Answer: The meaning of Polymorphism is something like one name many forms. Polymorphism enables one entity to be used as as general category for different types of actions. The specific action is determined by the exact nature of the situation. The concept of polymorphism can be explained as "one interface, multiple methods".

Question: Explain the different forms of Polymorphism.

Answer: From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:

Method overloading

Method overriding through inheritance

Method overriding through the Java interface

Question: What are Access Specifiers available in Java?

Answer: Access specifiers are keywords that determines the type of access to the member of a class. These are:

Public

Protected

Private

Defaults

Question: Describe the wrapper classes in Java.

Answer: Wrapper class is wrapper around a primitive data type. An instance of a wrapper class contains, or wraps, a primitive value of the corresponding type.

Following table lists the primitive types and the corresponding wrapper classes:

Primitive Wrapper

boolean https://www.doczj.com/doc/146852706.html,ng.Boolean

byte https://www.doczj.com/doc/146852706.html,ng.Byte

char https://www.doczj.com/doc/146852706.html,ng.Character

double https://www.doczj.com/doc/146852706.html,ng.Double

float https://www.doczj.com/doc/146852706.html,ng.Float

int https://www.doczj.com/doc/146852706.html,ng.Integer

long https://www.doczj.com/doc/146852706.html,ng.Long

short https://www.doczj.com/doc/146852706.html,ng.Short

void https://www.doczj.com/doc/146852706.html,ng.Void

Question: Read the following program:

public class test {

public static void main(String [] args) {

int x = 3;

int y = 1;

if (x = y)

System.out.println("Not equal");

else

System.out.println("Equal");

}

}

What is the result?

A. The output is equal?br>

B. The output in not Equal?br>

C. An error at " if (x = y)" causes compilation to fall.

D. The program executes but no output is show on console.

Answer: C

Question: what is the class variables ?

Answer: When we create a number of objects of the same class, then each object will share a common copy of variables. That means that there is only one copy per class, no matter how many objects are created from it. Class variables or static variables are declared with the static keyword in a class, but mind it that it should be declared outside outside a class. These variables are stored in static memory. Class variables are mostly used for constants, variable that never change its initial value. Static variables are always called by the class name. This variable is created when the program starts i.e. it is created before the instance is created of class by using new operator and gets destroyed when the programs stops. The scope of the class variable is same a instance variable. The class variable can be defined anywhere at class level with the keyword static. It initial value is same as instance variable. When the class variable is defined as int then it's initial value is by default zero, when declared boolean its default value is false and null for object references. Class variables are associated with the class, rather than with any object.

Question: What is the difference between the instanceof and getclass, these two are same or not ?

Answer: instanceof is a operator, not a function while getClass is a method of https://www.doczj.com/doc/146852706.html,ng.Object class. Consider a condition where we use

if(o.getClass().getName().equals("https://www.doczj.com/doc/146852706.html,ng.Math")){ }

This method only checks if the classname we have passed is equal to https://www.doczj.com/doc/146852706.html,ng.Math. The class https://www.doczj.com/doc/146852706.html,ng.Math is loaded by the bootstrap ClassLoader. This class is an abstract class.This class loader is responsible for loading classes. Every Class object contains a reference to the ClassLoader that defines. getClass() method returns the runtime class of an object. It fetches the java instance of the given fully qualified type name. The code we have written is not necessary, because we should not compare getClass.getName(). The reason behind it is that if the two different class loaders load the same class but for the JVM, it will consider both classes as different classes so, we can't compare their names. It can only gives the implementing class but can't compare a interface, but instanceof operator can.

The instanceof operator compares an object to a specified type. We can use it to test if an object is an instance of a class, an instance of a subclass, or an instance of a class that implements a particular interface. We should try to use instanceof operator in place of getClass() method. Remember instanceof opeator and getClass are not same. Try this example, it will help you to better understand the difference between the two. Interface one{

}

Class Two implements one {

}

Class Three implements one {

}

public class Test {

public static void main(String args[]) {

one test1 = new Two();

one test2 = new Three();

System.out.println(test1 instanceof one); //true

System.out.println(test2 instanceof one); //true

System.out.println(Test.getClass().equals(test2.getClass())); //false }

}

【常用JAVA面试题库(附答案、第四部分)】

31 是否可以继承String类?

String类是final类故不可以继承。

32 构造器Constructor是否可被override?

构造器Constructor不能被继承,因此不能重写Overriding,但可以被重载Overloading。

33 当一个线程进入一个对象的一个synchronized方法后,其它线程是否可进入此对象的其它方法?

不能,一个对象的一个synchronized方法只能由一个线程访问。

33 try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code 会不

会被执行,什么时候被执行,在return前还是后?

会执行,在return前执行。

34 编程题: 用最有效率的方法算出2乘以8等於几?

2 << 3

35 两个对象值相同(x.equals(y) == true),但却可有不同的hash code,这句话对不对?

不对,有相同的hash code。

36 当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性,并可返回变化后的结果,那么这里到底是值传递还是引用传递?

是值传递。Java编程语言只由值传递参数。当一个对象实例作为一个参数被传递到方法中时,参数的值就是对该对象的引用。对象的内容可以在被调用的方法中改变,但对象的引用是永远不会改变的。

37 swtich是否能作用在byte上,是否能作用在long上,是否能作用在String 上?

switch(expr1)中,expr1是一个整数表达式。因此传递给 switch 和 case 语句的参数应该是 int、 short、 char 或者 byte。long,string 都不能作用于swtich。

38 Hashtable和HashMap

Hashtable继承自Dictionary类,而HashMap是Java1.2引进的Map interface的一个实现

HashMap允许将null作为一个entry的key或者value,而Hashtable不允许

还有就是,HashMap把Hashtable的contains方法去掉了,改成containsvalue 和containsKey。因为contains方法容易让人引起误解。

最大的不同是,Hashtable的方法是Synchronize的,而HashMap不是,在多个线程访问Hashtable时,不需要自己为它的方法实现同步,而HashMap就必须为之提供外同步。

Hashtable和HashMap采用的hash/rehash算法都大概一样,所以性能不会有很大的差异。

【常用JAVA面试题库(附答案、第三部分)】

21 Overload和Override的区别。Overloaded的方法是否可以改变返回值的类型?

方法的重写Overriding和重载Overloading是Java多态性的不同表现。重写Overriding是父类与子类之间多态性的一种表现,重载Overloading是一个类中多态性的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写(Overriding)。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被“屏蔽”了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载(Overloading)。

Overloaded的方法是可以改变返回值的类型。

22 数组有没有length()这个方法? String有没有length()这个方法?

数组没有length()这个方法,有length的属性。

String有有length()这个方法。

23 Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别?

Set里的元素是不能重复的,那么用iterator()方法来区分重复与否。equals()是判读两个Set是否相等。 equals()和==方法决定引用值是否指向同一对象equals()在类中被覆盖,为的是当两个分离的对象的内容和类型相配的话,返回真值。

24最常见到的runtime exception。

Java面试题带答案

J a v a面试题带答案 Document number:BGCG-0857-BTDO-0089-2022

湖南世杰Java工程师面试题 选择题: 单选题 1,以下java程序代码,执行后的结果是( ) map= ("name",null); ("name","Jack"); 0 B: null C: 1 D: 2 答案:C 2,执行以下程序后的输出结果是( ) Public class Test { Public static void main(String[] args) { StringBuffer a = new StringBuffer("A"); StringBuffer b = new StringBuffer("B"); operator(a, b);

+","+ b); } Public static void operator(StringBuffer x, StringBuffer y) { (y); y = x; } } A: A,A B: A,B C: B,B D: AB,B 答案:D 3,关于依赖注入,下列选项中说法错误的是( ) A:依赖注入能够独立开发各组件,然后根据组件间关系进行组装 B:依赖注入使组件之间相互依赖,相互制约 C:依赖注入提供使用接口编程 D:依赖注入指对象在使用时动态注入 答案:B

4,关于spring说法错误的是( ) A: spring是一个轻量级JAVA EE的框架集合 B: spring是“依赖注入”模式的实现 C: 使用spring可以实现声明事务 D: spring提供了AOP方式的日志系统 答案:D 5,要在session对象中保存属性,可以使用以下哪个语句( ) A: (“key”,”value”) B: (“key”,”value”) C: (“key”) D: (“key”) 答案:B 6,关于以下程序代码的说明正确的是( ) Public class HasStatic{ Private static int x = 100; Public static void main(String args[]){

Java面试题大全(答案版)

一个".java"源文件中是否可以包括多个类(不是内部类)?有 什么限制? 可以,但是只能有一个类用public修饰,并且用public修饰的类名与文件名要一致 2、&和&&的区别。 &和&&都可以用作逻辑与; &&还具有短路功能,即如果第一个表达式的结果为false,则不再计算第二 个表达式; &还可以用作位运算符,当&操作符两边的表达式不是boolean类型时,&表示按位与操作。 3、J ava有没有goto? java中的保留字,现在没有在java中使用。 4、在JAVA中,如何跳出当前的多重嵌套循环? break+变量控制与return 5、s witch是否能作用在byte(拜特)上,是否能作用在long上,是否能作用在Stri ng 上? Switch可以作用在int上,而byte可以隐式转换为int所以能作用在byte 上 不能作用在long上,也不能作用在String上 6、s hort s1 = 1; s1 = s1 + 有什么错? short s1 = 1; s1 += 有什么错? 1在java中为int数据类型,short+int=int,大类型转为小类型,编译时,会报告需要强制转换类型的错误。s1+=1不会报,因为JVM会对它特殊处理(自动强转) 7、char型变量中能不能存贮一个中文汉字?为什么? 可以,char型变量是用来存储uni code(依妮Q特)编码的,而uni code编码包含了中文,所以是可以保存的

&编程题:用最有效率的方法算出2乘以8等於几? 2<<3,表示将2左移3位;一个数左移几位就表示这个数乘以了2的几次方, 左移运算,CPU直接支持,所以是最有效率的 9、请设计一个一百亿的计算器 思路:用两个数组分别保存两个操作数,再新建一个数组保存结果。 0、使用final关键字修饰一个变量时,是引用不能变,还是引用的对象不能变? 引用变量不能变 1、"=="和equals方法究竟有什么区别? ==和equals方法都可以用来比较两个对象是否是同一个对象。 ==还可以比较两个变量的值是否相等。 equals是Object类中的方法,可以由子类重写此方法,实现内容相等。 2、静态变量和实例变量的区别? 语法上不同:静态变量前要加static关键字,实例变量不需要 程序运行时不同:实例变量是属于某个对象的,只有创建了对象,才会为这个对象的实例变量分配空间。静态变量是属于类的,当程序加载了这个类的字节码文件,就会为静态变量分配空间,并且所有对象共享这个变量 3、是否可以从一个static方法内部发出对非static方法的调用? 不可以,非static方法需要与对象关联在一起的,而static方法调用时不需要对象,可以直接调用,也就是说调用static方法时,可能还没有创建任何实例 4、Integer与int的区别 int是java中的8种基本数据类型之一,默认值是0, Integer是int的包装类, 默认值是null,即Integer可以表示未赋值和赋值为0

Java面试题大全(答案版)

1、一个".java"源文件中是否可以包括多个类(不是内部类)?有什么限制? 可以,但是只能有一个类用public修饰,并且用public修饰的类名与文件名要一致 2、&和&&的区别。 &和&&都可以用作逻辑与; &&还具有短路功能,即如果第一个表达式的结果为false,则不再计算第二个表达式; &还可以用作位运算符,当&操作符两边的表达式不是boolean类型时,&表示按位与操作。 3、Java有没有goto? java中的保留字,现在没有在java中使用。 4、在JAVA中,如何跳出当前的多重嵌套循环? break+变量控制与return 5、switch是否能作用在byte(拜特)上,是否能作用在long上,是否能作用在String上? Switch可以作用在int上,而byte可以隐式转换为int 所以能作用在byte上 不能作用在long上,也不能作用在String上 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 1在java中为int数据类型,short+int=int,大类型转为小类型,编译时,会报告需要强制转换类型的错误。s1+=1不会报,因为JVM会对它特殊处理(自动强转) 7、char型变量中能不能存贮一个中文汉字?为什么? 可以,char型变量是用来存储unicode(依妮Q特)编码的,而unicode编码包含了中文,所以是可以保存的 8、编程题: 用最有效率的方法算出2乘以8等於几? 2<<3,表示将2左移3位;一个数左移几位就表示这个数乘以了2的几次方,左移运算,CPU直接支持,所以是最有效率的 9、请设计一个一百亿的计算器 思路:用两个数组分别保存两个操作数,再新建一个数组保存结果。 10、使用final关键字修饰一个变量时,是引用不能变,还是引用的对象不能变? 引用变量不能变 11、"=="和equals方法究竟有什么区别? ==和equals方法都可以用来比较两个对象是否是同一个对象。 ==还可以比较两个变量的值是否相等。 equals是Object类中的方法,可以由子类重写此方法,实现内容相等。 12、静态变量和实例变量的区别? 语法上不同: 静态变量前要加static关键字,实例变量不需要 程序运行时不同: 实例变量是属于某个对象的,只有创建了对象,才会为这个对象的实例变量分配空间。静态变量是属于类的,当程序加载了这个类的字节码文件,就会为静态变量分配空间,并且所有对象共享这个变量 13、是否可以从一个static方法内部发出对非static方法的调用? 不可以,非static方法需要与对象关联在一起的,而static方法调用时不需要对象,可以直接调用,也就是说调用static方法时,可能还没有创建任何实例 14、Integer与int的区别 int是java中的8种基本数据类型之一,默认值是0,Integer是int的包装类,默认值是null,即Integer可以表示未赋值和赋值为0 15、(麦死)Math.round(乱的)(11.5)等於多少? Math.round(-11.5)等於多少?

java笔试题及答案.doc

java笔试题及答案 有了下面java笔试题及答案,进行java笔试时就容易多了,请您对下文进行参考: 1、作用域public,private,protected,以及不写时的区别 答:区别如下: 作用域当前类同一package子孙类其他package public 7 7 7 7 protected 7 7 7 X friendly 7 7 X X private 7 X X X 不写时默认为friendly 2、Anonymouslnner Class (匿名内部类)是否可以exte nd s (继承)其它类,是否可以imple ment s (实现)i nterf ace (接口) 答:匿名的内部类是没有名字的内部类。不能exte n ds (继承)其它类,但一个内部类可以作为一个接口,由另一个内部类实现 3、Sta ti cNestedC las s 和Inner Clas s 的不同答: Nes tedC lass (一般是C+ +的说法),In ne rClass (—般是JAVA的说法)。J ava内部类与C++嵌套类最大的不同就在于是否有指向外部的引用上。注:静态内部类(I

nn erClass)意味着1创建一个st atic内部类的对象,不需要一个外部类对象,2不能从一个st atic内部类的一个对象访问一个外部类对象 4、和的区别 答:是位运算符,表示按位与运算,是逻辑运算符,表示遷辑与(and ) 5、Coll ect ion 和Col lect ions 的区别 答:Coll ect ion是集合类的上级接口,继承与他的接口主要有Set和List. Col lections是针对集合类的一个帮助类,他提供一系列静态方法实现对各种集合的搜索、排序、线程安全化等操作 6、什么时候用assert 答:asserti on (断言)在软件开发中是一种常用的调试方式,很多开发语言中都支持这种机制。在实现中,a ssertion 就是在程序中的一条语句,它对一个boolea n表 达式进行检查,一个正确程序必须保证这个bool ean表达 式的值为tr ue;如果该值为fal se,说明程序己经处于不正确的状态下,系统将给出警告或退出。一般来说,

【精品】最全 Java 面试题:Java基础篇

【精品】最全Java 面试题:Java基础篇 Java概述 何为编程 编程就是让计算机为解决某个问题而使用某种程序设计语言编写程序代码,并最终得到结果的过程。 为了使计算机能够理解人的意图,人类就必须要将需解决的问题的思路、方法、和手段通过计算机能够理解的形式告诉计算机,使得计算机能够根据人的指令一步一步去工作,完成某种特定的任务。这种人和计算机之间交流的过程就是编程。 什么是Java Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。jdk三大版本 ?Java SE(J2SE,Java 2 Platform Standard Edition,标准版) Java SE 以前称为J2SE。它允许开发和部署在桌面、服务器、嵌入式环境和实时环境中使用的Java 应用程序。Java SE 包含了支持Java Web 服务开发的类,并为Java EE和Java ME提供基础。 ?Java EE(J2EE,Java 2 Platform Enterprise Edition,企业版) Java EE 以前称为J2EE。企业版本帮助开发和部署可移植、健壮、可伸缩且安全的服务器端Java 应用程序。Java EE 是在Java SE 的基础上构建的,它提供Web 服务、组件模型、管理和通信API,可以用来实现企业级的面向服务体系结构(service-oriented architecture,SOA)和 Web2.0应用程序。

Java经典面试题大全_带答案

Java经典面试题带答案一、单项选择题 1.Java是从()语言改进重新设计。 A.Ada B.C++ C.Pasacal D.BASIC 答案:B 2.下列语句哪一个正确() A.Java程序经编译后会产生machine code B.Java程序经编译后会产生byte code(字节码) C.Java程序经编译后会产生DLL D.以上都不正确 答案:B 3.下列说法正确的有() A.class中的constructor不可省略 B.constructor必须与class同名,但方法不能与class同名C.constructor在一个对象被new时执行(构造器) D.一个class只能定义一个constructor 答案:C 4.提供Java存取数据库能力的包是() A.Java.sql /sql/数据库还有Oracle 也是一种数据库 B.java.awt C.https://www.doczj.com/doc/146852706.html,ng D.java.swing 答案:A 5.下列运算符合法的是() A.&& B.<> C.if D.:= 答案:A 6.执行如下程序代码 a=0;c=0; do{ --c; a=a-1; }while(a>0); 后,C的值是() A.0 B.1 C.-1 D.死循环

答案:C 7.下列哪一种叙述是正确的() A.abstract修饰符可修饰字段、方法和类 B.抽象方法的body部分必须用一对大括号{}包住 C.声明抽象方法,大括号可有可无 D.声明抽象方法不可写出大括号 答案:D 8.下列语句正确的是() A.形式参数可被视为localvariable B.形式参数可被字段修饰符修饰 C.形式参数为方法被调用时,真正被传递的参数 D.形式参数不可以是对象 答案:A 9.下列哪种说法是正确的() A.实例方法可直接调用超类的实例方法 B.实例方法可直接调用超类的类方法 C.实例方法可直接调用其他类的实例方法 D.实例方法可直接调用本类的类方法 答案:D 二、多项选择题 1.Java程序的种类有() A.类(Class) B.Applet C.Application D.Servlet 2.下列说法正确的有() A.环境变量可在编译sourcecode时指定 B.在编译程序时,所能指定的环境变量不包括class path C.javac一次可同时编译数个Java源文件 D.javac.exe能指定编译结果要置于哪个目录(directory)答案:BCD 3.下列标识符不合法的有() A.new B.$Usdollars C.1234 D.car.taxi 答案:ACD 4.下列说法错误的有() A.数组是一种对象 B.数组属于一种原生类 C.intnumber=[]={31,23,33,43,35,63} D.数组的大小可以任意改变 答案:BCD 5.不能用来修饰interface的有()

java笔试题含答案

班级:_______________ 学号:______________ 姓名:___________ Java 笔试题 (可多选) 1. 下面哪些是Thread类的方法( ABD) A start() B run() C exit() D getPriority() 2. 下面关于类的说法正确的是(A) A 继承自Throwable B Serialable C 该类实现了Throwable 接口 D 该类是一个公共类 3. 下面程序的运行结果是( false ) String str1 = "hello"; String str2 = "he" + new String("llo"); == str2); 4. 下列说法正确的有( C) A. class中的constructor不可省略

B. constructor必须与class同名,但方法不能与class同名C. constructor在一个对象被new时执行 D.一个class只能定义一个constructor 5. 指针在任何情况下都可进行>, <, >=, <=, ==运算( true ) 6. 下面程序的运行结果:(B) public static void main(String args[]) { Thread t = new Thread() { public void run() { pong(); } }; (); "ping"); } static void pong() { "pong"); } A pingpong

B pongping C pingpong和pongping都有可能 D 都不输出 7. 下列属于关系型数据库的是(AB) A. Oracle B MySql C IMS D MongoDB 8. GC(垃圾回收器)线程是否为守护线程( true ) 9. volatile关键字是否能保证线程安全( false ) 10. 下列说法正确的是(AC) A LinkedList继承自List B AbstractSet继承自Set C HashSet继承自AbstractSet D WeakMap继承自HashMap 11. 存在使i + 1 < i的数吗(存在) 12. 的数据类型是(B) A float B double C Float D Double

Java面试题集(最全版)

目录表 第一章技巧篇 2 介绍自己2 行为2 第二章智力篇 3 微软面试题 3 第三章 Java篇5 Java基础方面--概念 5 Java基础方面—线程编程方面12 Java基础方面—编程 14 第四章 Jsp篇30 第五章 Servlet篇31 第六章应用服务器篇37 第七章 J2EE,MVC篇38 第八章设计模式方面篇40 第九章 Hibernate程序性能优化篇41 Hibernate程序性能优化 45

Hibernate 优化47 Hibernate优化的几点建议51 Hibernate性能优化52 第十章数据库篇55 第一套数据库笔试题及答案 55第二套数据库笔试题及答案 64

第一章技巧篇 介绍自己 1、自我认识 想一矢中的,首先必须认清自我,一定要弄清以下三个问题。你现在是干什么的?你将来要干什么?你过去是干什么的? 这三个问题不是按时间顺序从过去到现在再到将来,而是从现在到将来再到过去。其奥妙在于:如果你被雇用,雇主选中的是现在的你,他希望利用的是将来的你,而这将来又基于你的历史和现状。 所以,第一个问题,你是干什么的?现在是干什么的?回答这个问题,要点是:你是你自己,不是别的什么人。除非你把自己与别人区别开来,在共同点的基础上更强调不同点,否则你绝无可能在众多的应征求职者中夺魁。对于这第一个问题,自我反省

越深,自我鉴定就越成功。 随后,着手回答第二个问题:你将来要干什么?如果你申请的是一份举足轻重的工作,雇主肯定很关注你对未来的自我设计。你的回答要具体,合理,并符合你现在的身份,要有一个更别致的风格。 然后,再着手回答最后一个问题:你过去是干什么的?你的过去当然都在履历上已有反映。你在面试中再度回答这个问题时,不可忽略之处是:不要抖落一个与你的将来毫不相干的过去。如果你中途彻底改行,更要在描述你的执着、职业目标的一贯性上下些功夫。要做到这一点,又要忠实于事实和本人,最简单的方法是:找到过去与将来的联系点,收集过去的资料,再按目标主次排列。 用这样的方法,以现在为出发点,以将来为目标,以过去为证实,最重要的是加深了你的自我分析和理解。其实,在面试的时候不一定有机会或者有必要照搬你的大作,但这三个问题的内在联系点一定会体现在自我表述的整体感觉中,使你的形象栩栩如生。 2、投其所好 清楚自己的强项后,便可以开始准备自我介绍的内容:包括工作模式、优点、技能,突出成就、专业知识、学术背景等。

Java开发工程师笔试题(带答案)

Java开发工程师笔试试题 (请不要在试题上留任痕迹,所有答案均写在答题纸上) 一.编程题(共26分) 1.任意写出一种排序算法。(6分) public void sort(int [] array){ //代码区 } 2.求1+2+3+..n(不能使用乘除法、for 、while 、if 、else 、switch 、case 等关键字 以及条件判断语句)(8分) public int sum(int n){ //代码区 return 0; } 3.完成下面法,输入一个整数,输出如下指定样式图案。(12分) 输入:3, 输出: 1*2*3 7*8*9 4*5*6

输入:4 输出: 1*2*3*4 9*10*11*12 13*14*15*16 5*6*7*8 public void drawNumPic(int n){ //代码区 } 二.选择题(定项选择每题3分,不定项选择每题4分,共63分) 1.在基本JAVA类型中,如果不明确指定,整数型的默认是__类型,带小数的默认是__类型?( B ) A.int float B.int double C.long float D.long double 2.只有实现了__接口的类,其对象才能序列化( A ) A.Serializable B.Cloneable https://www.doczj.com/doc/146852706.html,parable

D.Writeable 3.代码System. out. println(10 % 3 * 2);将打印出?( B ) A. 1 B.2 C.4 D.6 4.以下程序运行的结果为( A ) public class Example extends Thread{ @Override public void run(){ try{ Thread.sleep(1000); }catch (InterruptedException e){ e.printStackTrace(); } System.out.print("run"); } public static void main(String[] args){ Example example=new Example(); example.run(); System.out.print("main"); } } A.run main B.main run C.main D.run E.不能确定 5.下面有关java实例变量,局部变量,类变量和final变量的说法,错误的是?( B ) A.实例变量指的是类中定义的变量,即类成员变量,如果没有初始化,会有默认值

2017新版JAVA面试题目汇总

详解笔试面试题集 (1)下列各题ABCD四个选顼中,只有一个选项是正确的,请将正确选项填写在答题纸上 (1)下列关于栈的描述中错误的是(B) A.栈是先进后出的线性表 B栈只能顺序存储 C栈具有记忆作用 D对栈的插入弓删除操作中,不需要改变栈底指针 正确答案:B 分析:栈是链式存储的 ⑵对于长度为n的线性表,在最坏情况下,下列各排序法所对应的比较次数中正确的是() A 冒泡排序为n/2 B 冒泡排序为n C快速排序为n D 快速排序为n(n-1)/2 正确答案:D 分析: 想想快速排序,每次都会选取线性表的轴值,随后以此轴值划分为两个子线性表再分别 进行快排,在最坏情况下,也就是说每次选出的线性表轴值完全不能将这个线性表划分为两个子线性表。那么此时快速排序退化为冒泡排序了。 那么第一趟排序时,轴值(线性表的中间位置)被选出,这个值绝对是这个线性表中最 大的(不然也不能是最坏情况),其他值都比他小,那么线性表现在分为完全不对等的两段(一段是0,另一段是n - 1),一段是这个值,一段是其他值。同样第二趟排序在刚才剩下的值中选中间值(剩余值中最大的那个),又分为不对等两段,依次递推。也就 是说每次都比较了N- 1个元素(轴值选出后都与它比较大小),那么肯定是比较了n- 1 次(如第一次先挑了个轴值,然后剩下n - 1比较),n代表当前子线性表中元素个数 由此最白痴的数列问题出现了,如下 1 + 2 + 3 + ........ + n - 2 + n - 1 = n(n - 1) / 2 还有一种投机取巧的方法,在最垃圾情况下既然快排变为冒泡,那由时间复杂度知其必 为o(n A 2)的复杂度,答案中ABC都是线性时间复杂,显然错误 ⑶下列对于线性链表的描述中正确的是()

最新最新java笔试题及答案

一.选择题(1-10题每题2分,11-15题每题4分) 1.下面关于Java语言说法错误的是:() A.java语言是完全面向对象的 B。java语言支持多继承 C.java语言支持多线程 D。java语言最早是为消费电子产品领域设计的 2.下面标识符中正确的是:() A.*123 B。12java C.continue D。java$next 3.下列关于注释语句的描述中,正确的一项是() A。以//开始的是多行注释语句 B。以/*开始,*/结束的是单行注释语句 C。以/**开始,*/结束的是可以用于生成帮助文档的注释语句 D。以/**开始,*/结束的是单行注释语句 4.为了区分重载多态中同名的不同方法,要求()。 A)形式参数个数或者类型不同 B)返回值类型不同 C)调用时用类名或对象名做前缀 D)形式参数名称不同 5.下面定义数组的格式中正确的是:() A.int a[10] B。int a=new int[10] C.int []a=new int[5] D.int a[] 6.下面说法中不正确的是:() A.类是对象的抽象,对象是类的实例 B。类是组成java程序的最小的单位 C.java语言支持多继承 D。java一个程序中只能有一个public类 7.定义类时,不可能用到的保留字是()。 A) private B) class C) extends D) implements 8.为 AB 类的定义一个公共的构造函数,该方法头的形式为()

A.void AB( ) B。public void method( ) C.public method ( ) D。public AB( ) 9.下面说法中不正确的是:() A.java中一个类只允许实现一个接口 B。抽象类中允许有非抽象方法的存在 C.类变量(实例变量)可以直接用类名调用 D。通过super可以调用基类的构造函数 10.容器JFrame 默认使用的布局编辑策略是() A.BorderLayout B。FlowLayout C。GridLayout D。CardLayout 11.以下哪个表达式是不合法的() A.String x=”Hello”; int y=9; x+=y; B.String x=”Hello”; int y=9; if(x= =y) { } C.String x=”Hello”; int y=9; x=x+y; D.String x=null; int y=(x!=null)&&(x.length()>0) 12.class person { public int addvalue(int a,int b) { int s; s=a+b; return s; } }

北大青鸟推荐:Java精选笔试题(含答案解析)

北大青鸟推荐:Java精选笔试题(含答案解析)如果你是计算机专业出生,但是还没有找到工作的话,你就得补补技术了,一些关于面试、笔试的题要多刷一刷。有可能你知道答案,但是由于语言组织能力有所欠缺,所以面试官的印象不是很好,下面分享一些Java精选的鄙视题,希望对面试这者有帮助。 1,volatile关键字是否能保证线程安全?() 答案:否 volatile关键字用在多线程同步中,可保证读取的可见性,JVM只是保证从主内存加载到线程工作内存的值是最新的读取值,而非cache中。但多个线程对volatile的写操作,无法保证线程安全。 假如线程1,线程2 在进行read,load 操作中,发现主内存中count的值都是5,那么都会加载这个最新的值,在线程1对count进行修改之后,会write到主内存中,主内存中的count变量就会变为6;线程2由于已经进行read,load操作,在进行运算之后,也会更新主内存count的变量值为6;导致两个线程及时volatile关键字修改之后,还是会存在并发的情况。 2,下面哪个流类属于面向字符的输入流( ) A、BufferedWriter B、FileInputStream C、ObjectInputStream D、InputStreamReader 答案:D Java的IO操作中有面向字节(Byte)和面向字符(Character)两种方式。

面向字节的操作为以8位为单位对二进制的数据进行操作,对数据不进行转换,这些类都是InputStream和OutputStream的子类。 面向字符的操作为以字符为单位对数据进行操作,在读的时候将二进制数据转为字符,在写的时候将字符转为二进制数据,这些类都是Reader和Writer的子类。 3,Java能不能不通过构造函数创建对象() A、能 B、不能 答案:A Java创建对象的几种方式: (1) 用new语句创建对象,这是最常见的创建对象的方法。 (2) 运用反射手段,调用https://www.doczj.com/doc/146852706.html,ng.Class或者https://www.doczj.com/doc/146852706.html,ng.reflect.Constructor类的newInstance()实例方法。 (3) 调用对象的clone()方法。 (4) 运用反序列化手段,调用java.io.ObjectInputStream对象的readObject()方法。 (1)和(2)都会明确的显式的调用构造函数;(3)是在内存上对已有对象的影印,所以不会调用构造函数;(4)是从文件中还原类的对象,也不会调用构造函数。 4,下列哪个叙述是正确的() A.子类继承父类的构造方法。 B.abstract类的子类必须是非abstract类。 C.子类继承的方法只能操作子类继承和隐藏的成员变量。 D.子类重写或新增的方法也能直接操作被子类隐藏的成员变量。 答案:C 子类是不继承父类的构造方法的,而是必须调用其父类的构造方法。

java经典面试题大全带答案

Java经典面试题带答案 一、单项选择题 1.Java是从()语言改进重新设计。 A.Ada B.C++ C.Pasacal D.BASIC 答案:B 2.下列语句哪一个正确() A. Java程序经编译后会产生machine code B.Java程序经编译后会产生byte code C.Java程序经编译后会产生DLL D.以上都不正确 答案:B 3.下列说法正确的有() A.class中的constructor不可省略 B. constructor必须与class同名,但方法不能与class同名C.constructor在一个对象被new时执行 D.一个class只能定义一个constructor 答案:C 4.提供Java存取数据库能力的包是() A. B. C. D. 答案:A 5.下列运算符合法的是() A.&& B.<> C.if D.:= 答案:A 6.执行如下程序代码 a=0;c=0; do{ --c; a=a-1; }while(a>0); 后,C的值是() A.0 B.1 C.-1 D.死循环

答案:C 7.下列哪一种叙述是正确的() A.abstract修饰符可修饰字段、方法和类 B.抽象方法的body部分必须用一对大括号{}包住 C.声明抽象方法,大括号可有可无 D.声明抽象方法不可写出大括号 答案:D 8.下列语句正确的是() A.形式参数可被视为localvariable B.形式参数可被字段修饰符修饰 C.形式参数为方法被调用时,真正被传递的参数 D.形式参数不可以是对象 答案:A 9.下列哪种说法是正确的() A.实例方法可直接调用超类的实例方法 B.实例方法可直接调用超类的类方法 C.实例方法可直接调用其他类的实例方法 D.实例方法可直接调用本类的类方法 答案:D 二、多项选择题 1.Java程序的种类有() A.类(Class) B.Applet C.Application D.Servlet 2.下列说法正确的有() A.环境变量可在编译sourcecode时指定 B.在编译程序时,所能指定的环境变量不包括class path C.javac一次可同时编译数个Java源文件 D.能指定编译结果要置于哪个目录(directory) 答案:BCD 3.下列标识符不合法的有() A.new B.$Usdollars C.1234 D. 答案:ACD 4.下列说法错误的有() A.数组是一种对象 B.数组属于一种原生类 C.intnumber=[]={31,23,33,43,35,63} D.数组的大小可以任意改变 答案:BCD 5.不能用来修饰interface的有()

Java面试题(带答案)

湖南世杰Java工程师面试题选择题: 单选题 1,以下java程序代码,执行后的结果是( ) java.util.HashMap map=newjava.util.HashMap(); map.put("name",null); map.put("name","Jack"); System.out.println(map.size()); A: 0 B: null C: 1 D: 2 答案:C 2,执行以下程序后的输出结果是( ) Public class Test { Public static void main(String[] args) { StringBuffer a = new StringBuffer("A"); StringBuffer b = new StringBuffer("B"); operator(a, b); System.out.println(a +","+ b); } Public static void operator(StringBuffer x, StringBuffer y) { x.append(y); y = x; }

} A: A,A B: A,B C: B,B D: AB,B 答案:D 3,关于依赖注入,下列选项中说法错误的是( ) A:依赖注入能够独立开发各组件,然后根据组件间关系进行组装 B:依赖注入使组件之间相互依赖,相互制约 C:依赖注入提供使用接口编程 D:依赖注入指对象在使用时动态注入 答案:B 4,关于spring说法错误的是( ) A: spring是一个轻量级JAVA EE的框架集合 B: spring是“依赖注入”模式的实现 C: 使用spring可以实现声明事务 D: spring提供了AOP方式的日志系统 答案:D 5,要在session对象中保存属性,可以使用以下哪个语句( ) A: session.getAttribute(“key”,”value”) B: session.setAttribute(“key”,”value”) C: session.setAttribute(“key”) D: session.getAttribute(“key”) 答案:B 6,关于以下程序代码的说明正确的是?( ) Public class HasStatic{ Private static int x = 100;

java笔试题大集合及答案Java基础方面

Java基础方面: 1、作用域public,private,protected,以及不写时的区别 答:区别如下: 作用域当前类同一package 子孙类其他package public √√√√ protected √√√× friendly √√×× private √××× 不写时默认为friendly 2、Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口) 答:匿名的内部类是没有名字的内部类。不能extends(继承) 其它类,但一个内部类可以作为一个接口,由另一个内部类实现 3、Static Nested Class 和Inner Class的不同 答:Nested Class (一般是C++的说法),Inner Class (一般是JAVA的说法)。Java内部类与C++嵌套类最大的不同就在于是否有指向外部的引用上。注:静态内部类(Inner Class)意味着1创建一个static内部类的对象,不需要一个外部类对象,2不能从一个static内部类的一个对象访问一个外部类对象 4、&和&&的区别 答:&是位运算符,表示按位与运算,&&是逻辑运算符,表示逻辑与(and) 5、Collection 和 Collections的区别 答:Collection是集合类的上级接口,继承与他的接口主要有Set 和List. Collections是针对集合类的一个帮助类,他提供一系列静态方法实现对各种集合的搜索、排序、线程安全化等操作 6、什么时候用assert 答:assertion(断言)在软件开发中是一种常用的调试方式,很多开发语言中都支持这种机制。在实现中,assertion就是在程序中的一条语句,它对一个boolean表达式进行检查,一个正确程序必须保证这个boolean表达式的值为true;如果该值为false,说明程序已经处于不正确的状态下,系统将给出警告或退出。一般来说,assertion用于保证程序最基本、关键的正确

Java企业面试题填空题及标准答案

Java企业面试题填空题及答案

————————————————————————————————作者:————————————————————————————————日期:

Java填空题 1 一个Java源程序是由若干个类组成。 2 class 是Java的关键字,用来定义类。 3 Java应用程序中有多个类时,java命令后的类名必须是包含了main 方法的那个类的名字。 4 一个Java应用程序必须且只有一个类含有main 方法。 5 在一个Java应用程序中main方法必须被说明为public static void 。 6 Java中所有程序都使用方法,应用程序以main 方法开始。 7 Java源文件中有多个类,但只能有一个类是public 类。 8 Java源程序编译后生成的字节码文件扩展名为class 。 9 用来标识类名、变量名、方法名、类型名、数组名、文件名的有效字符序列称为标识符。 10 Java语言规定标识符由字母、下划线、美元符号和数字组成,并且第一个字符不能是数字。 11 关键字就是Java语言中已经被赋予特定意义的一些单词,不可以把这类词作为名字来用。 12 使用关键字boolean 来定义逻辑变量。 13 关键字就是Java语言中已经被赋予特定意义的一些单词。 14 结构化程序设计的基本数据类型包括逻辑类型、整数类型、字符类型、浮点类型。 15 Java中byte型数组在内存中的存储形式是补码。 16 对于int型变量,内存分配 4 个字节。 17 对于byte型变量,内存分配 1 个字节。 18 对于long型变量,内存分配8 个字节。 19 对于short型变量,内存分配 2 个字节。 20 结构化程序设计的基本数据类型包括整数类型、逻辑类型、字符类型、浮点类型。 21 使用关键字char 来定义字符变量。 22 结构化程序设计的基本数据类型包括字符类型、逻辑类型、整数类型、浮点类型。 23 java中,浮点型变量的类型有float和double 两种。 24 对于float型变量,内存分配 4 个字节。 25 对于double型变量,内存分配8 个字节。 26 结构化程序设计的基本数据类型包括浮点类型、逻辑类型、整数类型、字符类型。 27 Java使用Unicode 字符集。 28 混合运算中不同类型的数据先转化为同一类型,然后运算,其中不包括逻辑类型和字符类型。 29 混合运算中不同类型的数据先转化为同一类型,然后运算,其中不包括字符类型、逻辑类型。 30 当把级别高的变量的值赋予级别低的变量时,必须使用强制类型转换。 31 Java中关系运算符的运算结果是boolean 型。 32 Java中逻辑运算符的操作元必须是boolean 型数据。 33 整数类型数据在内存中以二进制的方式表示。 34 Java语言的控制语句有3种类型,即条件语句、循环语句、和转移语句。 35 Java中有两种类型的控制语句即if和switch 。 36 Java语言的控制语句有3种类型,即条件语句、循环语句、和转移语句。

2016最新java面试题 详细版

详解笔试面试题集 (1)下列各题ABCD四个选顼中,只有一个选项是正确的,请将正确选项填写在答题纸上 (1)下列关于栈的描述中错误的是( ) A. 栈是先进后出的线性表 B 栈只能顺序存储 C 栈具有记忆作用 D 对栈的插入弓删除操作中,不需要改变栈底指针 正确答案:B 分析:栈是链式存储的 (2)对于长度为n的线性表,在最坏情况下,下列各排序法所对应的比较次数中正确的是( ) A 冒泡排序为n/2 B 冒泡排序为n C 快速排序为n D 快速排序为n(n-l)/2 正确答案:D 分析: 想想快速排序,每次都会选取线性表的轴值,随后以此轴值划分为两个子线性表再分别进行快排,在最坏情况下,也就是说每次选出的线性表轴值完全不能将这个线性表划分为两个子线性表。那么此时快速排序退化为冒泡排序了。 那么第一趟排序时,轴值(线性表的中间位置)被选出,这个值绝对是这个线性表中最大的(不然也不能是最坏情况),其他值都比他小,那么线性表现在分为完全不对等的两段(一段是0,另一段是n - 1),一段是这个值,一段是其他值。同样第二趟排序在刚才剩下的值中选中间值(剩余值中最大的那个),又分为不对等两段,依次递推。也就是说每次都比较了N - 1个元素(轴值选出后都与它比较大小),那么肯定是比较了n - 1次(如第一次先挑了个轴值,然后剩下n - 1比较),n代表当前子线性表中元素个数由此最白痴的数列问题出现了,如下 1 + 2 + 3 + .......... + n - 2 + n - 1 = n(n - 1) / 2 还有一种投机取巧的方法,在最垃圾情况下既然快排变为冒泡,那由时间复杂度知其必为o(n ^ 2)的复杂度,答案中ABC都是线性时间复杂,显然错误 (3)下列对于线性链表的描述中正确的是( ) A 存储空间间不一定是连续,且各元素的存储顺序是任意的

2017年最新Java经典笔试面试题笔试题目及答案

2017年最新Java经典笔试面试题 2017年最新Java经典笔试面试题 想要成为java程序员可不是容易的事情,下面YJBYS小编为大家精心搜集了关于Java 经典笔试的面试题,欢迎大家参考借鉴,希望可以帮助到大家! 一.选择题(共50题,每题1.5分,共75分。多选题选不全或选错都不得分。) 1. 以下属于面向对象的特征的是(C,D)。(两项) A) 重载 B) 重写 C) 封装 D) 继承 2. 以下代码运行输出是(C) public class Person{ private String name=”Person”; int age=0; } public class Child extends Person{

public String grade; public static void main(String[] args){ Person p = new Child(); System.out.println(https://www.doczj.com/doc/146852706.html,); } } A) 输出:Person B) 没有输出 C) 编译出错 D) 运行出错 3. 在使用super 和this关键字时,以下描述正确的是(A) A) 在子类构造方法中使用super()显示调用父类的构造方法,super()必须写在子类构造方法的第一行,否则编译不通过 B) super()和this()不一定要放在构造方法内第一行 C) this()和super()可以同时出现在一个构造函数中

D) this()和super()可以在static环境中使用,包括static方法和static语句块 4. 以下对封装的描述正确的是(D) A) 只能对一个类中的方法进行封装,不能对属性进行封装 B) 如果子类继承了父类,对于父类中进行封装的方法,子类仍然可以直接调用 C) 封装的意义不大,因此在编码时尽量不要使用 D) 封装的主要作用在于对外隐藏内部实现细节,增强程序的安全性 5. 以下对继承的描述错误的是(A) A) Java中的继承允许一个子类继承多个父类 B) 父类更具有通用性,子类更具体 C) Java中的继承存在着传递性 D) 当实例化子类时会递归调用父类中的构造方法 6. 以下程序的运行结果是(D) class Person{ public Person(){ System.out.println(“this is a Person”);

相关主题
文本预览
相关文档 最新文档