java英语面试题大集合(网上搜索整理).doc

上传人:scccc 文档编号:12487765 上传时间:2021-12-04 格式:DOC 页数:31 大小:324.50KB
返回 下载 相关 举报
java英语面试题大集合(网上搜索整理).doc_第1页
第1页 / 共31页
java英语面试题大集合(网上搜索整理).doc_第2页
第2页 / 共31页
java英语面试题大集合(网上搜索整理).doc_第3页
第3页 / 共31页
java英语面试题大集合(网上搜索整理).doc_第4页
第4页 / 共31页
java英语面试题大集合(网上搜索整理).doc_第5页
第5页 / 共31页
点击查看更多>>
资源描述

《java英语面试题大集合(网上搜索整理).doc》由会员分享,可在线阅读,更多相关《java英语面试题大集合(网上搜索整理).doc(31页珍藏版)》请在三一文库上搜索。

1、java英语面试题* Q1. How could Java classesdirect program messagesto the system console, but error messages, say to a file?.The class System has a variable out that represe nts the sta ndard output, and the variable err that represe nts the sta ndard error device. By default, they both point at the system

2、 con sole. This how the sta ndard output could be re-directed:Stream st = newStream( newFileOutputStream("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 con tai n code in method bodies, w

3、hich is not allowed in an in terface. With abstract classes, you have to inherit your class from it and Java does not allow multiple in herita nee. On the other hand, you can impleme nt multiple in terfaces in your class.* Q3. Why would you use a synchronized block vs. synchronized method?A. Synchro

4、nized 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 in itia

5、lized with a default value of its data type (i.e. zero for in tegers).* 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 n

6、eeded?A. If you assig n a superclass object to a variable of a subclass's data type, you n eed to do explicit cast ing. 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

7、 difference between the methods sleep() and wait()A. The code sleep(IOOO); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one sec ond. A thread could stop wait ing earlier if it receives the no tify() or no tifyAll() call. The method wait() is defi ned in the c

8、lass Object and the method sleep() is defi ned 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 hav

9、e the same name as the class and can not return a value. They are onlycalled once while regular methods could be called many times.* Q10. Can you call one constructor from another if a class has multiple constructorsA. Yes. Use this() syntax.* Q11. Explain the usage of Java packages.A. This is a way

10、 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 packa

11、ge, 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 bel ongs to a package com.xyz.hr; and is located in the file c:devcomxyzh

12、rEmployee.java. In this case, you'd n eed to add c:dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a comma nd prompt wi ndow 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

13、differe nee. Sun Microsystems just re-bra nded 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 in sta nee of a S

14、tring 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 lOException. Exception's subclasses have to be caught first.Q16. What is more advisable to create a thread, by

15、implementing a Runnable interface or by extending Thread class?(donated in June 2005)A. Strategically speak ing, threads created by impleme nting Runn able in terface are more advisable. If you create a thread by exte nding a thread class, you cannot exte nd any other class. If you create a thread b

16、y impleme nti ng Runn able in terface, you save a space for your class to exte nd ano ther class now or in future.Q17. An application needs to load a library before it starts to run, how to code?One opti on is to use a static block to load a library before anything is called. For example, class Test

17、 static Syste m.lo adLibrary("path-to-library-file");When you call new Test(), the static block will be called first before any in itializati on happe ns.Note that the static block positi on may matter.Q18. What is the main difference between Java platform and other platforms?The Java plat

18、form differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms.The Java platform has two comp onen ts:1. The Java Virtual Machi ne (Java VM)2. The Java Applicati on Programmi ng In terface (Java API)Q19. What is the Java Virtual Ma

19、chine?The Java Virtual Mach ine is a software that can be ported onto various hardware-based platforms.Q20. What is the Java API?The Java API is a large collect ion of ready-made software comp onents that provide many useful capabilities, such as graphical user in terface (GUI) widgets.Q21. What is

20、the package?The package is a Java n amespace or part of Java libraries. The Java API is grouped into libraries of related classes and in terfaces; these libraries are known as packages.Q22. What is native code?The n ative code is code that after you compile it, the compiled code runs on a specific h

21、ardware platform.Q23. Can main() method be overloaded?Yes. the main() method is a special method for a program en try. You can overload mai n() method in any ways. But if you cha nge the sig nature of the main method, the entry point for the program will be gone.Q24. What is the serialization?The se

22、rializati on is a kind of mecha nism that makes a class or a bea n persiste nee by havi ng its properties or fields and state in formatio n saved and restored to and from storage.Q25. How to make a class or a bean serializable?By impleme nting either the java.io.Serializable in terface, or the java.

23、io.Exter nalizable in terface. As long as one class in a class's in herita nee hierarchy impleme nts Serializable or Exter nalizable, that class is serializable.Q26. What is J2EE?J2EE is an environment for develop ing and deplo ying en terprise applicati ons. The J2EE platform con sists of a set

24、 of services, applicati on program ming in terfaces (APIs), and protocols that provide the function ality for develop ing multitiered, web-based applicati ons.Q27. What are the four types of J2EE modules?1. Applicati on clie nt module2. Web module3. En terprise JavaBea ns module4. Resource adapter m

25、oduleQ28. What are the differences between Ear, Jar and War files? Under what circumstances should we use each one? (donated in April, 2005)There are no structural differences between the files; they are all archived using zip-jar compressi on. However, they are inten ded for differe nt purposes.-Ja

26、r files (files with a .jar exte nsion) are inten ded to hold gen eric libraries of Java classes, resources, auxiliary files, etc.-War files (files with a .war exte nsion) are inten ded to contain complete Web applicati ons. In this con text, a Web applicati on is defi ned as a sin gle group of files

27、, classes, resources, .jar files that can be packaged and accessed as one servlet con text.-Ear files (files with a .ear exte nsion) are inten ded to contain complete en terprise applicati ons. In this con text, an en terprise applicati on is defi ned as a collect ion of .jar files, resources, class

28、es, and multiple Web applicati ons.Each type of file (.jar, .war, .ear) is processed uniq uely by applicati on servers, servlet contain ers, EJB contain ers, etc.Q29. What two protocols are used in Java RMI technology?Java Object Serializati on and HTTP. The Object Serializati on protocol is used to

29、 marshal call and retur n data. The HTTP protocol is used to "POST" a remote method in vocati on and obta in retur n data whe n circumsta nces warra nt.Q30. Explain for 10 to 15 minutes a technology or product that you are familiar with.(donated in April,2005)This is to test the pers on

30、9;s com muni cati on skill and tech ni cal skill. If you are really comfortable, start with a public doma in tech no logy like Struts or JUn it. If not, sometimes it is better to expla in the product that you worked with rather tha n read about or studied.Q31: What are different types of inner class

31、es?A: Nested top-level classes, Member classes, Local classes, Anonym ous classesNested top-level classes- If you declare a class with in a class and specify the static modifier, the compiler treats the class just like any other top-level class.Any class outside the declaring class accesses the nest

32、ed class with the declaring class name acti ng similarly to a package. eg, outer.i nner. Top-level inner classes implicitly have access only to static variables.There can also be inner in terfaces. All of these are of the n ested top-level variety.Member classes - Member inner classes are just like

33、other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a n ested top-level class. The primary differe nee betwee n member classes and n ested top-level classes is that member classes

34、have access to the specific in sta nee of the en clos ing class.Local classes - Local classes are like local variables, specific to a block of code. Their visibility is on ly within the block of their declarati on. In order for the class to be useful bey ond the declarati on block, it would n eed to

35、 impleme nt amore publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable.Anonymous classes - Anonymous inner classes extend local inner classes one level further. As anonym ous classes have no n ame, you cannot provide

36、a con structor.Q32: Are the imports checked for validity at compile time? e.g. will the code containing an import such as javaang.ABCD compile?A: Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error s

37、ay in g,ca n not resolve symbol symbol : class ABCD locati on: package io import java.io.ABCD;Q33: Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?A: No you will have to import the subpackages explicitly. Importi ng com.My

38、Test.* will import classes in the package MyTest onl y. It will not import any class in any of it's subpackage.Q34: What is the difference between declaring a variable and defining a variable?A: In declarati on we just men ti on the type of the variable and it's n ame. We do not in itialize

39、it. But defi ning means declarati on + in itializatio n.e.g String s; is just a declarati on while String s = new String ("abed"); Or String s = "abcd" are both defi niti ons.Q35: What is the default value of an object reference declared as an instance variable?A: n ull uni ess w

40、e defi ne it explicitly.Q36: Can a top level class be private or protected?A: No. A top level class can n ot be private or protected. It can have either "public" or no modifier.If it does not have a modifier it is supposed to have a default access .If a top level class is declared as priva

41、te the compiler will compla in that the "modifier private is not allowed here". This means that a top level class can not be private. Same is the case with protected.Q37: What type of parameter passing does Java support?A: In Java the argume nts are always passed by value .Q38: What is the

42、 difference between preemptive scheduling and time slicing?A: Un der preemptive scheduli ng, the highest priority task executes un til it en ters the wait ing or dead states or a higher priority task comes into existe nee. Un der time slici ng, a task executes for a predefi ned slice of time and the

43、 n reen ters the pool of ready tasks. The scheduler the n determ ines which task should execute n ext, based on priority and other factors.Q39. What is ActionServlet?(donated in Nov.2005)Actio nServlet is the Comma nd part of the MVC impleme ntati on and is the core of the Struts Framework. Action S

44、ervlet creates and uses Action, an ActionForm, and Acti onFo rward. The struts-c on fig.xml file con figures the Comma nd. During the creati on of the Web project, Action and Actio nF orm are exte nded to solve the specific problem space. The file struts-co nfig.xml in structs Actio nServlet on how

45、to use the exte nded classes.Q40. What is Jakarta Struts Framework? (donated in Nov. 2005)Jakarta Struts is an ope n source impleme ntati on of MVC (Model-View-Co ntroller) pattern for the developme nt of web based applicati ons. Jakarta Struts is robust architecture and can be used for the developm

46、ent of application of any size. Struts framework makes it much easier to design scalable, reliable Web applicati ons with JavaQ41. What is Struts?Struts is a web page developme nt framework and an ope n source software that helps developers build web applications quickly and easily. Struts combines

47、Java Servlets, Java Server Pages, custom tags, and message resources into a unified framework. It is a cooperative, synergistic platform, suitable for developme nt teams, in depe ndent developers, and every one betwee n.Q42. How is the MVC design pattern used in Struts framework?In the MVC desig n p

48、atter n, applicati on flow is mediated by a cen tral Con troller. The Con troller delegates requests to an appropriate han dler. The han dlers are tied to a Model, and each han dler acts as an adapter betwee n the request and the Model. The Model represe nts, or en capsulates, an applicati on's

49、bus in ess logic or state. Con trol is usually the n forwarded back through the Con troller to the appropriate View. The forwarding can be determined by consulting a set of mappings, usually loaded from a database or con figurati on file. This provides a loose coupli ng betwee n the View and Model, which can make an applicati on sig ni fica ntly easier to create and maintain.Controller-Servlet controller which supplied by Struts itself; View - what you can see on the scree n, a JSP p

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1