文档库 最新最全的文档下载
当前位置:文档库 › java面试题-经典选择题部分

java面试题-经典选择题部分

java面试题-经典选择题部分
java面试题-经典选择题部分

1 、给出如下代码:

class Test{

private int m;

public static void fun() {

// some code...

}

}

如何使成员变量m 被函数fun() 直接访问? C

A 、将private int m 改为protected int m

B 、将private int m 改为public int m

C 、将private int m 改为static int m

D 、将private int m 改为int m

2 、下面哪个函数是public void example(){...} 的重载函数?D

A 、private void example( int m){...}

B 、public int example(){...}

C 、public void example2(){...}

D 、public int example ( int m, float f){...}

3 、给出下面的代码段:

public class Base{

int w, x, y ,z;

public Base(int a,int b)

{

x=a; y=b;

}

public Base(int a, int b, int c, int d)

{

// assignment x=a, y=b

w=d;

z=c;

}

}

在代码说明// assignment x=a, y=b 处写入如下哪个代码是正确的?D

A 、Base(a,b);

B 、x=a, y=b;

C 、this(a),this(b);

D 、this(a,b);

4 、已知如下定义:String s = "story";

下面哪个表达式是合法的?A

A 、s += "books";

B 、char c = s[1];

C 、int len = s.length;

D 、String t = 100;

5 、Java 中main() 函数的返回值是什么? D

A 、String

B 、int

C 、char

D 、void

6 、如下哪个字串在Java 中可作为自定义标识符? A

A 、$number

B 、super

C 、3number

D 、#number

7 、如下哪个不是Java 中有效的关键字? B

A 、const

B 、NULL

C 、false

D 、this

8 、如下哪个不是Java 中正确的整数表示? D

A 、22

B 、0x22

C 、022

D 、22H

9 、下面的代码段中,执行之后i 和j 的值是什么? C int i = 1;

int j;

j = i++;

A 、1, 1

B 、1, 2

C 、2, 1

D 、2, 2

10 、下面句话是正确的? A

A >> 是算术右移操作符.

B << 是算术右移操作符.

C >>> 是算术右移操作符

D <<< 是算术右移操作符

11 、下面哪个赋值语句不是合法的?A

A 、float a = 2.0

B 、double b = 2.0

C 、int c = 2

D 、long d = 2

12 、下面哪个是main() 函数的合法参数? C

A 、char args[]

B 、char args[][]

C 、String arg[]

D 、String args

13 、已知表达式int m[] = {0, 1, 2, 3, 4, 5, 6 };

下面哪个表达式的值与数组最大下标数相等?B

A 、m.length()

B 、m.length-1

C 、m.length()+1

D 、m.length+1

14.指出下列程序运行的结果(D)

public class Example{

String str=new String(″good″);

char[]ch={′a′,′b′,′c′};

public static void main(String args[]){

Example ex=new Example();

ex.change(ex.str,ex,ch);

System.out.print(ex.str+″and″);

System.out.print(ex.ch);

}

public void change(String str,char ch[]){

str=″test ok″;

ch[0]=′g′;

}

}

A.good and abc

B.good and gbc

C.test ok and abc

D.test ok and gbc

15 .函数重载是指( A)

A.两个或两个以上的函数取相同的函数名,但形参的个数或类型不同

B.两个以上的函数取相同的名字和具有相同的参数个数,但形参的类型可以不同

C.两个以上的函数名字不同,但形参的个数或类型相同

D.两个以上的函数取相同的函数名,并且函数的返回类型相同

16.在异常处理中,如释放资源、关闭文件、关闭数据库等由( C)来完成。

A.try子句

B.catch子句

C.finally子句

D.throw子句

17. 下面哪条语句定义了5个元素的数组( A )

A、int [] a={22,23,24,25,12};

B、int a []=new int(5);

C、int [5] array;

D、int [] arr;

18 、已知如下的命令执行java MyTest a b c 请问哪个语句是正确的?C

A 、args[0] = "MyTest a b c"

B 、args[0] = "MyTest"

C 、args[0] = "a"

D 、args[1]= 'c'

19. Applet类的直接父类是(D )

https://www.wendangku.net/doc/171222819.html,ponent类

B.Container类

C.Frame类

D.Panel类

20.对于catch子句的排列,下列哪种是正确的( B )

A.父类在先,子类在后

B.子类在先,父类在后

C.有继承关系的异常不能在同一个try程序段内

D.如何排列都可以

21. 下面哪个语句不能定义一个字符变量( B )

A、char c1=’a’;

B、char c2=” S ” ;

C、char c4=97 ;

D、char c3=’\u0041’;

22.构造方法何时被调用( B)

A.类定义时

B.创建对象时

C.调用对象方法时

D.使用对象的变量时

23.下面的表达式中正确的是( AE)

A.String s=″你好″;int i=3;s+=i;

B.String s=″你好″;int i=3;if(i==s){s+=i};

C.String s=″你好″;int i=3;s=i+s;

D.String s=″你好″;int i=3;s=i+;

24 、已知如下代码:

public class Test

{

long a[] = new long[10];

public static void main ( String arg[] ) {

System.out.println ( a[6] );

}

}

请问哪个情况是正确的? C

A 、输出为null.

B 、输出为0.

C 、编译时出错

D 、运行时出错

25 、Frame的默认的布局管理器是下列哪一个( B)

A.FlowLayout

B.BorderLayout

C.GridLayout

D.CardLayout

26.下列语句片段

int a=10,b=4,c=20,d=6;

System.out.println(a++*b+c*--d);

的结果为( C)

A.144

B.28

C.140

D.不能执行

27.下列语句片段:

int a=-67,b=116,c=78;

int d=~a|b&c;

System.out.println(d)的结果为( A)

A.70

B.67

C.78

D.56

28. 对象使用时,下面描述错误的是( B)

A.通过“.”运算符调用成员变量和方法

B.通过成员变量的访问权限设定限制自身对这些变量方法的调用

C.将一个对象申明为类的成员时,必须在使用前为其分配内存

D.在方法中使用对象作为参数时,采用引用调用

29. 执行下列代码后,哪个结论是正确的String[]s=new String[10]; B

A.s[10]为″″

B.s[9]为null

C.s[0]为未定义

D.s.length为101

30. Java编程所必须的默认引用包为(B )

A.java.sys包

https://www.wendangku.net/doc/171222819.html,ng包

C.java.new包

D.以上都不是

31.定义一个类名为“MyClass.java”的类,并且该类可被一个工程中的所有类访问,那么该类的正确声明应为:( C)

A.private class MyClass extends Object

