30道英文Java面试题附英文答案(16-30)
经典java面试英文题

1.What is the result when you compile and run the following code?public class Test{public void method(){for(int i=0;i<3;i++){System.out.print(i);}System.out.print(i);}}result: compile error分析:i是局部变量。
for循环完成后,i的引用即消失。
2.What will be the result of executing the following code?Given that Test1 is a class.class Test1{public static void main(String[] args){Test1[] t1 = new Test1[10];Test1[][] t2 = new Test1[5][];if(t1[0]==null){t2[0] = new Test1[10];t2[1] = new Test1[10];t2[2] = new Test1[10];t2[3] = new Test1[10];t2[4] = new Test1[10];}System.out.println(t1[0]);System.out.println(t2[1][0]);}}result:null null分析:new数组后,数组有大小,但值为null3.What will happen when you attempt to compile and run the following code? class Base{int i = 99;public void amethod(){System.out.println("Base.method()");}Base(){amethod();}}public class Derived extends Base{int i = -1;public static void main(String args[]){Base b = new Derived();System.out.println(b.i);b.amethod();}public void amethod(){System.out.println("Derived.amethod()");}}result:Derived.amethod()99Derived.amethod()解释:Derived 重写了Base的amethod方法。
英文java面试题(含答案)

英文java面试题(含答案)1.Tell me a little about yourselfI am holding a master degress in software science and had 2-year work experience in software development. I have used J2EE technology for 2 years,including Jsp,servlet,javabean,XML,EJB,I also used C language for half year and IBM mainframe technology half year and IBM mainframe technology half year.And the projects I participated in follow the Waterfall model lifecycle starting from design,then coding ,testing,maintenance.2.Describe a situation where you had to work under pressure,and explain how you handle it.Once when we did a mainframe project,our customer wanted to see a demo from our team before they signed the contract with our company.It is urgent,because our customer didn t give us enough time to do it. So all my team menbers had to work overtime,but we finished it punctually and perfectly . Our customer was satisfied with it.Actually,It is common to meet some deadlines or work under pressure in IT field.I am ok with it.3.What would your last employer tell me about your work performanceI am sure my last employer will praise my work performance,because he was reluctant to let me go when I told him I want to quit and study abroad,and he said I am welcome to come back when I finish study.4.What is your major weaknessI always want everything to be perfect.Sometimes,I am over-sensitive. When a design pattern or technical solution comes up during a meeting discussion,I am always the first one to test the feasibility.Some leader don t like such person because sometimes it is embarrassing when I prove it doesn t work while the leader still believe it is a perfect solution,But I think I did nothing wrong about it,it is good for the company.5.Why did you leave your last jobAlthough I did well in the last company,I always feel the theoretical study and actual practice are equally important and depend on each other.So,I decide to further study and actual practice are equally important and dependent on each other.So,I decide to further study to extend my theory in computer science.6.What are your strengthsWhat I am superior to others I believe is strong interest in software development I have.Many friends of mine working in IT field are holding bachelor degree or master degree and have worked for several years,but they don t have much interest in it,they only treat what they do everything a job,a means to survive,they don t have career plan at all. I am different. I like writing programs.I have set up my career goal long time ago.I will do my best to make it possible in the future.And I have worked hard towards this goal for several years.7.What are your future career plansI would like to be a software engineer now.but my career goal is to be an excellent software architector in the future.I like writing programs. Software is a kind of art, although sometimes it drove me crazy,after I overcame the difficulties I feel I am useful,I will keep working in IT field.8.What are your salary expectationsI believe your company will set up reasonable salary for me according to my ability,so I don t worry about it at all.Between 7000 to 8000 monthly9. Why are you interested in this position?Your company specializes in providing technical solutionsto customers and the last company I worked in also specializes in this field. I have relevant skills and experiences meeting your requirement.I am sure I can do it well.10.Do you have any questions that you would like to ask meWhat is a typical workday like and what would I doWhat is your expectation for me in this job11.What J2EE design patterns have you used beforeCommand/Session Facade/Service Locator/Data Access Object/Business Delegate。
30道英文Java面试题附英文答案(1-15)

内容摘要:如果你打算参加IT外企的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 constructorsA. 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.。
J2EE英文面试题及答案

