Frenquently asked interview questions

2024-01-11 20:48

本文主要是介绍Frenquently asked interview questions,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 1.    what is the difference between an applet and an application? 【程序编程相关:利用Reflection API访问类的】

 

java questions & answers 【推荐阅读:软件开发尽量采用成熟的FrameWork】

a java applet is made up of at least one public class that has to be subclassed from java.awt.applet. the applet is confined to living in the users web browser, and the browsers security rules, (or suns appletviewer, which has fewer restrictions). 【扩展信息:先贴段jsp代码试试】

a java application is made up of a main() method declared as public static void that accepts a string array argument, along with any other classes that main() calls. it lives in the environment that the host os provides.

the differences between an applet and an application are as follows:

1. applets can be embedded in html pages and downloaded over the internet whereas applications have no special support in html for embedding or downloading.

2. applets can only be executed inside a java compatible container, such as a browser or appletviewer whereas applications are executed at command line by java.exe or jview.exe.

3. applets execute under strict security limitations that disallow certain operations(sandbox model security) whereas applications have no inherent security restrictions.

4. applets dont have the main() method as in applications. instead they operate on an entirely different mechanism where they are initialized by init(),started by start(),stopped by stop() or destroyed by destroy().

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

3. what is rmi? 【程序编程相关:利用Reflection API访问类的】

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. 【推荐阅读:软件开发尽量采用成熟的FrameWork】

4. what gives java its "write once and run anywhere" nature? 【扩展信息:先贴段jsp代码试试】

rmi stands for remote method invocation. traditional approaches to executing code on other machines across a network have been confusing as well as tedious and error-prone to implement. the nicest way to think about this problem is that some object happens to live on another machine, and that you can send a message to the remote object and get a result as if the object lived on your local machine. this simplification is exactly what java remote method invocation (rmi) allows you to do.

java is compiled to be a byte code which is the intermediate language between source code and machine code. this byte code is not platorm specific and hence can be fed to any platform. after being fed to the jvm, which is specific to a particular operating system, the code platform specific machine code is generated thus making java platform independent.

a class can only directly extend one class at a time. multiple inheritance is only allowed with regard to interfaces. a class can implement many interfaces. but a class can only extend one non-interface class. 【程序编程相关:利用Reflection API访问类的】

5. how does java inheritance work? 【推荐阅读:软件开发尽量采用成熟的FrameWork】

native methods are used when the implementation of a particular method is present in language other than java say c, c++. 【扩展信息:先贴段jsp代码试试】

6. what are native methods? how do you use them?

to use the native methods in java we use the keyword native

 

public native method_a()

 

this native keyword is signal to the java compiler that the implementation of this method is in a language other than java.

 

native methods are used when we realize that it would take up a lot of rework to write that piece of already existing code in other language to java.

 

7. class a subclass b subclass c. all override foo(). i cast c to a and call foo(). what happens? can c call a->foo()?

an instance of class c is of type class b and a (both). so you can cast c to a. you cannot cast an instance of a to c.

8. what does the "static" keyword mean in front of a variable? a method? a class? curly braces {}?

-- static methods: 【程序编程相关:利用Reflection API访问类的】

-- static variables: these are class level variable whose value remain same irrespective of the number of instances of the class. 【推荐阅读:软件开发尽量采用成熟的FrameWork】

-- static block: these are called before the main is called and are called only once. subsequent invocation of the java program containing static block would not call it again. hence, they can be used to load libraries say in native function call. 【扩展信息:先贴段jsp代码试试】

these are those methods that can be called without the need for creating the objects of the class i.e. they are class level methods. they can call only static methods. they cannot refer to "this" as they are not associated with any particular instance.

 

-- only inner class could be declared as a "static". this declaration suppress the generation of the reference to the outer class object. 这意味着:1)为创建一个static内部类的对象,我们不需要一个外部类对象;2)不能从static内部类对象访问一个外部类对象.

9. how many different types of jdbc drivers are present? discuss them.

there are four jdbc driver types.

 

type 1: jdbc-odbc bridge plus odbc driver:

 