B.class MyClass extends Object

C.public class MyClass

D.private class MyClass extends Object

32 、以下哪个方法用于定义线程的执行体? C

A 、start()

B 、init()

C 、run()

D 、main()

E 、synchronized()

33 如果类中的成员变量可以被同一包访问,则使用如下哪个约束符? D

A 、private

B 、public

C 、protected

D 、缺省

E 、final

34 、以下哪个约束符可用于定义成员常量? B

A 、static

B 、final

C 、abstract

D 、finally

35. 当方法遇到异常又不知如何处理时,下列哪种说法是正确的(B )

A.捕获异常

B.抛出异常

C.声明异常

D.嵌套异常

36. Java程序的执行过程中用到一套JDK工具,其中java.exe是指( C)

A.Java文档生成器

B.Java解释器

C.Java编译器

D.Java类分解器

37.下列不属于容器的是(B )

A.Window

B.TextBox

C.Panel

D.ScrollPane

38 、已知如下类说明:

public class Test {

private float f = 1.0;

int m = 12;

static int n=1;

public static void main(String arg[]) {

Test t = new Test();

// some code...

}

}

如下哪个使用是正确的?D

A 、t.f

B 、this.n

C 、Test.m

D 、Test.n

39 、已知如下代码:

1: class Example{

2: String str;

3: public Example(){

4: str= "example";

5: }

6: public Example(String s){

7: str=s;

8: }

9:}

10: class Demo extends Example{

11: }

12: public class Test{

13:public void f () {

14:Example ex = new Example("Good"); 15:Demo d = new Demo("Good"); 16:} }

哪句语句会导致错误?E

A 、line 3

B 、line 6

C 、line 10

D 、line 14

E 、line 15

40 、已知如下类定义:

class Base {

public Base (){ //... }

public Base ( int m ){ //... }

public void fun( int n ){ //... }

}

public class Child extends Base{

// member methods

}

如下哪句可以正确地加入子类中?D

A 、private void fun( int n ){ //...}

B 、void fun ( int n ){ //... }

C 、protected void fun ( int n ) { //... }

D 、public void fun ( int n ) { //... }

41 在如下源代码文件Test.java 中, 哪个是正确的类定义?B

A 、public class test {

public int x = 0;

public test(int x)

{

this.x = x;

}

}

B 、public class Test{

public int x=0;

public Test(int x) {

this.x = x;

}

}

C 、public class Test extends T1, T2 {

public int x = 0;

public Test (int x) {

this.x = x;

}

}

D、protected class Test extends T2{

public int x=0;

public Test(int x){

this.x=x;

}

}

42、当Frame 改变大小时,放在其中的按钮大小不变,则使用如下哪个layout? A

A 、FlowLayout

B 、CardLayout

C 、BorderLayout

D 、GridLayout

43 、如下哪个方法可以从WindowEvent 获取事件源? C

A 、getFrame()

B 、getID()

C 、getSource()

D 、getEvent()

44监听器接口的方法返回值是什么? C

A 、int

B 、String

C 、void

D 、Object

45下面哪个方法与applet 的显示无关? B

A 、update()

B 、draw()

C 、repaint()

D 、paint()

46下面哪个不是Java 中的容器? B

A 、ScrollPane

B 、Canvas

C 、Dialog

D 、Applet

47在Java中,属于整数类型变量的是( C)

A.single

B.double

C.byte

D.char

48下面哪个描述是正确的( C )

A、Applet程序中不需要main()方法,也不能有

B、Application程序中可以没有main()方法。

C、Applet程序中可以不定义init( )方法

D、Application程序中必须有run( )方法

49 给出一段程序,试判断哪个是正确的结果( B )public class rtExcept{

public static void throwit(){

System.out.print(“throwit”);

throw new RuntimeException(); }

public static void main(String [] aa){

try{

System.out.print(“hello “);

throwit(); }

catch(Exception re){

System.out.print(“caught ”); }

finally{

System.out.print(“finally ”); }

System.out.print(“after ”);

}

}

A、hello throwit caught

B、hello throwit caught finally after

C、hello throwit RuntimeException after

D、hello throwit caught finally after RuntimeException

50. 下列哪个方法可用于创建一个可运行的类( A)

A.public class X implements Runable{ public void run(){......} }

B.public class X implements Thread{ public void run(){......} }

C.public class X implements Thread{ public int run(){......} }

D.public class X implements Runable{ protected void run(){......} }

1.Which statement is true?

A.An anonymous inner class may be declared as final.

B.An anonymous inner class can be declared as private.

C.An anonymous inner class can implement multiple interfaces .

D.An anonymous inner class can access final variables in any enclosing scope.

E.Construction of an instance of a static inner class requires an instance of the enclosing outer class.

答案是D

anonymous inner class can not declared with any modifyer.

and can only implement one interface

2. Which statement about static inner classes is true?

A.An anonymous class can be declared as static

B.A static inner class cannot be a static member of the outer class

C.A static inner class does not require an instance of the enclosing class

D.Instance members of a static inner class can be referenced using the class name of the static inner class

答案是C

because static , it needn't instance of enclosing outer class

and it's instance member need it's instance.

3.public class Foo{

public static void main(String sgf[]){

StringBuffer a = new StringBuffer("A");

StringBuffer b = new StringBuffer("B");

operate(a,b);

System.out.println(a+","+b);

}

static void operate(StringBuffer x,StringBuffer y){

x.append(y);

y=x;

}

}

What is the result?

A.The code compiles and prints “A.B”.

B.The code compiles and prints “A.A”.

C.The code compiles and prints “B.B”.

D.The code compiles and prints “AB.B”.

E.The code compiles and prints “AB.AB”.

答案是D

java中都是按值传递的,所以a,b还是指向原来的地址空间,经过operate操作后,x更改了该地址空间的值,而y没有.

public class Foo{

public static void main(String sgf[]){

StringBuffer a = new StringBuffer("A");

StringBuffer b = new StringBuffer("B");

operate(a,b); //方法调用完以后,a对象的内容为:AB,b对象的内容为:B

System.out.println(a+","+b);

}

static void operate(StringBuffer x,StringBuffer y){

//对象传递进来以后又分别复制了一个x和y对象x'和y',

x'和x指向同一个对象。y'和y指向同一个对象。

x.append(y); //所以执行此步操作以后,main中的x对象的内容也变化了。

//因为本来就是指向同一个对象吗!

y=x; //执行此步操作以后,main中的y对象的内容没变!

//因为此y费彼y也!

}

}

class ValHold{

public int i = 10;

}

public class ObParm{

public static void main(String argv[]){

ObParm o = new ObParm();

o.amethod();

}

public void amethod(){

int i = 99;

ValHold v = new ValHold();

v.i=30;

another(v,i);

System.out.println(v.i);

}//End of amethod

public void another(ValHold v, int i){

i=0;

v.i = 20;

ValHold vh = new ValHold();

v = vh;

System.out.println(v.i+ " "+i);

}//End of another

}

1) 10,0, 30

2) 20,0,30

3) 20,99,30

4) 10,0,20

答案是4)

首先必须明白一点

参数传递到方法内的时候实际上是复制了一份

而且java并不直接处理对象,而是通过对象参考来处理的。

public static void main(String argv[]){

ObParm o = new ObParm();

o.amethod();

}

public void amethod(){

int i = 99;

ValHold v = new ValHold();

v.i=30;

another(v,i);

System.out.println(v.i);

}//End of amethod

public void another(ValHold v, int i){

//参数v,i传进来后进行复制,并且两个v都是指向同一个对象

i=0;

v.i = 20; //这里就导致所指向的对象的i值变化

ValHold vh = new ValHold();

v = vh; //这里改变了v的对象参考,指向新的一个ValHold对象

System.out.println(v.i+ " "+i);

}//End of another

}

W hich of the following statements is/are true? Choose all correct options.

A) At the moment a thread calls an object's wait() method, the thread must own

