1.

Q: What is HashMap and Map?
A: Map is Interface and Hashmap is class that implements that.

2.

Q: Difference between HashMap and HashTable?
A:HashMap allows null values as key and value whereas Hashtable doesnt allow

HashMap is unsynchronized and Hashtable is synchronized.

(All the elements  in the HashMap  and HashTable are not ordered).

3

.Q: Difference between Vector and ArrayList?
A: Vector is synchronized whereas arraylist is not.

(All the elements  in the Vector and ArrayList are ordered).

4.

Q: What if I write static public void instead of public static void?
A: Program compiles and runs properly.

5.

Q: What is the difference between an Interface and an Abstract class?
A:  The interface is mainly used for framework design.

An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly public and abstract .

The abstract class  is mainly used for code reuse and interface implementation.

An abstract class can have instance methods that implement a default behavior.

The methods  can be declared  as public ,private, protected; An abstract class can  also declare some variables and construction methods and staic methods, but cannot have abstract construction methods and abstract  staic  methods.

(接口和抽象类

接口更多的是在系统架构设计方法发挥作用,主要用于定义模块之间的通信契约。而抽象类在代码实现方面发挥作用,可以实现代码的重用,可以实现接口的空实现。

含有抽象方法的类必须定义为抽象类,抽象类中可以没有抽象方法。

抽象类不能实例化对象,子类需要实现抽象类中所有的抽象方法,所以抽象类中不能有抽象的构造方法和抽象静态方法,可以有构造方法和静态方法。

如果子类没有实现抽象类中的抽象方法,则子类也要定以为抽象的。

如果抽象方法实现某个接口,则子类还要实现抽象类中没有实现的接口方法。

接口可以说是抽象类的特例,接口中所有的方法必须为抽象的即 public abstract 通常省略,所有的成员变量必须为静态的 public static final .

下面比较一下两者的语法区别:

1.抽象类可以有构造方法,接口中不能有构造方法。

2.抽象类中可以有普通成员变量,接口中没有普通成员变量

3.抽象类中可以包含非抽象的普通方法,接口中的所有方法必须都是抽象的,不能有非抽象的普通方法。

4. 抽象类中的抽象方法的访问类型可以是public,protected和(默认类型,虽然

eclipse下不报错,但应该也不行),但接口中的抽象方法只能是public类型的,并且默认即为public abstract类型。

5. 抽象类中可以包含静态方法,接口中不能包含静态方法

6. 抽象类和接口中都可以包含静态成员变量,抽象类中的静态成员变量的访问类型可以任意,但接口中定义的变量只能是public static final类型,并且默认即为public static final类型。

7. 一个类可以实现多个接口,但只能继承一个抽象类。)

6.Q: What is an abstract class?

A: Abstract class must be extended. 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  must be declared as abstract class .
A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.·

7.Q: What is the difference between a constructor and a method?

A: A constructor is  used to create objects of that class. It has the same name as the class itself, has no return type.
A method is an ordinary member function of a class. It has its own name, a return type (which may be void).

8.Q: What is final?

A: A final class can’t be extended ie.,A 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).

9Q: Describe synchronization in respect to multithreading.

A: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 the same shared variable. This usually leads to serious errors.

10.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 better,cause when you are going for multiple inheritance..the only interface can help.

11.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.)

12.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.

13.Q: What is static in java?

Static means  the variables or mehods belong to the calss instead of  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.

14.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.

15.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.

16.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.

17.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.

18.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.

19.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.

20.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. 

21.Q: Do I need to import java.lang package any time? Why ?
A: No. It is by default loaded internally by the JVM.

22.Q: What are checked exceptions?
A: Checked exception are those which the Java compiler forces you to catch. e.g. IOException are checked Exceptions.

23Q: 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.

24.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.

25.Q: What is the default value of an object reference declared as an instance variable?
A: null unless we define it explicitly.

26.Q: What type of parameter passing does Java support?
A: In Java the arguments are always passed by value .

27.Q: Primitive data types are passed by reference or pass by value?
A: Primitive data types are passed by value.

28.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 .

29.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.

30.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.

31.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.

32.Q: 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.

33.Q: 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 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.

34.Q: 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.

35.Q: 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.).

36.Q: How to create custom exceptions?

A: Your class should extend class Exception, or some more specific type thereof.

37.Q: 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. and
2. List the desired exceptions in the throws clause of the method and let the caller of the method hadle those exceptions.

38.Q: 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);
Step 3: Now Create a query using :
Statement stmt = Connection.Statement(\”select * from TABLE NAME\”);
Step 4 : Exceute the query :
stmt.exceuteUpdate();

39.Q: What method must be implemented by all threads?
A: All tasks must implement the run() method, whether they are a subclass of Thread or implement the Runnable interface.

40.Q: What modifiers are allowed for methods in an Interface?
A: Only public and abstract modifiers are allowed for methods in interfaces.

41.Q: Is Empty .java file a valid source file?
A: Yes, an empty .java file is a perfectly valid source file.

42.Q: Can a .java file contain more than one java classes?
A: Yes, a .java file contain more than one java classes, provided at the most one of them is a public class.

43Q: Is String a primitive data type in Java?
A: No String is not a primitive data type in Java, even though it is one of the most extensively used object. Strings in Java are instances of String class defined in java.lang package.

44.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.

45.Q: What is transient variable?

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

46.

