JAVA 면접 문제 집(상)
1.C++ Java 。
JAVA JAVA ,JAVA 。 2 。 JAVA 。 , IndexOutOfBoundsException; null NullPointerException。 JAVA , , throw 。 java.lang.Thowable 。
2. Java C++ 。
Java , , 。 , , 。 , , public static, public. 。
3. 。 2 。
Java , c++ , Java 。 ,Java " " , " "。 , 。 , , 。 , 。
4. 。
wait(): , lock。
sleep(): , , InterruptedException 。
notify(): , , , JVM , 。
Allnotity(): , , 。
5. 。
6. Error Exception ?
Error ,
Exception 。
7. java final , ?
, 。
8. 。
9. heap stack 。
, 。 。
10. ( long ), )。
public class BigInt()
{
int[] ArrOne = new ArrOne[1000];
String intString="";
public int[] Arr(String s)
{
intString = s;
for(int i=0;i<ArrOne.leght;i++)
{
11. , (Point,Line,Rectangle,Triiangles)
12, final, finally, finalize 。
final— ( ) final, , 。 abstract , final 。 final, 。 final , , 。 final , 。
finally— finally 。 , catch , finally ( )。
finalize— 。Java finalize() 。 。 Object , 。 finalize() 。finalize() 。
13,Anonymous Inner Class ( ) extends( ) , implements( )interface( )?
。 extends( ) , , 。
14,Static Nested Class Inner Class , ( )。
Nested Class ( C++ ),Inner Class ( JAVA )。Java C++ 。 http: //www.frontfree.net/articles/services/view.asp?id=704&page=1
: (Inner Class) 1 static , ,2 static
,& && 。
& 。&& 。
15,HashMap Hashtable 。
Map , 。
HashMap 。 null null 。
Hashtable HashMap, null null 。 HashMap , 。
16,Collection Collections 。
Collections java.util , 。
Collection java.util , 。
17, assert。
, true。 false, Assertionerror。 :
assert(a > 0); // throws an Assertionerror if a <= 0
:
assert Expression1 ;
assert Expression1 : Expression2 ;
Expression1 。
Expression2 。 String 。
。 , source 1.4 :
javac -source 1.4 Test.java
, -enableassertions -ea 。
, -da -disableassertions 。
, -esa -dsa 。 。
。 。 , , , 。 , , 。 , 。
18,GC ? GC? ( )。
GC 。Java , 。 , :
System.gc()
Runtime.getRuntime().gc()
19,String s = new String("xyz"); String Object?
, "xyx", "xyx" s。
20,Math.round(11.5) ? Math.round(-11.5) ?
Math.round(11.5) (long)12,Math.round(-11.5) (long)-11;
21,short s1 = 1; s1 = s1 + 1; ? short s1 = 1; s1 += 1; ?
short s1 = 1; s1 = s1 + 1; ,s1 short ,s1+1 int , short 。 s1 =(short)(s1 + 1) 。short s1 = 1; s1 += 1 。
22,sleep() wait() ?
sleep() 。 sleep , 。 , , (a)" " (b) 。
wait() , x wait() , , , 。
23,Java goto?
Goto—java , java 。
24, length() ? String length() ?
length() , length 。
String length() 。
25,Overload Override 。Overloaded ?
Overriding Overloading Java 。 Overriding , Overloading 。 , (Overriding)。 , , , " " 。 , , (Overloading)。Overloaded 。
26,Set , ? == equals()? ?
Set , iterator() 。equals() Set 。
equals() == equals() , , 。
27, runtime exception。
ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException,
ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFORMatException, SecurityException, SystemException, UndeclaredThrowableException, UnmodifiableSetException, UnsupportedOperationException
28,error exception ?
error 。 。 。
exception 。 , , 。
29,List, Set, Map Collection ?
List,Set ,Map
30,abstract class interface ?
(abstract class), , , 。 abstract 。 , , 。 。Abstract , 。 , 。 。
(interface) 。 , 。 。 , 。 static final 。 , 。 , ( ) 。 , 。 , 。 。 ,instanceof 。
31,abstract method static, native, synchronized?
32, ? (implements) ? (concrete class)?
。 (implements) , , 。
33, run() start()?
start() , , JVM 。 。run() 。
34, Constructor override?
Constructor , Overriding, Overloading。
35, String ?
String final 。
36, synchronized , ?
, synchronized 。
37,try {} return , try finally {} code , , return ?
, return 。
38, : 2 8 ?
C 。
2 << 3
39, (x.equals(y) == true), hash code, ?
, hash code。
40, , , , ?
。Java 。 , 。 , 。
41,swtich byte , long , String ?
switch(expr1) ,expr1 。 switch case int、 short、 char byte。long,string swtich。
42, : Singleton 。
Singleton Java , Class 。
Singleton :
: , private , static private , , public getInstance , 。
public class Singleton {
private Singleton(){}
// , ?
// private
private static Singleton instance = new Singleton();
// class ,
public static Singleton getInstance() {
return instance;
}
}
:
public class Singleton {
private static Singleton instance = null;
public static synchronized Singleton getInstance() {
// , ,
// , !
if (instance==null)
instance=new Singleton();
return instance; }
}
:
, private , static 。
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 , 。
43. JVM class ?
44. ?
45. java , , .
46. java ?
47. C , java 。
48、 , , ;
49、 ;
50、 ;
51、 ;
52、 ;
53、 ?
54、 , "END" , ;
55、 public,private,protected,
: :
package package
public √ √ √ √
protected √ √ √ ×
friendly √ √ × ×
private √ × × ×
friendly
56、ArrayList Vector ,HashMap Hashtable
: ArrayList Vector .
. :Vector , , ArrayList ,
. : ,Vector , ArrayList
HashMap HashTable 。
. :Hashtable Dictionary ,HashMap Java 1.2 Map
. :Hashtable , , HashMap ,
. : HashMap key value
57、char ? ?
: , java unicode , char 16 ,
58、 , ? , ?
: , Thread Runnable
, synchronized,wait notify
59、 , ?
,
60、float float f=3.4 ?
: 。 , , :float f=(float)3.4
61、 JAVA Collection FrameWork( )?
:Collection FrameWork :
Collection
├List
│├LinkedList
│├ArrayList
│└Vector
│ └Stack
└Set
Map
├Hashtable
├HashMap
└WeakHashMap
Collection , Collection Object, Collection (Elements)
Map key value
62、Java , ?
11、JAVA ?
,
63、 ?
: , (JAVA ) , ( )。
:
1. n , , ;
;
, , ,
reset
(1) public static String[] splitStringByComma(String source){
if(source==null||source.trim().equals(""))
return null;
StringTokenizer commaToker = new StringTokenizer(source,",");
String[] result = new String[commaToker.countTokens()];
int i=0;
while(commaToker.hasMoreTokens()){
result[i] = commaToker.nextToken();
i++;
}
return result;
}
String
Integer.parseInt(String s) int
int
Arrays.sort(int[] a),
a
2. , :
(¥1011)->( ) 。
3、 , , ?
: :
package test;
public class FatherClass
{
public FatherClass()
{
System.out.println("FatherClass Create");
}
}
:
package test;
import test.FatherClass;
public class ChildClass extends FatherClass
{
public ChildClass()
{
System.out.println("ChildClass Create");
}
public static void main(String[] args)
{
FatherClass fc = new FatherClass();
ChildClass cc = new ChildClass();
}
}
:
C:>java test.ChildClass
FatherClass Create
FatherClass Create
ChildClass Create
4、 ?
: :
package test;
public class OuterClass
{
private class InterClass
{
public InterClass()
{
System.out.println("InterClass Create");
}
}
public OuterClass()
{
InterClass ic = new InterClass();
System.out.println("OuterClass Create");
}
public static void main(String[] args)
{
OuterClass oc = new OuterClass();
}
}
:
C:>java test/OuterClass
InterClass Create
OuterClass Create
:
public class OuterClass {
private double d1 = 1.0;
//insert code here
}
You need to insert an inner class declaration at line 3. Which two inner class declarations are
valid?(Choose two.)
A. class InnerOne{
public static double methoda() {return d1;}
}
B. public class InnerOne{
static double methoda() {return d1;}
}
C. private class InnerOne{
double methoda() {return d1;}
}
D. static class InnerOne{
protected double methoda() {return d1;}
}
E. abstract class InnerOne{
public abstract double methoda();
}
:
. , 。 A、B
. , ;return d1 。
D
. 。 C
. C、E
5、Java , ( ), JAVA SOCKET , , ?
:Server :
package test;
import java.net.*;
import java.io.*;
public class Server
{
private ServerSocket ss;
private Socket socket;
private BufferedReader in;
private PrintWriter out;
public Server()
{
try
{
ss=new ServerSocket(10000);
while(true)
{
socket = ss.accept();
String RemoteIP = socket.getInetAddress().getHostAddress();
String RemotePort = ":"+socket.getLocalPort();
System.out.println("A client come in!IP:"+RemoteIP+RemotePort);
in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
String line = in.readLine();
System.out.println("Cleint send is :" + line);
out = new PrintWriter(socket.getOutputStream(),true);
out.println("Your Message Received!");
out.close();
in.close();
socket.close();
}
}catch (IOException e)
{
out.println("wrong");
}
}
public static void main(String[] args)
{
new Server();
}
};
Client :
package test;
import java.io.*;
import java.net.*;
public class Client
{
Socket socket;
BufferedReader in;
PrintWriter out;
public Client()
{
try
{
System.out.println("Try to Connect to 127.0.0.1:10000");
socket = new Socket("127.0.0.1",10000);
System.out.println("The Server Connected!");
System.out.println("Please enter some Character:");
BufferedReader line = new BufferedReader(new
InputStreamReader(System.in));
out = new PrintWriter(socket.getOutputStream(),true);
out.println(line.readLine());
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println(in.readLine());
out.close();
in.close();
socket.close();
}catch(IOException e)
{
out.println("Wrong");
}
}
public static void main(String[] args)
{
new Client();
}
};
6、 JAVA ,JAVA ( )? COLLECTION , ?
:
package test;
import java.util.*;
class InsertSort
{
ArrayList al;
public InsertSort(int num,int mod)
{
al = new ArrayList(num);
Random rand = new Random();
System.out.println("The ArrayList Sort Before:");
for (int i=0;i<num ;i++ )
{
al.add(new Integer(Math.abs(rand.nextInt()) % mod + 1));
System.out.println("al["+i+"]="+al.get(i));
}
}
public void SortIt()
{
Integer tempInt;
int MaxSize=1;
for(int i=1;i<al.size();i++)
{
tempInt = (Integer)al.remove(i);
if(tempInt.intValue()>=((Integer)al.get(MaxSize-1)).intValue())
{
al.add(MaxSize,tempInt);
MaxSize++;
System.out.println(al.toString());
} else {
for (int j=0;j<MaxSize ;j++ )
{
if
(((Integer)al.get(j)).intValue()>=tempInt.intValue())
{
al.add(j,tempInt);
MaxSize++;
System.out.println(al.toString());
break;
}
}
}
}
System.out.println("The ArrayList Sort After:");
for(int i=0;i<al.size();i++)
{
System.out.println("al["+i+"]="+al.get(i));
}
}
public static void main(String[] args)
{
InsertSort is = new InsertSort(10,100);
is.SortIt();
}
}
JAVA java.io.Serializable
Collection Comparable Comparator
7、 : , , 。 , " ABC"4, " AB", " ABC DEF",6, " ABC" " ABC+ "。
: :
package test;
class SplitString
{
String SplitStr;
int SplitByte;
public SplitString(String str,int bytes)
{
SplitStr=str;
SplitByte=bytes;
System.out.println("The String is:′"+SplitStr+"′;SplitBytes="+SplitByte);
}
public void SplitIt()
{
int loopCount;
loopCount=(SplitStr.length()%SplitByte==0)?(SplitStr.length()/SplitByte):(SplitStr.length()/Split
Byte+1);
System.out.println("Will Split into "+loopCount);
for (int i=1;i<=loopCount ;i++ )
{
if (i==loopCount){
System.out.println(SplitStr.substring((i-1)*SplitByte,SplitStr.length()));
} else {
System.out.println(SplitStr.substring((i-1)*SplitByte,(i*SplitByte)));
}
}
}
public static void main(String[] args)
{
SplitString ss = new SplitString("test dd dsaf 3443n 43 0ewldfls=103",4);
ss.SplitIt();
}
}
8、JAVA 。 JAVA , , 1, , 。
,
9、STRING STRINGBUFFER 。
:STRING ,STRINGBUFFER 。 , , StringBuffer, String, StringBuffer toString()
Jsp
1、jsp ? ?
:JSP 9 ( ASP 6 ):
request , GET/POST
response
pageContext
session
application servlet
out
config servlet
page JSP
exception ,
2、jsp ? ?
:JSP 6
jsp:include: 。
jsp:useBean: JavaBean。
jsp:setProperty: JavaBean 。
jsp:getProperty: JavaBean 。
jsp:forward: 。
jsp:plugin: Java OBJECT EMBED
3、JSP INCLUDE INCLUDE ?
: INCLUDE jsp:include
<jsp:include page="included.jsp" flush="true" /> , ,
INCLUDE include , ,
<%@ include file="included.htm" %>
4、 ? ?
: , :
<jsp:include page="included.jsp" flush="true">
<jsp:forward page= "nextpage.jsp"/>
include , , 。 , 。 . , 。 go to 。
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.