that object's lock.

B) At the moment a thread calls an object's wait() method, the thread loses that

object's lock.

C) At the moment a waiting thread is notified, it is given the lock of the object

for which it was

waiting.

D) At any moment, a thread may not be waiting for the lock of more than one object.

首先,可以肯定c是错误的。因为当一个thread被notify后,它只是从wait pool 转向object's lock pool,不一定马上能够拿到lock.

其次,a,b两项应该是正确的。当一个thread在call wait()之前,它手中拿着该object 的lock,当它call完wait( )之后,就把object's lock交出,排到wait pool里等待。Correct selection is: A, B, D

A and

B are true because the whole point of wait() is to force a thread that owns an object's lock to give up the lock and block.

C is false: the notified thread must now contend for the object's lock.

D is true because after the thread calls wait() on the first object, it is no longer running, so it cannot call wait() on another object.

Given the following code

class Base {}

class Agg extends Base{

public String getFields(){

String name = "Agg";

return name;

}

}

public class Avf{

public static void main(String argv[]){

Base a = new Agg();

//Here

}

}

What code placed after the comment //Here will result in calling the getFields method resulting in the output of the string "Agg"?

1) System.out.println(a.getFields());

2) System.out.println(https://www.wendangku.net/doc/171222819.html,);

3) System.out.println((Base) a.getFields());

4) System.out.println( ((Agg) a).getFields());

answer 1:a's reference type is Base ,not Agg,so method getFields not found ... Base a=new Agg(); change>>>> Agg a =new Agg(); compile correct.. answer 2:variable name not found..

answer 3:the reason is the same as answer1

answer 4:correct

W hich of the following thread state transitions are valid?

A From ready to running.

B From running to ready.

C From running to waiting.

D From waiting to running.

E From waiting to ready.

F From ready to waiting.

thread has four states:

ready, running, non-runnable(sleeping, waiting,Blocked),dead The relationship is shown as following

ready <-> running

running -> dead, non-runnable

non-runnable -> ready

so the answer is A,B,C,E

请看以下例子:

1.

public class Test{

public static void main(String argv[]){

Test t = new Test();

t.amothed();

}

void amothed(){

byte[] a;

System.out.println(a[0]);

}

}

编译时报错:变量a可能未被初始化。

2.

public class Test{

public static void main(String argv[]){

Test t = new Test();

t.amothed();

}

void amothed(){

byte[] a = new byte[5];

System.out.println(a[0]);

}

}

编译通过,输出0。

数组是会自动初始化的……这肯定没错……

但你必须先把它实例化……

int[] a;//定义一个整型数组,但尚未实例化……

a = new int[3];//实例化a,同时a的所有元素被初始化为0……

System.out.println(a[0]);

System.out.println(a[1]);

System.out.println(a[2]);

For the following code:

class Super

{ int index = 5;

public void printVal()

{ System.out.println( "Super" );

}

}

class Sub extends Super

{ int index = 2;

public void printVal()

{ System.out.println( "Sub" );

}

}

public class Runner

{ public static void main( String argv[] )

{ Super sup = new Sub();

System.out.print( sup.index + "," );

sup.printVal();

}

}

What will be printed to standard output?

The code compiles and "5, Sub" is printed to standard output.

1.

成员变量是编译时绑定,

Super sup = new Sub(); //这里声明sup为Super, 所以在编译时,就确定了sup.index=5 System.out.print( sup.index + "," ); //打印出5

成员函数则是动态绑定,

sup.printVal(); //尽管sup被声明为super,但是实际上是new Sub(),所以在运行时,sup实际上指向的一个Sub对象。由于是动态绑定,所以这里执行的是Sub的方法。

What happens when you try to compile and run the following program?

class Mystery {

String s;

public static void main(String[] args) {

Mystery m = new Mystery();

m.go();

}

void Mystery() {

s = "constructor";

}

void go() {

System.out.println(s);

}

}

Select the one right answer.

this code runs and writes "null" in the standard output

构造函数没有返回值,即在构造函数前面不要写任何东西,void也不能写(除了可以写public).

如果写了void或者其他返回类型,比如此例中的

void Mystery();//这时,这个函数已经不是构造函数了,而且一个普通的函数,尽管与类和构造函数同名,但是他已经是一个普通的函数了,返回类型是void.

也就是说在此例中,其实是没有显示的写出构造函数。所以s当然为空。

1)class A {

static int si=5;

static { System.out.println(si);}

A(){ si++;}

public static void main(String args[]) {

for (int i=0;i<3;i++)

new A();

}

}

参考答案:print out "5" once

当类加载的时候首先是初始化static类变量和执行static类方法,只有这一次机会。此时也许还没有一个类实例。以后所有对象都共享static变量。对static类变量的修改会影响到

所有的类实例。

2)class Z {

public static void main(String args[]) {

System.out.println("AAA"+new Z());

}

public String toString() {

System.out.println("###");

return "Z";

}

}

参考答案:"###" followed by "AAAZ"

要打印"AAA"+new Z(),就要先把他翻译成字符串,要想翻译成字符串就要先执行z.toString(),所以先遇到了打印“###”,于是打印了出来,然后z.toString()执行完毕,然后开始执行打印"AAA"+"z",顺序是这样的。