Question: What is OOPS?

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

47.

Question: Describe the principles of OOPS.

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

48.

uestion: Explain the different forms of Polymorphism.

Answer:The reference of the interface points to its implementation class,

The reference of the parent class points to the object of its subclass

Polymorphism exists in three distinct forms in Java:

    Method overloading

    Method overriding through inheritance

    Method overriding through the Java interface

49.

Question: What are Access Specifiers available in Java?

Answer: Access specifiers are keywords that determines the type of access to the

member of a class. These are:

Public

Protected

Private

Default

Java 英文面试题的更多相关文章

  1. Java基础机试题

    package day8;import java.util.Scanner;/** * Java基础机试题 * @author:lyrand * */public class convert {   ...

  2. JAVA 综合面试题

    JAVA 综合面试题 2007-08-12 目录 TOC \o "1-3" \h \z \u Java面试题整理 9 Java面向对象 9 1. super()与this()的区别 ...

  3. Java 面试/笔试题神整理 [Java web and android]

    Java 面试/笔试题神整理 一.Java web 相关基础知识 1.面向对象的特征有哪些方面 1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并 ...

  4. 一份最贴近真实面试的Java基础面试题

    这是一份Java基础知识的面试题.在网上的关于Java的面试题数不胜数,但认真看过感觉大多数都没有实用性,有很多是面试官根本就不会问到的,那些已经脱离了实际开发的技术问题.而这份资料来源自一份个人觉得 ...

  5. 【转载】 Java线程面试题 Top 50

    Java线程面试题 Top 50 不管你是新程序员还是老手,你一定在面试中遇到过有关线程的问题.Java语言一个重要的特点就是内置了对并发的支持,让Java大受企业和程序员 的欢迎.大多数待遇丰厚的J ...

  6. java常见面试题及答案 1-10(基础篇)

    java常见面试题及答案 1.什么是Java虚拟机?为什么Java被称作是"平台无关的编程语言"? Java 虚拟机是一个可以执行 Java 字节码的虚拟机进程.Java 源文件被 ...

  7. Java线程面试题 Top 50 (转载)

    转载自:http://www.cnblogs.com/dolphin0520/p/3958019.html 原文链接:http://www.importnew.com/12773.html   本文由 ...

  8. 经典的Java基础面试题集锦

    经典的Java基础面试题集锦,欢迎收藏和分享. 问题:如果main方法被声明为private会怎样? 答案:能正常编译,但运行的时候会提示”main方法不是public的”. 问题:Java里的传引用 ...

  9. Java线程面试题 Top 50

    转自:http://www.importnew.com/12773.html 不管你是新程序员还是老手,你一定在面试中遇到过有关线程的问题.Java语言一个重要的特点就是内置了对并发的支持,让Java ...

随机推荐

  1. Spring Boot 整合 Mybatis Annotation 注解的完整 Web 案例

    摘要: 原创出处 www.bysocket.com 「泥瓦匠BYSocket 」欢迎转载,保留摘要,谢谢! 『 公司需要人.产品.业务和方向,方向又要人.产品.业务和方向,方向… 循环』 本文提纲一. ...

  2. c#获取文件MD5算法

    //获取文件MD5算法 private static string GetMD5FromFile(string fileName) { try { FileStream file = new File ...

  3. linux 运维,代理,acl控制访问

    运维概述:运行 & 维护,Operation & MaintanceIT运维.业务运维.日常管理运维采用相关的方法.手段.技术.制度.流程和文档等,对IT运行环境.IT业务系统和IT运 ...

  4. XAF_GS_02_创建第一个XAF项目

    上一节我们讲解了如何安装XAF环境,这次我们要开始创建一个自己的XAF项目. Setp 1 第一步打开你的Visual Studio,新建项目,如下图所示,选择DevExpress XAF,选择好你的 ...

  5. caffe︱ImageData层、DummyData层作为原始数据导入的应用

    Part1:caffe的ImageData层 ImageData是一个图像输入层,该层的好处是,直接输入原始图像信息就可以导入分析. 在案例中利用ImageData层进行数据转化,得到了一批数据. 但 ...

  6. 6.2 PowerPC处理器如何处理MSI中断请求

    PowerPC处理器使用OpenPIC中断控制器或者MPIC中断控制器,处理外部中断请求.其中MPIC中断控制器基于OpenPIC中断控制器,但是作出了许多增强,目前Freescale新推出的Powe ...

  7. VxWorks下USB驱动总结2

    3:USBD驱动详解 这一部分将要描述USBD(USB Host Driver)的典型应用.例如初始化,client注册,动态连接注册,设备配置,数据传输,同时还探讨了USBD内部设计的关键特性.这部 ...

  8. Flex和Servlet结合上传文件报错(一)

    1.具体错误如下 一个表单域 不是一个表单域 java.io.FileNotFoundException: D:\MyEclipse\workspace\FlexFileUpload\Web\null ...

  9. zTree实现地市县三级级联报错(三)

    zTree实现地市县三级级联报错(三) 1.具体报错如下 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] ...

  10. VC++信息安全编程(13)Windows2000/xp/vista/7磁盘扇区读写技术

    有些时候,我们读取磁盘文件,会被hook.我们读到的可能并非实际的文件. 我们直接读取磁盘扇区获取数据. 实现磁盘数据的读写,不依赖WindowsAPI. [cpp] view plaincopy v ...