the first type of jdbc driver is the jdbc-odbc bridge. it is a driver that provides jdbc access to databases through odbc drivers. the odbc driver must be configured on the client for the bridge to work. this driver type is commonly used for prototyping or when there is no jdbc driver available for a particular dbms.

type 3: jdbc-net pure java driver: 【程序编程相关:利用Reflection API访问类的】

 

the native to api driver converts jdbc commands to dbms-specific native calls. this is much like the restriction of type 1 drivers. the client must have some binary code loaded on its machine. these drivers do have an advantage over type 1 drivers because they interface directly with the database. 【推荐阅读:软件开发尽量采用成熟的FrameWork】

 

type 4: native-protocol pure java driver 【扩展信息:先贴段jsp代码试试】

 

the jdbc-net drivers are a three-tier solution. this type of driver translates jdbc calls into a database-independent network protocol that is sent to a middleware server. this server then translates this dbms-independent protocol into a dbms-specific protocol, which is sent to a particular database. the results are then routed back through the middleware server and sent back to the client. this type of solution makes it possible to implement a pure java client. it also makes it possible to swap databases without affecting the client.

 

these are pure java drivers that communicate directly with the vendors database. they do this by converting jdbc commands directly into the database engines native protocol. this driver has no additional translation or middleware layer, which improves performance tremendously.

 

10. does java have "goto"?

yes and no. there is no "goto" operator used in java, but it is a reserved keyword, and one can use break statements to branch to a labelled statement, exactly as one would use a goto.

11. why "bytecode"? can you reverse-engineer the code from bytecode?

12. how does exception handling work in java? 【程序编程相关:利用Reflection API访问类的】

yes, with some tools. 【推荐阅读:软件开发尽量采用成熟的FrameWork】

2.it allows a clean path for error propagation. if the called method encounters a situation it cant manage, it can throw an exception and let the calling method deal with it. 【扩展信息:先贴段jsp代码试试】

1.it separates the working/functional code from the error-handling code by way of try-catch clauses.

3.by enlisting the compiler to ensure that "exceptional" situations are anticipated and accounted for, it enforces powerful coding.

4.exceptions are of two types: compiler-enforced exceptions, or checked exceptions and runtime exceptions, or unchecked exceptions. compiler-enforced (checked) exceptions are instances of the exception class or one of its subclasses -- excluding the runtimeexception branch. the compiler expects all checked exceptions to be appropriately handled. checked exceptions must be declared in the throws clause of the method throwing them -- assuming, of course, theyre not being caught within that same method. the calling method must take care of these exceptions by either catching or declaring them in its throws clause. thus, making an exception checked forces us to pay heed to the possibility of it being thrown. an example of a checked exception is java.io.ioexception. as the name suggests, it throws whenever an input/output operation is abnormally terminated.

13. does java have destructors?

java does not have destructors. garbage collector does this job periodically depending upon the memory requirements of the machine and on the fact that a particular object is no longer needed.

public void finalize() { } 【程序编程相关:利用Reflection API访问类的】

 

but it has finalizers that does a similar job. the syntax is 【推荐阅读:软件开发尽量采用成熟的FrameWork】

14. what does the "final" keyword mean in front of a variable? a method? a class? 【扩展信息:先贴段jsp代码试试】

if an object has a finalizer, the method is invoked before the system garbage collects the object, but using finalize() does not guarantee that it would be called b4 garbage collector is invoked.

a final variable cannot be reassigned, but it is not constant. for instance,

final stringbuffer x = new stringbuffer();

 

x.append("hello");

 

is valid. x cannot have a new value in it, but nothing stops operations on the object that it refers, including destructive operations.

 

also, a final method cannot be overridden or hidden by new access specifications. this means that the compiler can choose to in-line the invocation of such a method. (i dont know if any compiler actually does this, but its true in theory.)

the best example of a final class is string, which defines a class that cannot be derived.

15. access specifiers: "public", "protected", "private", nothing?

public?  any other class from any package can instantiate and execute the classes and methods

protected? only subclasses and classes inside of the package can access the classes and methods

 

private? the original class is the only class allowed to execute the methods.

 

and in case if there is no modifier specified, it means, only the classes inside the package can access this class and its methods, it is also called "friendly".