What is the result of attempting to compile and run the following program?

1. public class Test {

2. private int i = j;

3. private int j = 10;

4.

5. public static void main(String args[]) {

6. System.out.println((new Test()).i);

7. }

8. }

[Select one correct answer]

a. Compiler error complaining about access restriction of private variables of Test.

b. Compiler error complaining about forward referencing.

c. No error - The output is 0;

d. No error - The output is 10;

答案是: b

JAVA中类的编译顺序是只要建立了对象实例,即NEW,就会先初始化变量,在调用CONSTRUCTOR,而变量的初始化是必须按顺序的,所以,第一题选B

What is the output of the following program

1. public class Test {

2. private int i = giveMeJ();

3. private int j = 10;

4.

5. private int giveMeJ() {

6. return j;

7. }

8.

9. public static void main(String args[]) {

10. System.out.println((new Test()).i);

11. }

12. }

Select one correct answer

a. Compiler error complaining about access restriction of private variables of AQuestion.

b. Compiler error complaining about forward referencing.

c. No Compilation error - The output is 0;

d. No Compilation error - The output is 10;

答案是: c。生成test类,首先为i,j分配空间并初始化为0,然后执行i=giveMeJ(),这时j还是0,所以i的结果为0;然后执行j=10。所以最后输出为0。

Which two cannot directly cause a thread to stop executing?

A.exiting from a synchronized block

B.calling the wait method on an object

C.calling the notify method on an object

D.calling a read method on an InputStream object

E.calling the setPriority method on a thread object

Answer:CE

there are 7 possible for causing thread to stop executing:

1\exiting from synchronized block

2/calling the wait method on the object/

3\calling read method on the InputStream object

4/priorer thread enters ready state/

5\calling system.exit(0)

6/The thread executes a sleep() call

7\A call to the thread's stop method.

·2 ways to synchronize:

1.Synchronize the entire method

·Declare the method to be synchronized - very common practice.

·Thread should obtain the object’s lock.

2.Synchronize part of the method

·Have to pass an arbitrary object which lock is to be obtained to execute the synchronized code block (part of a method).

Synchronized(target) {statements}

·We can specify “this” in place object, to obtain very brief locking – not very common

·If target is null, then the NullPointerException is thrown.

Which of the following are correct, if you compile the following code?

public class CloseWindow extends Frame implements WindowListener {

public CloseWindow() {

addWindowListener(this); // This is listener registration

setSize(300, 300);

setVisible(true);

}

public void windowClosing(WindowEvent e) {

System.exit(0);

}

public static void main(String args[]) {

CloseWindow CW = new CloseWindow();

}

}

A) Compile time error

B) Run time error

C) Code compiles but Frames does not listen to WindowEvents

D) Compile and runs successfully

这道题考得很隐蔽,考你implement 抽象类,必须实例化里面所有的方法,由于没有都实例化,所以答案是A

先说抽象类吧,A类如果要继承抽象类B,那么A类必须对抽象类里的所有抽象方法实例化,即override这些抽象方法,同时去掉abstract 前缀。

WindowListener 是 interface,而接口里的方法默认都为抽象的,当然也就....

出题人认为:我们都应该猜到至少WindowListener有比如关闭..之类的方法,而此中没有对这些抽象方法实例话...so .....

Which statements about garbage collection are true?

Select all valid answers.

a) You can directly free the memory allocated by an object.

b) You can directly run the garbage collector whenever you want to.

c) The garbage collector informs your object when it is about to be garbage collected.

d) The garbage collector reclaims an object memory as soon as it becomes a candidate for garbage collection.

e) The garbage collector runs in low-memory situations.

答案是ade

对于声明为final类型的成员变量,可以在声明语句中进行初始化如

final int i=0;

也可以在类的构造函数中进行初始化,如果有多个构造函数,每个都必须进行初始化

class test{

final int i;

test(){

i=0;

}

}

甚至可以在类的初始化block中进行初始化,

class test{

final int i;

{

int i=0;

}

}

final变量只能初始化一次。

Which of the following statements are true?

1) The x,y coordinates of an instance of MouseEvent can be obtained using the getX() and getY() methods

2) The x,y coordinates of an instance of MouseEvent can be obtained using the X and Y integer fields

3) The time of a MouseEvent can be extracted using the getTime() method

4) The time of a MouseEvent can be extracted using the when parameter of the MouseEvent constructor

1,4.

What will happen if you compile/run the folowing lines of code?

1: Vector a = new Vector();

2:

3: a.addElement(10);

4:

5: System.out.println(a.elementAt(0));

A) Prints 10.

B) Prints 11.

C) Compilation error at line 3.

D) Prints some garbage.

答案是C。Vetor 接受的是一个对象,不是一个primitive type

Which statements describe guaranteed behavior of the garbage collection and finalization mechanisms?

1) Objects are deleted when they can no longer be accessed through any reference.

2) The finalize() method will eventually be called on every object.

3) The finalize() method will never be called more than once on an object.

4) An object will not be garbage collected as long as it is possible for an active part of the program to access it through a reference.

java基础笔试题(答案已整理)