J2EE英文面试题及答案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 cannotinstantiate directly.12.what is differenece between string and stringbuffer.13.what is immutable14.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 api18.what is legacy interface.19.what is main difference hashmap and hastable20.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 independent41.what is awt and swing.42.what is heavy wieght ponents.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 jsp50.why choose weblogic8.1 other than any applicationserver.51.what is water fall model vs sdlc52.what is use of dataflowdiagrams53.wha t is ip in ur project.54.what about reception module1. Oracle is an RDBMS product with DDL and DML from a pany called Oracle Inc.2. Difference between 8i and 9i is given in the Oracle site3. Question not available4. Something5. oops is Object Oriented Programming6.what is single inheritance.ans:one class is inherited by only other one class7.what is multiple inheritance.ans:One class inheriting more than one class at atime8.can java support multiple inheritance.ans:No9.what is interface.ans:Interface has only method declarations but no defn10.what is differenec between abstract class and interface.ans:In abstract class some methods may contain definition,but in interface every method should be abstract11.how to u prove that abstrace class cannotinstantiate directly.ans:As they dont have constructor they cant be instantiated12.what is differenece between string and stringbuffer.ans:Strings are immutable where as string buffer can be modified13.what is immutableans:Which cant be changed14.how to write a program using sort program.15 how to write a program using unsort program.ans: Both can be done using javascriptThis is for Sortfunction SelectTextSort(obj) { // sort by textvar N=obj.options.length;for (var i=0;ifor (var j=i+1;jif ( obj.options[i].text > obj.options[j].text ) {var i1= (obj.options[i].selected == true ) ? true : falsevar j1= (obj.options[j].selected == true ) ? true :falsevar 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 : falseobj.options[j].selected = (i1 && true ) ? true : false}}}return true}16.what is legacy.17.what is legacy api18.what is legacy interface.ans: legacy is something that is old in terms of technology/ system19.what is main difference hashmap and hastableans:Hash table is synchronised20.what is main difference between arraylist and vector.ans:Vector is synchronised21.what is struts framework.22.what are distributed techonologies.distributed technologies means any technology / s/w program that are having many ponents 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 value26.what is jdbc.ans:Connecting to DB from java program requires JDBC27.what are type of drivers.type1,2,3,429.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 CaseImplements Code, Performs TestSubmits Code through CVS / VSSSubmits documents along with Release Checklist to the tester / leader.31.what is deployment descriptor.ans:Which contains the infrnmation like which file to be used40.what is platfrom independentans:A language is said to be platform independent if it can be run on any machine with out modifying code41.what is awt and swing.ans:AWT are heavy weight ponents and swings are light weight ponents46.what is major concepts in oops.ans:Abstraction,polymorphism,encapsulation,inheritance47.why u choose mvc-2 architecture.ans:In MVC-2 controller is servlet rather than JSP which makes it efficient48.what is implicit object.ans:Implicit objects are a set of Java objects that the JSP Container makes available to developers in each page49.how many implicit objects in jspans:out,page,session,request,response,application,page context,config。
【最新】java,英文面试-实用word文档 (21页)

本文部分内容来自网络整理,本司不为其真实性负责,如有异议或侵权请及时联系,本司将立即删除!== 本文为word格式,下载后可方便编辑和修改! ==java,英文面试篇一:java 英语面试大全1. What are java beans?JavaBeans is a portable, platform-independent component model written in the Java programming language, developed in collaboration with industry leaders. It enables developers to write reusable components once and run them anywhere -- benefiting from the platform-independent power of Java technology. JavaBeans acts as a Bridge between proprietary component models and provides a seamless and powerful means for developers to build components that run in ActiveX container applications.Java beans is very powerful tool you can use in your servlet/JSP bridge. You can use the servlets to build the bean and can be passed over to the JSP for reading. This provides tight encapsulation of the data while preserving the sanctity of servlets and JSP。
Java面试题和答案(英文版)

Java面试题和答案(英文版)Q: What is the difference between an Interface and an Abstract class?A: An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.Q: What is the purpose of garbage collection in Java, and when is it used?A: The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.Q: Describe synchronization in respect to multithreading.A: With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.Q: Explain different way of using thread?A: The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.Q: What are pass by reference and passby value?A: Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.Q: What is HashMap and Map?A: Map is Interface and Hashmap is class that implements that.Q: Difference between HashMap and HashTable?A: The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time. HashMap is unsynchronized and Hashtable is synchronized.Q: Difference between Vector and ArrayList?A: Vector is synchronized whereas arraylist is not.Q: Difference between Swing and Awt?A: AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster than AWT.Q: What is the difference between a constructor and a method?A: A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.Q: What is an Iterator?A: Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.Q: State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.A: public : Public class is visible in other packages, field is visible everywhere (class must be public too)private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature.protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.default :What you get by default ie, without any access modifier (ie, public private or protected).It means that it is visible to all within a particular package.Q: What is an abstract class?A: Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. Any class with an abstract method is automatically abstract itself, and must be declared as such.A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.Q: What is static in java?A: Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class.Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass.Q: What is final?A: A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).Q: What if the main method is declared as private?A: The program compiles properly but at runtime it will give "Main method not public." message.[ Received from Sandesh Sadhale]Q: What if the static modifier is removed from the signature of the main method?A: Program compiles. But at runtime throws an error "NoSuchMethodError".[ Received from Sandesh Sadhale]Q: What if I write static public void instead of public static void?A: Program compiles and runs properly.[ Received from Sandesh Sadhale]Q: What if I do not provide the String array as the argument to the method?A: Program compiles but throws a runtime error "NoSuchMethodError".[ Received from Sandesh Sadhale]Q: What is the first argument of the String array in main method?A: The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.[ Received from Sandesh Sadhale]Q: If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?A: It is empty. But not null.[ Received from Sandesh Sadhale]Q: How can one prove that the array is not null but empty using one line of code?A: Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.[ Received from Sandesh Sadhale]Q: What environment variables do I need to set on my machine in order to be able to run Java programs?A: CLASSPATH and PATH are the two variables.[ Received from Sandesh Sadhale]Q: Can an application have multiple classes having main method?A: Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.[ Received from Sandesh Sadhale]Q: Can I have multiple main methods in the same class?A: No the program fails to compile. The compiler says that the main method is already defined in the class.[ Received from Sandesh Sadhale]Q: Do I need to import ng package any time? Why ?A: No. It is by default loaded internally by the JVM.[ Received from Sandesh Sadhale]Q: Can I import same package/class twice? Will the JVM load the package twice at runtime?A: One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the JVM will internally load the class only once no matter how many times you import the same class.[ Received from Sandesh Sadhale]Q: What are Checked and UnChecked Exception?A: A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown.eg, IOException thrown by java.io.FileInputStream's read() method·Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method· Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.Q: What is Overriding?A: When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass.When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private.Q: What are different types of inner classes?A: Nested top-level classes, Member classes, Local classes, Anonymous classesNested top-level classes- If you declare a class within 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 nested class with the declaring class name acting similarly to a package. eg, outer.inner. Top-level inner classes implicitly have access only to static variables.There can also be inner interfaces. All of these are of the nested top-level variety.Member classes - Member inner classes are just like 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 nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.Local classes - Local classes are like local variables, specific to a block of code. Their visibility is only within the block oftheir declaration. In order for the class to be useful beyond the declaration block, it would need to implement a more 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 anonymous classes have no name, you cannot provide a constructor.Q: Are the imports checked for validity at compile time? e.g. will the code containing an import such as ng.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 saying,can not resolve symbolsymbol : class ABCDlocation: package ioimport java.io.ABCD;[ Received from Sandesh Sadhale]Q: 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. Importing com.MyTest.* will import classes in the package MyTest only. It will not import any class in any of it's subpackage.[ Received from Sandesh Sadhale]Q: What is the difference between declaring a variable and defining a variable?A: In declaration we just mention the type of the variable and it's name. We do not initialize it. But defining means declaration + initialization.e.g String s; is just a declaration while String s = new String ("abcd"); Or String s = "abcd"; are both definitions. [ Received from Sandesh Sadhale]Q: What is the default value of an object reference declared as an instance variable?A: null unless we define it explicitly.[ Received from Sandesh Sadhale]Q: Can a top level class be private or protected?A: No. A top level class can not 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 private the compiler will complain 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.[ Received from Sandesh Sadhale]Q: What type of parameter passing does Java support?A: In Java the arguments are always passed by value .[ Update from Eki and Jyothish Venu]Q: Primitive data types are passed by reference or pass by value?A: Primitive data types are passed by value.[ Received from Sandesh Sadhale]Q: Objects are passed by value or by reference?A: Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object .[ Update from Eki and Jyothish Venu]Q: What is serialization?A: Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream.[ Received from Sandesh Sadhale]Q: How do I serialize an object to a file?A: The class whose instances are to be serialized should implement an interface Serializable. Then you pass the instance to the ObjectOutputStream which is connected to a fileoutputstream. This will save the object to a file.[ Received from Sandesh Sadhale]Q: Which methods of Serializable interface should I implement?A: The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.[ Received from Sandesh Sadhale]Q: How can I customize the seralization process? i.e. how can one have a control over the serialization process?A: Yes it is possible to have control over serialization process. The class should implement Externalizable interface. This interface contains two methods namely readExternal and writeExternal. You should implement these methods and write the logic for customizing the serialization process.[ Received from Sandesh Sadhale]Q: What is the common usage of serialization?A: Whenever an object is to be sent over the network, objects need to be serialized. Moreover if the state of an object is to be saved, objects need to be serilazed.[ Received from Sandesh Sadhale]Q: What is Externalizable interface?A: Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism. Thus if your class implements this interface, you can customize the serialization process by implementing these methods.[ Received from Sandesh Sadhale]Q: When you serialize an object, what happens to the object references included in the object?A: The serialization mechanism generates an object graph for serialization. Thus it determines whether the included object references are serializable or not. This is a recursive process. Thus when an object is serialized, all the included objects are also serialized alongwith the original obect.[ Received from Sandesh Sadhale]Q: What one should take care of while serializing the object?A: One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializableException.[ Received from Sandesh Sadhale]Q: What happens to the static fields of a class during serialization?A: There are three exceptions in which serialization doesnot necessarily read and write to the stream. These are1. Serialization ignores static fields, because they are not part of ay particular state state.2. Base class fields are only hendled if the base class itself is serializable.3. Transient fields.[ Received from Sandesh Sadhale Modified after P.John David comments.]Q: Does Java provide any construct to find out the size of an object?A: No there is not sizeof operator in Java. So there is not direct way to determine the size of an object directly in Java. [ Received from Sandesh Sadhale] TOPQ: Give a simplest way to find out the time a method takes for execution without using any profiling tool?A: Read the system time just before the method is invoked and immediately after method returns. Take the time difference, which will give you the time taken by a method for execution.To put it in code...long start = System.currentTimeMillis ();method ();long end = System.currentTimeMillis ();System.out.println ("Time taken for execution is " + (end - start));Remember that if the time taken for execution is too small, it might show that it is taking zero milliseconds for execution. Try it on a method which is big enough, in the sense the one which is doing considerable amout of processing.[ Received from Sandesh Sadhale] TOPQ: What are wrapper classes?A: Java provides specialized classes corresponding to each of the primitive data types. These are called wrapper classes. They are e.g. Integer, Character, Double etc.[ Received from Sandesh Sadhale] TOPQ: Why do we need wrapper classes?A: It is sometimes easier to deal with primitives as objects. Moreover most of the collection classes store objects and not primitive data types. And also the wrapper classes provide many utility methods also. Because of these resons we need wrapper classes. And since we create instances of these classes we can store them in any of the collection classes and pass them around as a collection. Also we can pass them around as method parameters where a method expects an object.[ Received from Sandesh Sadhale] TOPQ: What are checked exceptions?A: Checked exception are those which the Java compiler forces you to catch. e.g. IOException are checked Exceptions. [ Received from Sandesh Sadhale] TOPQ: What are runtime exceptions?A: Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time.[ Received from Sandesh Sadhale] TOPQ: What is the difference between error and an exception?A: An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors and you can not repair them at runtime. While exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc.).[ Received from Sandesh Sadhale] TOPQ: How to create custom exceptions?A: Your class should extend class Exception, or some more specific type thereof.[ Received from Sandesh Sadhale] TOPQ: If I want an object of my class to be thrown as an exception object, what should I do?A: The class should extend from Exception class. Or you can extend your class from some more precise exception type also.[ Received from Sandesh Sadhale] TOPQ: If my class already extends from some other class what should I do if I want an instance of my class to be thrown as an exception object?A: One can not do anytihng in this scenarion. Because Java does not allow multiple inheritance and does not provide any exception interface as well.[ Received from Sandesh Sadhale] TOPQ: How does an exception permeate through the code?A: An unhandled exception moves up the method stack in search of a matching When an exception is thrown from a code which is wrapped in a try block followed by one or more catch blocks, a search is made for matching catch block. If a matching type is found then that block will be invoked. If a matching type is not found then the exception moves up the method stack and reaches the caller method. Same procedure is repeated if the caller method is included in a try catch block. This process continues until a catch block handling the appropriate type of exception is found. If it does not find such a block then finally the program terminates.[ Received from Sandesh Sadhale] TOPQ: What are the different ways to handle exceptions?A: There are two ways to handle exceptions,1. By wrapping the desired code in a try block followed by a catch block to catch the exceptions. and2. List the desired exceptions in the throws clause of the method and let the caller of the method hadle those exceptions. [ Received from Sandesh Sadhale] TOPQ: What is the basic difference between the 2 approaches to exception handling.1> try catch block and2> specifying the candidate exceptions in the throws clause?When should you use which approach?A: In the first approach as a programmer of the method, you urself are dealing with the exception. This is fine if you are in a best position to decide should be done in case of an exception. Whereas if it is not the responsibility of the method to deal with it's own exceptions, then do not use this approach. In this case use the second approach. In the second approach we are forcing the caller of the method to catch the exceptions, that the method is likely to throw. This is often the approach library creators use. They list the exception in the throws clause and we must catch them. You will find the same approach throughout the java libraries we use.[ Received from Sandesh Sadhale] TOPQ: Is it necessary that each try block must be followed by a catch block?A: It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method.[ Received from Sandesh Sadhale] TOPQ: If I write return at the end of the try block, will the finally block still execute?A: Yes even if you write return as the last statement in the try block and no exception occurs, the finally block will execute. The finally block will execute and then the control return.[ Received from Sandesh Sadhale] TOPQ: If I write System.exit (0); at the end of the try block, will the finally block still execute?A: No in this case the finally block will not execute because when you say System.exit (0); the control immediately goes out of the program, and thus finally never executes.[ Received from Sandesh Sadhale]Q: How are Observer and Observable used?A: Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.[Received from Venkateswara Manam] TOPQ: What is synchronization and why is it important?A: With respect to multithreading, synchronization is the capability to controlthe access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often leads to significant errors.[ Received from Venkateswara Manam] TOPQ: How does Java handle integer overflows and underflows?A: It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.[ Received from Venkateswara Manam] TOPQ: Does garbage collection guarantee that a program will not run out of memory?A: Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.[ Received from Venkateswara Manam] TOPQ: What is the difference between preemptive scheduling and time slicing?A: Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.[ Received from Venkateswara Manam] TOPQ: When a thread is created and started, what is its initial state?A: A thread is in the ready state after it has been created and started.[ Received from Venkateswara Manam] TOPQ: What is the purpose of finalization?A: The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.[ Received from Venkateswara Manam] TOPQ: What is the Locale class?A: The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.[ Received from Venkateswara Manam] TOPQ: What is the difference between a while statement and a do statement?A: A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.[ Received from Venkateswara Manam] TOPQ: What is the difference between static and non-static variables?A: A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.[ Received from Venkateswara Manam] TOPQ: How are this() and super() used with constructors?A: This() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.[ Received from Venkateswara Manam] TOPQ: What are synchronized methods and synchronized statements?A: Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.[ Received from Venkateswara Manam] TOPQ: What is daemon thread and which method is used to create the daemon thread?A: Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.[ Received from Shipra Kamra] TOPQ: Can applets communicate with each other?A: At this point in time applets may communicate with other applets running in the same virtual machine. If the applets are of the same class, they can communicate via shared static variables. If the applets are of different classes, then each will need a reference to the same class with static variables. In any case the basic idea is to pass the information back and forth through a static variable.An applet can also get references to all other applets on the same page using the getApplets() method ofjava.applet.AppletContext. Once you get the reference to an applet, you can communicate with it by using its public members.It is conceivable to have applets in different virtual machines that talk to a server somewhere on the Internet and store any data that needs to be serialized there. Then, when another applet needs this data, it could connect to this same server. Implementing this is non-trivial.[ Received from Krishna Kumar ] TOPQ: What are the steps in the JDBC connection?A: While making a JDBC connection we go through the following steps :Step 1 : Register the database driver by using :Class.forName(" driver classs for that specific database" );Step 2 : Now create a database connection using :Connection con = DriverManager.getConnection(url,username,password);。
Java工程师全英文面试题
Java软件工程师面试题Circle one or more options which are correct.1. Why would someone want to use JavaScript on a Web page? (5 scores)A. To react to events that occur with Web page useB. To read and write HTMLC. To validate data in a Web formD. To pass data to a Java applet programE. To run a clock or timer in a Web page2. Evaluate the following String method uses by writing the value of s after the evaluation (5 scores) (write one value on the line to the right of each evaluation)var str="Mix and Match"A. s = str.indexOf("x") __2B. s = str.indexOf("g") ___-1C. s = str.indexOf("M") ___0D. s = stIndexOf("a") ___9E. s = str.indexOf("and") ___43. How can someone properly open a second Web browser window with a JavaScript statement?(5 scores)A. document.openWin("/")B. openWindow("/")C. window.open(“/”)D. document.open("/")E. document.location("/")4. Given the following valid HTML form, how would you assign the value typed into the ownercontrol to a variable ssn in a JavaScript statement?(5 scores)<FORM Name=SSN Action=processme.html><INPUT Name=owner></FORM>A. ssn = window.SSN.owner.value;B. ssn = document.SSN.owner.value;C. ssn = document.SSN.input.value;D. ssn = document.form.input.value;E. ssn = window.owner.value;5. After a JavaScript function runs the following two lines of code, what value does the variable x contain?(5 scores)arr = new Array(5);x = Math.random() / arr.length;A. a floating point number between 0.0 and 0.2B. a floating point number between 0.0 and 0.25C. a floating point number between 0.0 and 1.0D. a floating point number between 0.0 and 5.0E. x would not be assigned due to one or more errors in the code6. What is the value of variable x after the following block of JavaScript code is run? (5 scores)x=0;y=2;while(y>0.5 || y<0.0) {x = x+1;y = y/x - y;}A. 0B. 1C. more than 1D. undetermined since the code divides by zeroE. less than 17. What will happen when you attempt to compile and run this code? (5 scores)abstract class Base{abstract public void myfunc();public void another(){System.out.println("Another method");}}public class Abs extends Base{public static void main(String argv[]){Abs a = new Abs();a.amethod();}public void myfunc(){System.out.println("My Func");}public void amethod(){myfunc();}}A The code will compile and run, printing out the words "My Func"B The compiler will complain that the Base class has non abstract methodsC The code will compile but complain at run time that the Base class has non abstract methodsD The compiler will complain that the method myfunc in the base class has no body, nobody at all to looove it8. Which most closely matches a description of a Java Map? (5 scores)A. A vector of arrays for a 2D geographic representationB. A class for containing unique array elementsC. A class for containing unique vector elementsD. An interface that ensures that implementing classes cannot contain duplicate keys9. What will happen when you attempt to compile and run the following code? (5 scores)public class StrEq{public static void main(String argv[]){StrEq s = new StrEq();}private StrEq(){String s = "Marcus";String s2 = new String("Marcus");if(s == s2){System.out.println("we have a match");}else{System.out.println("Not equal");}}}A. Compile time error caused by private constructorB. Output of "we have a match"C. Output of "Not equal"D. Compile time error by attempting to compare strings using ==10. What will happen when you attempt to compile and run the following code? (5 scores)import java.io.*;class Base{public void amethod()throws FileNotFoundException{}}public class ExcepDemo extends Base{public static void main(String argv[]){ExcepDemo e = new ExcepDemo();}public void amethod(){}protected ExcepDemo(){try{DataInputStream din = new DataInputStream(System.in);System.out.println("Pausing");din.readByte();System.out.println("Continuing");this.amethod();}catch(IOException ioe) {}}}A. Compile time error caused by protected constructorB. Compile time error caused by amethod not declaring ExceptionC. Runtime error caused by amethod not declaring ExceptionD. Compile and run with output of "Pausing" and "Continuing" after a key is hit11. What will happen when you attempt to compile and run this program? (5 scores) public class Outer{public String name = "Outer";public static void main(String argv[]){Inner i = new Inner();i.showName();}//End of mainprivate class Inner{String name =new String("Inner");void showName(){System.out.println(name);}}//End of Inner class}A. Compile and run with output of "Outer"B. Compile and run with output of "Inner"C. Compile time error because Inner is declared as privateD. Compile time error because of the line creating the instance of Inner12. What will be output by the following line? (5 scores)System.out.println(Math.floor(-2.1));A. -2B. 2.0C. -3D. -3.013. What will happen when you attempt to compile and run the following code? (5 scores)int Output=10;boolean b1 = false;if((b1==true) && ((Output+=10)==20)){System.out.println("We are equal "+Output);}else {System.out.println("Not equal! "+Output);}A. Compile error, attempting to peform binary comparison on logical data typeB. Compilation and output of "We are equal 10"C. Compilation and output of "Not equal! 20"D. Compilation and output of "Not equal! 10"14. Given the following variableschar c = 'c';int i = 10;double d = 10;long l = 1;String s = "Hello";Which of the following will compile without error? (5 scores)A.c=c+i;B.s+=i;C.i+=s;D.c+=s;15. Given the following class definition, which of the following statements would be legal after the comment //Here? (5 scores)class InOut{String s= new String("Between");public void amethod(final int iArgs){int iam;class Bicycle{public void sayHello(){//Here}}//End of bicycle class}//End of amethodpublic void another(){int iOther;}}A. System.out.println(s);B. System.out.println(iOther);C. System.out.println(iam);D. System.out.println(iArgs);16. Which of the following are methods of the Thread class? (5 scores)A. yield()B. sleep(long msec)C. go()D. stop()17. How would you "print" a text message to the browser? (5 scores)A.PrintWriter out = response.getWriter(); out.println(message);B.response.println(message);C.ServletOutputStream out = response.getWriter(); out.println(message);D.ServletOutputStream out = response.ServletOutputStream(); out.println(message);18. Which of the following will include the text of a resource at translation time? (5 scores)A.<%@ include file="relativeURLspec" %>B.<%! include file="relativeURLspec" %>C.<%jsp:include file="relativeURLspec" %>D.<%@ page import="relativeURLspec" %>19. What is the correct syntax for assigning a value to a bean's property? (5 scores)A.<jsp:property name="houseLotBean" property="id" value="33245" />B.<jsp:useBean name="houseLotBean" property="id" value="33245" />C.<jsp:setProperty name="houseLotBean" property="id" value="33245" />D.<jsp:setProperty property="id" value="33245" />20. How do you get the request header names? (5 scores)A.Enumeration e = request.getHeaderNames ;B.String[] names = request.getHeaderNames ;C.Enumeration e = request.getHeaders ;D.String[] names = request.getHeaders ;21. How do you perform programmatic server-side includes? (5 scores)A.setForward(String url)B.RequestDispatcherC.RequestD.getResource(String url)22. What happens if, when calling getParameterValues, the parameter has a single value? (5 scores)A.It returns an error. You should use the getParameterValue method for single value parameters.B.It returns an array with a length of one.C.getParameterValues calls getValue for that single value.D.getParameterValues calls getValue for that single value.23. Read the following code:public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<html>");out.println("<head><title>Servlet Error Handling " + "Example</title></head>");out.println("<body>");out.println("A skimpy, but complete servlet.");out.println("</body>");out.println("</html>");}Which two statements are true regarding this code (choose two)?(5 scores)A. The doGet, doPost, or doPut method is called next depending on the type of request.B. This code is invalid because it doesn't call one of the doGet, doPost, or doPut methods.C. This code is valid and will handle all three types of HTTP requests including GET, POST, and PUT.D. The next method invoked is destroy.24. You normally write a servlet by overriding the doPut, doGet, and doPost methods. Which class do they come from? (5 scores)A.HttpServletRequestB.HttpServletResponseC.HttpServletD.HttpSession25. Which interface defines the methods for retrieving form parameters? (5 scores)A.ServletRequestB.ServletResponseC.HTTPRequestD.HTTPResponse26. Given the following deployment descriptor code:<servlet><servlet-name>test</servlet-name><servlet-class>TestServlet</servlet-class><init-param><param-name>color</param-name><param-value>green</param-value></init-param></servlet>Which methods can be used to access a servlet initialization parameter color? (5 scores)A.Servlet.getInitParameter()B.HttpServletRequest.getParameter()C.ServletContext.getInitParameter()D.ServletConfig.getInitParameter()27. Which of the following objects are available within JSP? (5 scores)A.requestB.responseC.errorD.exception28. Which two of the following are true about application .war files?(5 scores)A.They can be created by the jar tool.B.They are placed in the WEB-INF directory.C.They can be used to distribute Web applications.D.They must be registered with the application's deployment descriptor.29. Case:某学校有若干学院,每一学院有若干班级。
恩士迅java面试英文题
恩士迅java面试英文题Enson Java Interview English Questions1. What is Java?Java is a high-level, object-oriented programming language developed by Sun Microsystems (now owned by Oracle) in 1995. It is known for its platform independence, which means that Java programs can run on any device or operating system that has a Java Virtual Machine (JVM). Java is widely used for creating web applications, mobile applications, desktop software, and enterprise solutions.2. What are the main features of Java?Java has several key features that make it popular among developers:- Object-oriented: Java follows the principles ofobject-oriented programming (OOP), allowing developers to create reusable and modular code.- Platform independence: Java's 'write once, run anywhere' approach allows programs to be run on any device with a JVM, making it highly portable.- Memory management: Java uses automatic garbage collection, freeing developers from managing memory manually. - Multi-threading: Java supports concurrent programmingwith its built-in support for threads, allowing multiple tasks to run simultaneously.- Security: Java provides a secure environment with its built-in security features, such as sandboxing and permission-based access control.3. What is the difference between JDK and JVM?JDK (Java Development Kit) and JVM (Java Virtual Machine) are both essential components of the Java platform, but they serve different purposes.- JDK: JDK is a software development kit that provides tools and libraries necessary for Java development. It includes the Java compiler, debugger, and other utilities required to write, compile, and run Java programs.- JVM: JVM is a runtime environment that executes Java bytecode. It interprets the compiled Java code and converts it into machine code that can be understood by the underlying operating system. JVM also handles memory management and provides various runtime services.4. What is the difference between an abstract class and an interface?- Abstract class: An abstract class is a class that cannot be instantiated and is typically used as a base class for otherclasses. It can contain both abstract and non-abstract methods. Subclasses of an abstract class must implement its abstract methods. An abstract class can also have fields and constructors.- Interface: An interface is a collection of abstract methods and constants. It cannot be instantiated and is used to define a contract for implementing classes. A class can implement multiple interfaces, but it can only extend a single class. Interfaces are used to achieve multiple inheritance in Java.5. What are the different types of exceptions in Java? Java has two types of exceptions: checked exceptions and unchecked exceptions.- Checked exceptions: These are exceptions that are checked at compile-time. The developer must either handle these exceptions using try-catch blocks or declare them in the method signature using the 'throws' keyword. Examples of checked exceptions include IOException and SQLException.- Unchecked exceptions: These are exceptions that are not checked at compile-time. They are subclasses of RuntimeException and Error classes. Unchecked exceptions do not need to be declared or caught explicitly. Examples ofunchecked exceptions include NullPointerException and ArrayIndexOutOfBoundsException.These are just a few sample questions that can be asked during a Java interview. It is important to remember that the depth and complexity of questions may vary depending on the level of the position being applied for. It is advisable to thoroughly prepare and revise various topics related to Java programming to increase the chances of success in a Java interview.。
java 英文面试题
java 英文面试题Java面试题1. What is Java?Java is a high-level programming language developed by Sun Microsystems (now owned by Oracle) in 1995. It is widely used for developing various applications, including web and mobile applications.2. What are the key features of Java?- Platform independence: Java programs can run on any system that has a Java Virtual Machine (JVM) installed.- Object-oriented: Java follows the object-oriented programming paradigm and supports concepts like encapsulation, inheritance, and polymorphism.- Robust: Java includes features like automatic memory management (garbage collection) and exception handling, which make it less prone to errors and crashes.- Secure: Java includes built-in security features that protect against viruses, tampering, and unauthorized access.- Multithreading: Java supports multithreading, allowing programs to execute multiple tasks concurrently.- Portable: Java programs can be easily moved from one system to another without any modification.3. What is the difference between JDK, JRE, and JVM?- JDK (Java Development Kit): It includes the tools necessary for developing and running Java applications. It includes the Java compiler, debugger, and other development utilities.- JRE (Java Runtime Environment): It provides the necessary runtime environment for executing Java applications. It includes the JVM and Java libraries.- JVM (Java Virtual Machine): It is responsible for executing the Java bytecode. It provides a platform-independent execution environment for Java programs.4. What are the various access specifiers in Java?Java provides four access specifiers to control the visibility and accessibility of classes, methods, and variables:- public: Accessible from anywhere.- private: Accessible only within the same class.- protected: Accessible within the same class, package, and subclasses.- default (no specifier): Accessible within the same package.5. What are the primitive data types in Java?Java has eight primitive data types:- byte: 8-bit signed integer.- short: 16-bit signed integer.- int: 32-bit signed integer.- long: 64-bit signed integer.- float: 32-bit floating-point number.- double: 64-bit floating-point number.- boolean: true or false.- char: 16-bit Unicode character.6. What is the difference between an interface and an abstract class?- An interface is a completely abstract class that defines a contract for its implementing classes. It cannot have method implementations. In contrast, an abstract class can have both abstract and non-abstract methods.- A class can implement multiple interfaces, but it can only extend a single abstract class.- Interfaces are used to achieve multiple inheritance in Java, while abstract classes provide a way to partially implement a class.7. What is the purpose of the "final" keyword in Java?The "final" keyword in Java is used to restrict certain behaviors:- A final class cannot be inherited.- A final method cannot be overridden by subclasses.- A final variable cannot be reassigned once initialized.8. What are the differences between checked and unchecked exceptions in Java?- Checked exceptions are checked at compile-time, and the compiler forces the developers to handle them using try-catch blocks or by declaring them in the method signature. Examples include IOException and SQLException.- Unchecked exceptions do not require mandatory handling and are checked at runtime. Examples include NullPointerException and ArrayIndexOutOfBoundsException.9. What are the benefits of using Java generics?- Type safety: Generics allow you to enforce compile-time type checking, preventing type-related errors at runtime.- Code reusability: With generics, you can write a single generic method or class that can work with various types, reducing code duplication.- Performance: Generics can improve performance by eliminating the need for type casting, which can be expensive in terms of memory and processing time.10. What is the difference between method overloading and method overriding?- Method overloading occurs when a class has multiple methods with the same name but different parameters. The methods are differentiated basedon the number, order, and types of parameters.- Method overriding occurs when a subclass provides a different implementation of a method already defined in its superclass. The methodsignature (name and parameters) must be the same in both the superclass and subclass.In conclusion, these are some common Java interview questions that cover various aspects of the Java programming language. It is important to understand these concepts thoroughly to succeed in a Java interview.。
Java关于线程的面试题(英文)
Java关于线程的面试题(英文)问题:Java关于线程的面试题(英文) 回答:1. Do I need to use synchronized on setValue(int) It depends whether the method affects method local variables, class static or instance variables. If only method local variables are changed, the value is said to be confined by the method and is not prone to threading issues.2. Do I need to use synchronized on setValue(int) It depends whether the method affects method local variables, class static or instance variables. If only method local variables are changed, the value is said to be confined by the method and is not prone to threading issues.3. What is the SwingUtilities.invokeLater(Runnable) method for The static utility method invokeLater(Runnable) is intended to execute a new runnable thread from a Swing application without disturbing the normal sequence of event dispatching from the Graphical User Interface (GUI). The method places the runnable object in the queue of Abstract Windowing Toolkit (AWT) events that are due to be processed and returns immediately. The runnable object’s run() methodis only called when it reaches the front of the queue. The deferred effect of the invokeLater(Runnable) method ensures that any necessary updates to the user interface can occur immediately, and the runnable work will begin as soon as those high priority events are dealt with. The invoke later method might be used to start work in response to a button click that also requires a significant change to the user interface, perhaps to restrict other activities, while the runnable thread executes.4. What is the volatile modifier for The volatile modifier is used to identify variables whose values should not be optimized by the Java Virtual Machine, by caching the value for example. The volatile modifier is typically used for variables that may be accessed or modified by numerous independent threads and signifies that the value may change without synchronization.5. Which class is the wait() method defined in The wait() method is defined in the Object class, which is the ultimate superclass of all others. So the Thread class and any Runnable implementation inherit this method from Object. The wait() method is normally called on an object in a multi-threaded program to allow other threads to run. The method shouldshould only be called by a thread that has ownership of the object’s monitor, which usually means it is in a synchronized method or statement block.6. Which class is the wait() method defined in I get incompatible return type for my thread’s getState( ) method! It sounds like your application was built for a Java software development kit before Java 1.5. The Java API Thread class method getState() was introduced in version 1.5. Your thread method has the same name but different return type. The compiler assumes your application code is attempting to override the API method with a different return type, which is not allowed, hence the compilation error.7. What is a working thread A working thread, more commonly known as a worker thread is the key part of a design pattern that allocates one thread to execute one task. When the task is complete, the thread may return to a thread pool for later use. In this scheme a thread may execute arbitrary tasks, which are passed in the form of a Runnable method argument, typically execute(Runnable). The runnable tasks are usually stored in a queue until a thread host is available to run them. The worker thread design pattern is usually used to handle many concurrent tasks where it is notimportant which finishes first and no single task needs to be coordinated with another. The task queue controls how many threads run concurrently to improve the overall performance of the system. However, a worker thread framework requires relatively complex programming to set up, so should not be used where simpler threading techniques can achieve similar results.8. What is a green thread A green thread refers to a mode of operation for the Java Virtual Machine (JVM) in which all code is executed in a single operating system thread. If the Java program has any concurrent threads, the JVM manages multi-threading internally rather than using other operating system threads. There is a significant processing overhead for the JVM to keep track of thread states and swap between them, so green thread mode has been deprecated and removed from more recent Java implementations. Current JVM implementations make more efficient use of native operating system threads.9. What are native operating system threads Native operating system threads are those provided by the computer operating system that plays host to a Java application, be it Windows, Mac or GNU/Linux. Operating system threadsenable computers to run many programs simultaneously on the same central processing unit (CPU) without clashing over the use of system resources or spending lots of time running one program at the expense of another. Operating system thread management is usually optimised to specific microprocessor architecture and features so that it operates much faster than Java green thread processing.。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
内容摘要:本文是本站从国外知名的java技术网站搜来的,为即将参加IT外企的java软件工程师面试的开发人员精心准备的。
软件开发行业的外企面试一般都是全英文哦(技术面试和非技术面试)。
内容正文:
* Q16. Can an inner class declared inside of a method access local variables of this method?
A. It's possible if these variables are final.
* Q17. What can go wrong if you replace && with & in the following code: String a=null; if (a!=null && a.length()>10) {...}
A. A single ampersand here would lead to a NullPointerException.
* Q18. What's the main difference between a Vector and an ArrayList
A. Java Vector class is internally synchronized and ArrayList is not.
* Q19. When should the method invokeLater()be used?
A. This method is used to ensure that Swing components are updated through the event-dispatching thread.
* Q20. How can a subclass call a method or a constructor defined in a superclass?
A. Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor.
For senior-level developers:
** Q21. What's the difference between a queue and a stack?
A. Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule
** Q22. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?
A. Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.
** Q23. What comes to mind when you hear about a young generation in Java?
A. Garbage collection.
** Q24. What comes to mind when someone mentions a shallow copy in Java?
A. Object cloning.
** Q25. If you're overriding the method equals() of an object, which other method you might also consider?
A. hashCode()
** Q26. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use:
ArrayList or LinkedList?
A. ArrayList
** Q27. How would you make a copy of an entire Java object with its state?
A. Have this class implement Cloneable interface and call its method clone().
** Q28. How can you minimize the need of garbage collection and make the memory use more effective?
A. Use object pooling and weak object references.
** Q29. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?
A. If these classes are threads I'd consider notify() or notifyAll(). For regular classes you can use the Observer interface.
** Q30. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?
A. You do not need to specify any access level, and Java will use a default package access level.
The J2EE questions are coming soon. Stay tuned for Yakov Fain on Live . Ask your questions to Yakov on the air!。