这篇关于Frenquently asked interview questions的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/595653

相关文章

ural 1026. Questions and Answers 查询

1026. Questions and Answers Time limit: 2.0 second Memory limit: 64 MB Background The database of the Pentagon contains a top-secret information. We don’t know what the information is — you

Interview preparation--elasticSearch倒排索引原理

搜索引擎应该具备哪些要求 查询速度快 优秀的索引结构设计高效率的压缩算法快速的编码和解码速度 结果准确 ElasiticSearch 中7.0 版本之后默认使用BM25 评分算法ElasticSearch 中 7.0 版本之前使用 TP-IDF算法 倒排索引原理 当我们有如下列表数据信息,并且系统数据量达到10亿,100亿级别的时候,我们系统该如何去解决查询速度的问题。数据库选择—mysq

PHP interview

01 输入open_door 返回 OpenDoor <?php$str = "open_door";$arr = explode('_',$str);foreach($arr as $v){$new = ucwords($v);$ret .= $new;}echo $ret;?> 02 反转字符串 <?phpfunction revstr($str){$len = strlen($

About interview Questions Collection(Basic,Intermediate and Advanced) in MySQL

Basic MySQL Interview Questions 1.What is Mysql? Database management system for web servers 2.What are some of the advantages of using MySQL? FlexibilityPowerEnterprise-Level SQL FeatureFull-Text

{ Cracking The Coding Interview: 150 programming QA } --- Arrays and Strings

Hashtable, ArrayList (Dynamically resizing array, providing O(1) access), StringBuffer (do string concatenation) 1. 判断string是否有重复字符,不允许使用其他数据结构。 Step 1: 问清楚限制,string的编码是ASCII还是Unicode a. 如果可以用其他数

Interview preparation--RabbitMQ

AMQP AMQP(Advanced Message Queueing protocol). 高级消息队列协议,是进程之间床底一步新消息的网络协议AMQP工作原理如下: 发布者(Publisher)发布消息(Message)经过交换机(Exchange),交换机根据绑定的路由规则(RoutingKey)将收到消息分发给交换机绑的队列(Queue),最后AMQP代理会将消息投递给订阅了此队列的消费

C - Job Interview

思路: 先不考虑溢出,将n+m+1按照分配的工作分类 会发现,有且仅有一种工作的人数是溢出的,即超过了上限,记作工作1;且另一种工作的人数没有溢出,记作工作2 工作2因为没有溢出,不管没来的那个人是谁,工作2的人还是做工作2,不受影响 工作1溢出了,若没来的那个人在工作1前n个位置,答案是工作1前n+1个人做工作1+其他人做工作2-没来的那个人做工作1; 其他情况答案是前n个人做工作1+

【Interview】深入理解阻塞队列之ArrayBlockingQueue

概述 ArrayBlockingQueue是一个由数组构成的有界阻塞队列,此队列按 FIFO(先进先出)原则对元素进行排序,支持公平和非公平模式,默认情况下不保证线程公平的访问队列。新元素插入到队列的尾部,队列获取操作则是从队列头部开始获得元素 常用方法 ArrayBlockingQueue(int capacity) 创建一个固定容量和默认非公司访问策略队列ArrayBlockingQu

【Interview】深入理解ConcurrentLinkedQueue源码

文章目录 概述常用方法源码分析offer入队操作初始化出队操作 总结 概述 ConcurrentLinkedQueue是一个基于链接节点的无边界的线程安全队列,它采用先进先出原则对元素进行排序,插入元素放入队列尾部,出队时从队列头部返回元素,利用CAS方式实现的ConcurrentLinkedQueue的结构由头节点和尾节点组成的,都是使用volatile修饰的。每个节点由节点

【Interview】深入理解ThreadLocal源码

概述 ThreadLocal 是一个本地线程副本变量工具类。主要用于将私有线程和该线程存放的副本对象做一个映射,各个线程之间的变量互不干扰。在高并发场景下,可以实现无状态的调用,适用于各个线程不共享变量值的操作。内部使用静态内部类ThreadLocalMap存储每个线程变量副本的方法,key存储的是当前线程的ThreadLocal对象,value就是当前ThreadLocal对应的线程变量的的副