Java基础试题 一:选择题(1*30=30)(题目写在答题纸上面) 1:Java 提供哪几种运算符多选( abcd )。 A)算术运算符B)位运算符 C)关系运算符D)逻辑运算符E)条件运算符 2:https://www.wendangku.net/doc/171222819.html,ng包的()方法比较二个对象是否相等返回true.。(b) A:toString() B:equals() C:compare D:以上都不正确 3:下列对Java 的变量与函数说法正确的是多选(ace )。 A)变量是用来保存数据的B)变量是用来实现操作过程的C)函数是用来实现操作过程的D)函数是用来保存数据的E)函数的参数是数据的入口 4:已知:int[] a = new int[100];在下列给出的数组元素中,非法的是。(d) A:a[0] B:a[1] C:a[99] D:a[100] 5:在java中,一个类可同时定义许多同名的方法,在这些方法的形式参数个数,类型或顺序各不相同,传值也可以各不相同。这种面向对象程序的特性称为。(c) A:隐藏B:覆盖C:重载D:Java不支持此特性 6:()是一组常量和抽象方法的集合。(d) A:实例B:类C:包D:接口 7:下面关于数组说法正确的是多选(abcde)。 A)一维数组实质上是相同类型变量的列表 B)创建一个数组首先定义数组变量所需的类型 C)char c[]=new char[26];可声明一个含有26 个元素的char型数组 D)当为一个多维数组的时候分配内存时,仅需要为第一指定内存,然后再分配其他维的存E)int twain[][] = new int[4][5];可声明一个二维数组 8:Java源文件和编译后的文件扩展名分别为。(b) A:.class和.java B:.java各.class C:.class和.class D:.java和.java 9:设x=5;则y=x--和y=--x的结果,使y分别为。(c) A:5,5 B:5,6 C:5,4 D:4,4 10:若x是float类变量,x=10/4;则x 的值是。(b) A:2 B:2.0 C:2,5 D:编译错误 11:.下面方法中,用于调度线程使其运行的是?多选(bc ) A. init() B. start() C. run() D. resume() E. sleep() 12.下面哪种情况能实现自动转换多选(ace )。 A)byte 型转换成int 型B)int 型转换成byte 型 C)float 型转换成double型D)double 型转换成int 型E)char型转换成int 型 13:下列那些是正确的JAVA字符串?多选(abd )。 A. "\"\"" B. "Oxzabc" C. "\"\" D. "\t\t\r\n" E. "boolean"5 14:在使用super 和this关键字时,以下描述正确的是。(a) A::在子类构造方法中使用super()显示调用父类的构造方法,super()必须写在子类构造方法的第一行,否则编译不通过 B:super()和this()不一定要放在构造方法内第一行

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 (一般是JA V A的说法)。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用于保证程序最基本、关键的正确性。assertion检查通常在开发和测试时开启。为了提高性能,在软件发布后,assertion检查通常是关闭的 7、String s = new String("xyz");创建了几个String Object 答:两个,一个字符对象,一个字符对象引用对象 8、Math.round(11.5)等於多少? Math.round(-11.5)等於多少 答: Math.round(11.5)==12;Math.round(-11.5)==-11;round方法返回与参数最接近的长整数,参数加1/2后求其floor 9、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错 答:short s1 = 1; s1 = s1 + 1; (s1+1运算结果是int型,需要强制转换类型)short s1 = 1; s1 += 1;(可以正确编译) 10、Java有没有goto 答:java中的保留字,现在没有在java中使用 11、数组有没有length()这个方法? String有没有length()这个方法 答:数组没有length()这个方法,有length的属性。String有有length()这个方法 12、Overload和Override的区别。Overloaded的方法是否可以改变返回值的类型

JAVA基础面试题经典

JAVA基础面试题经典

第一阶段题库 基础知识部分: 1.JDK是什么?JRE是什么? a)答:JDK:java开发工具包。JRE:java运行时 环境。 2.什么是java的平台无关性? a)答:Java源文件被编译成字节码的形式,无论 在什么系统环境下,只要有java虚拟机就能运行这个字节码文件。也就是一处编写,处处运行。这就是java的跨平台性。 3.在一台电脑上配置java环境,path起什么作 用?如何配置? a)答:path的作用是在DOS环境下,能在任意 位置使用JDK目录中bin文件夹中的可执行程序,来编译执行java程序。 b)在环境变量中找到path变量,把bin文件夹 的绝对路径加上即可。 4.什么样的标识符是合法的? a)由字母、数字、_和$组成,长度不限。其中字 母能够是大写或小写的英文字母,数字为0到9。

b)标识符的第一个字符不能是数字。 c)标识符区分大小写。 d)标识符不能包含空格。 5.Java有几种基本数据类型? a)byte,short,int,long,char,boolean,float,double 6.什么是隐式类型转换?什么是显示类型转换? a)当将占位数少的类型赋值给占位数多的类型 时,Java自动使用隐式类型转换。 b)当把在级别高的变量的值赋给级别底变量时, 必须使用显示类型转换运算。 7.&&和&区别,||和|区别? a)&&和||是短路与,短路或,当左边的表示式能 判断当前结果,则不判断右边的表示式。 b)而& 和|则将两边的表示式都运算完毕后,再 算结果。 8.break,continue区别? a)break结束最近的一个循环,continue结束当 次循环,进入下次循环。 9.类的命名规则是什么? a)如果类名使用拉丁字母,那么名字的首写字母 使用大写字母。

JAVA框架面试题汇总

1.SpringMVC Framework的理解: 1、它是基于组件技术的.全部的应用对象,无论控制器和视图,还是业务对象之类的都是java组件。并且和Spring提供的其他基础结构紧密集成 2、不依赖于Servlet API(目标虽是如此,但是在实现的时候确实是依赖于Servlet的) 3、可以任意使用各种视图技术,而不仅仅局限于JSP 4、支持各种请求资源的映射策略 5、它应是易于扩展的 2.简单的谈一下SpringMVC的工作流程? 流程? 1、用户发送请求至前端控制器DispatcherServlet? 2、DispatcherServlet收到请求调用HandlerMapping处理器映射器。? 3、处理器映射器找到具体的处理器,生成处理器对象及处理器拦截器(如果有则生成)一并返回给DispatcherServlet。? 4、DispatcherServlet调用HandlerAdapter处理器适配器? 5、HandlerAdapter经过适配调用具体的处理器(Controller,也叫后端控制器)。? 6、Controller执行完成返回ModelAndView? 7、HandlerAdapter将controller执行结果ModelAndView返回给DispatcherServlet? 8、DispatcherServlet将ModelAndView传给ViewReslover视图解析器? 9、ViewReslover解析后返回具体View? 10、DispatcherServlet根据View进行渲染视图(即将模型数据填充至视图中)。? 11、DispatcherServlet响应用户 3.如何解决POST请求中文乱码问题,GET的又如何处理呢? 在web.xml中加入: . .CharacterEncodingFilter . .???? .????????encoding .?????? utf-8

java面试题-经典选择题部分

