笔记有关Java的一些问题

来源:互联网 发布:阿里云域名管理地址 编辑:程序博客网 时间:2024/05/22 10:24
1.如何定义常量:
用static final关键字来定义

2.哪个是同步的?
Hashtable: Hashtable is synchronized.

Vector:Vector is synchronized.

TreeSet:

Note that this implementation is not synchronized. If multiple threads access a tree set concurrently, and at least one of the threads modifies the set, it must be synchronized externally. This is typically accomplished by synchronizing on some object that naturally encapsulates the set. If no such object exists, the set should be "wrapped" using the Collections.synchronizedSortedSet method. This is best done at creation time, to prevent accidental unsynchronized access to the set:

   SortedSet s = Collections.synchronizedSortedSet(new TreeSet(...));

LinkedList:

Note that this implementation is not synchronized. If multiple threads access a linked list concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list. If no such object exists, the list should be "wrapped" using the Collections.synchronizedList method. This is best done at creation time, to prevent accidental unsynchronized access to the list:
   List list = Collections.synchronizedList(new LinkedList(...));
注:Vector和Hashtable是两个古老的集合类,Vector实现了List接口,Hashtable实现了Map接口,只有这两个(Vector和Hashtable)是同步的,其他都使非同步的。Hashtable不允许null作为key或者value。Vector底层由动态数组实现。

3. JDBC Transaction Isolation Levels

If a DBMS supports transaction processing, it will have some way of managing potential conflicts that can arise when two transactions are operating on a database at the same time. A user can specify a transaction isolation level to indicate what level of care the DBMS should exercise in resolving potential conflicts. For example, what happens when one transaction changes a value and a second transaction reads that value before the change has been committed or rolled back? Should that be allowed, given that the changed value read by the second transaction will be invalid if the first transaction is rolled back? A JDBC user can instruct the DBMS to allow a value to be read before it has been committed (a "dirty read") with the following code, where con is the current connection:

con.setTransactionIsolation(TRANSACTION_READ_UNCOMMITTED);

The higher the transaction isolation level, the more care is taken to avoid conflicts. The Connection interface defines five levels, with the lowest specifying that transactions are not supported at all and the highest specifying that while one transaction is operating on a database, no other transactions may make any changes to the data read by that transaction.
  TRANSACTION_READ_UNCOMMITTED, used in the previous example, is one level up from the lowest level. Typically, the higher the level of isolation, the slower the application executes (due to increased locking overhead and decreased concurrency between users). The developer must balance the need for performance with the need for data consistency when making a decision about what isolation level to use. Of course, the level that can actually be supported depends on the capabilities of the underlying DBMS.

When a new Connection object is created, its transaction isolation level depends on the driver, but normally it is the default forthe  underlying data source. A user may call the method setIsolationLevel to change the transaction isolation level, and the new level will be in effect for the rest of the connection session. To change the transaction isolation level for just one transaction, one needs to set it before executing any statements in the transaction and then reset it after the transaction terminates. Changing thetransaction isolation level during a transaction is not recommended, for it will trigger an immediate call to the methodcommit, causing any changes up to that point to be made permanent.

4. Apache Web Server 区别于其他应用服务器的主要特点
The Apache HTTP Server ("httpd") is a project of The Apache Software Foundation.
The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.

Subprojects

  • Docs
  • Test
  • Flood
  • libapreq
  • Modules
  • mod_fcgid
  • mod_ftp
The Difference Between the Apache Web Server and the Tomcat Server:

History

  • The Apache Software Foundation got its start in 1995 with its first project, the Apache Hypertext Transfer Protocol (HTTP) Server, also known as Apache Web Server. The project evolved from the httpd software developed by the National Center for Super Computing (NCSA), which was the most popular web server on the Internet at the time. The first Apache Web Server was released in December 1995.

    The Tomcat server got its start at Sun Microsystems, the creators of the Java programming language, as a server implementing the Java Servlets and JavaServer Pages (JSP) specification. Sun Microsystems donated the code to the Apache Software Foundation in 1999. Apache's first Tomcat server release was version 3.0 in 1999.

Function

  • Apache Web Server is software that resides on a network-connected computer, accepts requests from web browsers and other clients on remote computers, and responds by sending back the content requested. The content can be static files, such as web pages and images, or the results of executable files, such as PHP and Perl scripts.

    Tomcat Server is a specialized web server called a "servlet container." It features a basic web server customized to execute Java servlets and JSP pages.

Benefits

  • Apache Web Server offers flexibility, both natively and through add-ons called "modules" or simply "mods." It can be configured to handle requests for dynamic content driven by a wide range of languages and technologies, including Perl, Python, PHP, Ruby, ASP and binary executables. Apache can also be configured to use the Tomcat server as a back-end handler for servlets and JSP pages. Other modules for Apache Web Server provide added functionality, such as generating formatted directory views, serving web content from user directories, authentication, SSL, WebDAV and response content compression. The popularity of the Apache Web Server has led to extensive third-party development for the package.

    Tomcat, as a stand-alone web server, offers optimization for servlets and JSP pages. Tomcat can be configured to serve dynamic content generated by Common Gateway Interface (CGI), PHP, Ruby and other technologies.

Considerations

  • Websites serving only static content, servlets and JSP pages often choose to use the Tomcat as the primary web server because it offers enhanced performance over the Apache Web Server. Tomcat can also serve as back-end servlet container for the Apache Web Server. While this configuration can affect overall performance, it provides the additional flexibility that Apache offers for configuring complex, multi-user environments.

Warnings

  • Results may vary. There is some debate over whether Tomcat Server or Apache Web Server is the faster web server. Server performance is dependent on the configuration of the server software. Start-up options, optimizations, performance tuning, and other settings all affect performance. As a result, performance comparisons don't always illustrate a clear winner. Ultimately, the choice to use one, the other, or a combination of both is dependent not on performance, but on requirements and preference.

Read more: The Difference Between the Apache Web Server and the Tomcat Server | eHow.com http://www.ehow.com/about_5525825_difference-apache-server-tomcat-server.html#ixzz1gsPThXiM

5. 如下哪些可以被继承
java.lang.Thread 普通类
Thread类是可以被继承的,一个线程的的一种方式就是继承Thread类

java.lang.Number抽象类
The abstract class Number is the superclass of classes BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, and Short.
Subclasses of Number must provide methods to convert the represented numeric value to byte, double, float, int, long, and short.

java.lang.Double,java.lang.Math, 由final修饰,不能被继承,

java.lang.ClassLoader是抽象类,可以被继承,可以实现在自己的类加载器的。