1 、给出如下代码: class Test{ private int m; public static void fun() { // some code... } } 如何使成员变量m 被函数fun() 直接访问? C A 、将private int m 改为protected int m B 、将private int m 改为public int m C 、将private int m 改为static int m D 、将private int m 改为int m 2 、下面哪个函数是public void example(){...} 的重载函数?D A 、private void example( int m){...} B 、public int example(){...} C 、public void example2(){...} D 、public int example ( int m, float f){...} 3 、给出下面的代码段: public class Base{ int w, x, y ,z; public Base(int a,int b) { x=a; y=b; } public Base(int a, int b, int c, int d) { // assignment x=a, y=b w=d; z=c; } } 在代码说明// assignment x=a, y=b 处写入如下哪个代码是正确的?D A 、Base(a,b); B 、x=a, y=b; C 、this(a),this(b); D 、this(a,b); 4 、已知如下定义:String s = "story"; 下面哪个表达式是合法的?A A 、s += "books"; B 、char c = s[1]; C 、int len = s.length;

2019最新Java面试题,常见面试题及答案汇总

ava最新常见面试题+ 答案汇总 1、面试题模块汇总 面试题包括以下十九个模块:Java 基础、容器、多线程、反射、对象拷贝、Java Web 模块、异常、网络、设计模式、Spring/Spring MVC、Spring Boot/Spring Cloud、Hibernate、Mybatis、RabbitMQ、Kafka、Zookeeper、MySql、Redis、JVM 。如下图所示: 可能对于初学者不需要后面的框架和JVM 模块的知识,读者朋友们可根据自己的情况,选择对应的模块进行阅读。 适宜阅读人群 需要面试的初/中/高级java 程序员 想要查漏补缺的人 想要不断完善和扩充自己java 技术栈的人 java 面试官 具体面试题 下面一起来看208 道面试题,具体的内容。 一、Java 基础 1.JDK 和JRE 有什么区别? 2.== 和equals 的区别是什么? 3.两个对象的hashCode()相同,则equals()也一定为true,对吗? 4.final 在java 中有什么作用? 5.java 中的Math.round(-1.5) 等于多少? 6.String 属于基础的数据类型吗? 7.java 中操作字符串都有哪些类?它们之间有什么区别? 8.String str="i"与String str=new String(“i”)一样吗? 9.如何将字符串反转? 10.String 类的常用方法都有那些? 11.抽象类必须要有抽象方法吗? 12.普通类和抽象类有哪些区别? 13.抽象类能使用final 修饰吗?

14.接口和抽象类有什么区别? 15.java 中IO 流分为几种? 16.BIO、NIO、AIO 有什么区别? 17.Files的常用方法都有哪些? 二、容器 18.java 容器都有哪些? 19.Collection 和Collections 有什么区别? 20.List、Set、Map 之间的区别是什么? 21.HashMap 和Hashtable 有什么区别? 22.如何决定使用HashMap 还是TreeMap? 23.说一下HashMap 的实现原理? 24.说一下HashSet 的实现原理? 25.ArrayList 和LinkedList 的区别是什么? 26.如何实现数组和List 之间的转换? 27.ArrayList 和Vector 的区别是什么? 28.Array 和ArrayList 有何区别? 29.在Queue 中poll()和remove()有什么区别? 30.哪些集合类是线程安全的? 31.迭代器Iterator 是什么? 32.Iterator 怎么使用?有什么特点? 33.Iterator 和ListIterator 有什么区别? 34.怎么确保一个集合不能被修改?

百一测评——Java经典面试题 带答案

职业技能题库&在线云笔试平台https://www.wendangku.net/doc/171222819.html, 试卷名称:Java经典面试题带答案 试卷描述:java笔试题目、招聘笔试、微信考试、在线考试 试卷链接:https://www.wendangku.net/doc/171222819.html,/store/open/paperInfo/41651 试卷限时:50分 一.单项选择题 每题分值:2.5分 是否题目乱序:是 是否选项乱序:是 是否可回溯:是 难度:中 1.[单选]Java是从()语言改进重新设计。 A.Ada B.C++ C.Pasacal D.BASIC 答案:B 2.[单选]下列语句哪一个正确() A.Java程序经编译后会产生machine code B.Java程序经编译后会产生byte code C.Java程序经编译后会产生DLL D.以上都不正确

职业技能题库&在线云笔试平台https://www.wendangku.net/doc/171222819.html, 答案:B 3.[单选]下列说法正确的有() A.class中的constructor不可省略 B.constructor必须与class同名,但方法不能与class同名 C.constructor在一个对象被new时执行 D.一个class只能定义一个constructor 答案:C 4.[单选]提供Java存取数据库能力的包是() A.java.sql B.java.awt C.https://www.wendangku.net/doc/171222819.html,ng D.java.swing 答案:A 5.[单选]下列运算符合法的是() A.&& B.<> C.if D.:= 答案:A 6.[单选]执行如下程序代码 a=0;c=0;

职业技能题库&在线云笔试平台https://www.wendangku.net/doc/171222819.html, 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.形式参数不可以是对象

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.wendangku.net/doc/171222819.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的有()

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.wendangku.net/doc/171222819.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”);

java面试题大全(整理版)

2018年(整理版) 1、面向对象的特征有哪些方面? - 抽象:抽象是将一类对象的共同特征总结出来构造类的过程,包括数据抽象和行为抽象两方面。抽象只关注对象有哪些属性和行为,并不关注这些行为的细节是什么。 - 继承:继承是从已有类得到继承信息创建新类的过程。提供继承的类叫父类(超类、基类)、得到继承的类叫子类(派生类)。 - 封装:通常认为封装是把数据和操作数据的方法绑定起来,对数据的访问只能通过已定义的接口。可以说,封装就是隐藏一切可隐藏的东西,只向外界提供最简单的编程接口(可以想想普通洗衣机和全自动洗衣机的差别,明显全自动洗衣机封装更好因此操作起来更简单;我们现在使用的智能手机也是封装得足够好的,因为几个按键就搞定了所有的事情)。 - 多态性:多态性是指允许不同子类型的对象对同一消息作出不同的响应。简单的说就是用同样的对象引用调用同样的方法但是做了不同的事情。实现多态需要做两件事:1). 方法重写(子类继承父类并重写父类中的方法);2). 对象造型(用父类型引用引用子类型对象,

这样同样的引用调用同样的方法就会根据子类对象的不同而表现出不同的行为) 2、访问修饰符public,private,protected,以及不写(默认)时的区别? 3、String 是最基本的数据类型吗? 答:不是。Java中的基本数据类型只有8个:byte、short、int、long、float、double、char、boolean;除了基本类型(primitive type)和枚举类型(enumeration type),剩下的都是引用类型(reference type)。 4、float f=3.4;是否正确? 答:不正确。3.4是双精度数,将双精度型(double)赋值给浮点型(float)属于下转型(down-casting,也称为窄化)会造成精度损失,因此需要强制类型转换float f =(float)3.4; 或者写成float f =3.4F;。

Java面试经典试题及答案

Java面试经典试题及答案 第一,谈谈final, finally, finalize的区别。 final—修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承。因此一个类不能既被声明为 abstract的,又被声明为final的。将变量或方法声明为final,可以保证它们在使用中不被改变。被声明为final的变量必须在声明时给定初值,而在以后的引用中只能读取,不可修改。被声明为final的方法也同样只能使用,不能重载。 finally—再异常处理时提供 finally 块来执行任何清除操作。如果抛出一个异常,那么相匹配的 catch 子句就会执行,然后控制就会进入 finally 块(如果有的话)。 finalize—方法名。Java 技术允许使用 finalize() 方法在垃圾收集器将对象从内存中清除出去之前做必要的清理工作。这个方法是由垃圾收集器在确定这个对象没有被引用时对这个对象调用的。它是在 Object 类中定义的,因此所有的类都继承了它。子类覆盖 finalize() 方法以整理系统资源或者执行其他清理工作。finalize() 方法是在垃圾收集器删除对象之前对这个对象调用的。 第二,Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 匿名的内部类是没有名字的内部类。不能extends(继承) 其它类,但一个内部类可以作为一个接口,由另一个内部类实现。 第三,Static Nested Class 和 Inner Class的不同,说得越多越好(面试题有的很笼统)。 Nested Class (一般是C++的说法),Inner Class (一般是JA V A的说法)。Java内部类与C++嵌套类最大的不同就在于是否有指向外部的引用上。具体可见http: //https://www.wendangku.net/doc/171222819.html,/articles/services/view.asp?id=704&page=1 注:静态内部类(Inner Class)意味着1创建一个static内部类的对象,不需要一个外部类对象,2不能从一个static 内部类的一个对象访问一个外部类对象 第四,&和&&的区别。 &是位运算符。&&是布尔逻辑运算符。 第五,HashMap和Hashtable的区别。 都属于Map接口的类,实现了将惟一键映射到特定的值上。 HashMap 类没有分类或者排序。它允许一个 null 键和多个 null 值。 Hashtable 类似于 HashMap,但是不允许 null 键和 null 值。它也比 HashMap 慢,因为它是同步的。 第六,Collection 和 Collections的区别。 Collections是个java.util下的类,它包含有各种有关集合操作的静态方法。Collection是个java.util下的接口,它是各种集合结构的父接口。

这76道Java面试题及答案

这76道Java面试题及答案,祝你能成功通过面试 1、一个".java"源文件中是否可以包括多个类(不是内部类)?有什么限制? 可以有多个类,但只能有一个public的类,并且public的类名必须与文件名相一致。 2、Java有没有goto? java中的保留字,现在没有在java中使用。 3、说说&和&&的区别。 &和&&都可以用作逻辑与的运算符,表示逻辑与(and),当运算符两边的表达式的结果都为true时,整个运算结果才为true,否则,只要有一方为false,则结果为false。 &&还具有短路的功能,即如果第一个表达式为false,则不再计算第二个表达式。 &还可以用作位运算符,当&操作符两边的表达式不是boolean类型时,&表示按位与操作。 4、在JAVA中如何跳出当前的多重嵌套循环? 在Java中,要想跳出多重循环,可以在外面的循环语句前定义一个标号,然后在里层循环体的代码中使用带有标号的break语句,即可跳出外层循环。

5、switch语句能否作用在byte上,能否作用在long上,能否作用在String 上? 在switch(expr1)中,expr1只能是一个整数表达式或者枚举常量(更大字体),整数表达式可以是int基本类型或Integer包装类型,由于,byte,short,char 都可以隐含转换为int,所以,这些类型以及这些类型的包装类型也是可以的。显然,long和String类型都不符合switch的语法规定,并且不能被隐式转换成int类型,所以,它们不能作用于swtich语句中。 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 对于short s1 = 1; s1 = s1 + 1;由于s1+1运算时会自动提升表达式的类型,所以结果是int型,再赋值给short类型s1时,编译器将报告需要强制转换类型的错误。 对于short s1 = 1; s1 += 1;由于 +=是java语言规定的运算符,java编译器会对它进行特殊处理,因此可以正确编译。 7、char型变量中能不能存贮一个中文汉字?为什么? char型变量是用来存储Unicode编码的字符的,unicode编码字符集中包含了汉字,所以,char型变量中当然可以存储汉字啦。不过,如果某个特殊的汉字没有被包含在unicode编码字符集中,那么,这个char型变量中就不能存储这个特殊汉字。补充说明:unicode编码占用两个字节,所以,char类型的变量也是占用两个字节。 8、用最有效率的方法算出2乘以8等於几? 2 << 3,

java面试题集(面霸必备)

Java选择题测试 试题1 指出下面语句没有编译错误的是()。 A. long n = 999999999999; B.int n = 999999999999L; C. long n = 999999999999L; D. double n = 999999999999; 试题2 完成代码计算10的阶乘并输出,应该填入的代码是()long result = 1; for(int i = 2; i <= 10; i++) { < 填入代码> } System.out.println(“result= ” + result); ……… A. result = result * i; B. result = i*i; C. result = i*(i+1); D. reslut = i*(i-1); 试题3 下列关于数组的声明错误的是( ) A.int[] arry = new int[100]; B. int[3] arry = {1,2,3} C. int[] arry = new int[]{1,2,3} D. int[][] arry = new int[3][] 试题4 实现对数组arry的冒泡排序,应填入的代码是( )

public static void bubbleSort(int[] arry) { int len = arry.length; for (int i = 1; i < len; i++) { boolean asc = true; < 填入代码> if (asc) return; } } private static void swap(int[] arry, int i, int j) { int temp = arry[i]; arry[i] = arry[j]; arry[j] = temp; } A. for (int j = len-1; j > i; j–) { if (arry[j] < arry[j - 1]) { swap(arry, j, j – 1); asc = false; } } B. for (int j = len – 1; j >= i; j–) { if (arry[j] < arry[j - 1]) { swap(arry, j, j – 1); asc = false; } } C. for (int j = len – 1; j >= i; j–) {

Java经典面试笔试题及答案

1.什么是对象序列化,为什么要使用? 所谓对象序列化就是把一个对象以二进制流的方式保存到硬盘上。好处:方便远程调用。 2.值传递与引用传递的区别? 所谓值传递就是把一个对象的值传给一个新的变量,但是系统会给这个新的变量开辟一个新的内存空间。不会改变原有的值所谓引用传递就是把一个对象在堆中保存的数据传递给一个变量,此时新的变量与原有的变量对应同一个内存存储空间,当新的变量修改对象的属性时,内存中的数据也会修改。 3.接口与抽象类的区别? 1:接口里面不可以实现方法体,抽象类可以实现方法体。 2:接口可以多继承接口,抽象类不可以。 3:接口需要被子类实现,抽象类是要被子类继承(单一继承)。 4:接口中只能有公有的方法和属性而且必须赋初始值,抽象类中可以有私有方法和属性. 5: 接口中不能存在静态方法,但属性可以和final,抽象类中方法中可以有静态方法,属性也可以。 4.谈谈继承,为什么要使用继承? 所谓继承就是找出几个类中共同的部分,提取出来作为父类。而子类只需要继承父类,就可以共享父类的方法。 使用继承能够减少重复的代码。 5.方法重载的好处?

所谓重载就是在一个类中可以定义多个相同的方法,但是方法的参数类型和参数的个数以及顺序要不同。 重载的好处就是能够让我们很快的掌握该方法的功能,我们只要要记住该方法就能很快的理解该方法的参数以及参数的作用 6.项目中印象最深的部分? 我觉得在该项目中我体现到了反射技术的强大之处,原来我一直不清楚反射是一种什么样的技术,只知道一些概念上的知识,经过这个项目之后,终于知道该怎样灵活运用反射,以及在什么时候运用。 谈谈你对面向对象的理解与认识? 我觉得使用面向对象这种思维的方式比较符合我们人类的思想,不需要去学习一些什么新的思考方式,就按照现实生活做的一些故事就能让人理解该内容的知识以及他们的作用。 我的看法就是: 1:当加入新的功能的时候不会修改原有的代码。(面向接口编程) 2: 当我们写的一个类可以重复的运用在其他项目中。(代码的复用性) 3:当写一个新类的时候要考虑到他的可扩展性。(灵活性) 7.谈谈集合框架? 集合框架分为三部分,第一部分是collection接口,第二部分是Map接口、第三部分是collections帮助类 首先说一下collection接口,collection接口下面的接口分为set 接口、list接口,在往下面就是他们一些实现类。

JAVA基础面试题(经典)

基础知识部分: 1. JDK是什么?JRE是什么? a) 答:JDK:java开发工具包。JRE:java运行时环境。 2. 什么是java的平台无关性? a) 答:Java源文件被编译成字节码的形式,无论在什么系统环境下,只要有java虚拟机就能运行这个字节码文件。也就是一处编写,处处运行。这就是java的跨平台性。 3. 在一台电脑上配置java环境,path起什么作用?如何配置? a) 答:path的作用是在DOS环境下,能在任意位置使用JD K目录中bin文件夹中的可执行程序,来编译执行java程序。 b) 在环境变量中找到path变量,把bin文件夹的绝对路径加上即可。

4. 什么样的标识符是合法的? a) 由字母、数字、_和$组成,长度不限。其中字母可以是大写或小写的英文字母,数字为0到9。 b) 标识符的第一个字符不能是数字。 c) 标识符区分大小写。 d) 标识符不能包含空格。 5. Java有几种基本数据类型? a) byte,short,int,long,float,double,char,bool ean 6. 什么是隐式类型转换?什么是显示类型转换? a) 当将占位数少的类型赋值给占位数多的类型时,Java自动使用隐式类型转换。

b) 当把在级别高的变量的值赋给级别底变量时,必须使用显示类型转换运算。 7. &&和&区别,||和|区别? a) &&和||是短路与,短路或,当左边的表达式能判断当前结果,则不判断右边的表达式。 b) 而& 和|则将两边的表达式都运算完毕后,再算结果。 8. break,continue区别? a) break结束所有循环,continue结束当次循环,进入下次循环。 9. 类的命名规则是什么? a) 如果类名使用拉丁字母,那么名字的首写字母使用大写字母。

java高级软件工程师面试题

java高级软件工程师面试题 招聘java高级工程师,职位描述如下,有兴趣的加394504340交流,打扰了,谢谢! 职位名称:java高级开发工程师(急) 职位描述:互联网产品的开发和维护。 职位要求:1. 熟悉JAVA、J2EE体系结构,熟练掌握Spring、Struts、Hibernate、ibatis 的开发技术。 2. 熟悉MySql等数据库开发,熟练掌握SQL语句,有较好的数据库设计能力。 3. 熟练掌握HTML、javascript、ajax等web开发技术,熟悉http协议。 4. 熟悉SVN、Maven、Junit等工具。 5. 具有良好的学习能力、沟通能力,乐于承担工作压力。 6. 有大型门户或社区网站开发经验者优先。 职位所在城市:杭州 职位所在行业:高科技 -------------------------========================================================= 1.说一下struts中常用的对象 2.怎样整合apatche和tomcat 3.说一下在linx系统中搭建服务器 4.简述一下sql server 建模 5.请写一个程序,把一个10进制转换成16进制 6.表student 列id name age WA(本科以上,大专,高中,初中以下) 毕业学校ID,学校信息表 问:统计出文化学历本科以上,大专,高中,初中以下,每个年龄各有多少人(一条SQL语句) 7.有两位少年从隧道的一端向另一端行走.当他们走过隧道的五分之二时,发现隧道外面迎来一辆火车.火车很快就要进入隧道.两位少年向来时隧道跑去.两位少年都是每小时10公里.两位在千钧一发跑出了隧道.假设火车速度恒定,并且两位少年都在瞬间达到最大速度,请问火车的速度 8.请写出常用的oracle语句及说明,存储过程的语句及说明 ---------------------------------------------------------------------------------------------------------------------------------

Java经典笔试题01

1. Given: 1. public class test ( 2. public static void main (String args[]) { 3. int i = 0xFFFFFFF1; //0001 4. int j = ~i;//1110,取反 5. 6. } 7. ) What is the decimal value of j at line 5? A. 0 B. 1 C. 14 D. -15 E. An error at line 3 causes compilation to fail. F. An error at line 4 causes compilation to fail. 2. Given: Integer i = new Integer (42); Long 1 = new Long (42); Double d = new Double (42.0); Which two expressions evaluate to True? (Choose Two) A. (i ==1) B. (i == d) C. (d == 1) D. (i.equals (d)) E. (d.equals (i)) F. (i.equals (42))

3. Click the exhibit button: 1. public class test ( 2. private static int j = 0; 3. 4. private static boolean methodB(int k) ( 5. j += k; 6. return true; 7. ) 8. 9. public static void methodA(int i) { 10. boolean b; 11. b = i < 10 | methodB (4);//非短路 12. b = i < 10 || methodB (8);//短路,后面不执行 13. ) 14. 15. public static void main (String args[] } ( 16. methodA (0); 17. system.out.printIn(j); 18. ) 19. ) What is the result? A. The program prints “0” B. The program prints “4” C. The program prints “8” D. The program prints “12” E. The code does not complete 4. Given: 1.Public class test ( 2. Public static void main (String args[]) ( 3. System.out.printIn (6 ^ 3); //0110 ^ 0011 = 0101 4. ) 5.) What is the output? 5 1.Which statement is correctly declare a variable a which is suitable for refering to an array of 50 string empty object? (长度为50的空数组引用) A. String [] a B. String a[]

相关文档
相关文档 最新文档