Review Java advanced features

 

 

http://www.oracle.com/technetwork/java/javase/documentation/api-jsp-136079.html 

http://download.oracle.com/javase/6/docs/api/

 
Here the topics that you should master as part of your advance java study.

    Generics
        Introduction to Generics
        Type Erasure
        Type Boundaries
        Wildcards
        Generic Methods
        Strengths and Weaknesses of Generics
        Legacy Code and Generics
    Threads
        Java Thread Model
        Creating and Running Threads
        Manipulating Thread State
        Thread Synchronization
        Volatile Fields vs. Synchronized Methods
        wait and notify
        join and sleep
        The Concurrency API
        Atomic Operations
    Reflection
        Uses for Meta-Data
        The Reflection API
        The Class<T> Class
        The java.lang.reflect Package
        Reading Type Information
        Navigating Inheritance Trees
        Dynamic Instantiation
        Dynamic Invocation
        Reflecting on Generics
    Annotations
        Aspect-Oriented Programming and Java
        The Annotations Model
        Annotation Types and Annotations
        Built-In Annotations
        Annotations vs. Descriptors (XML)
    Sockets
        The OSI Reference Model
        Network Protocols
        The Socket Class
        The ServerSocket Class
        Connecting Through URL Objects
        HTTP and Other TCP Servers
        Datagram Clients and Servers
        Non-Blocking Sockets
    Database and SQL Fundamentals
        Relational Databases and SQL
        Database, Schema, Tables, Columns and Rows
        SQL Versions and Vendor Implementations
        DDL -- Creating and Managing Database Objects
        DML -- Retrieving and Managing Data
        Sequences
        Stored Procedures
        Using SQL Terminals
    JDBC Fundamentals
        What is the JDBC API?
        JDBC Drivers
        Making a Connection
        Creating and Executing a Statement
        Retrieving Values from a ResultSet
        SQL and Java Datatypes
        Creating and Updating Tables
        Handling SQL Exceptions and Proper Cleanup
        Handling SQLWarning
    Advanced JDBC
        SQL Escape Syntax
        Using Prepared Statements
        Using Callable Statements
        Scrollable Result Sets
        Updatable Result Sets
        Transactions
        Commits, Rollbacks, and Savepoints
        Batch Processing
    Introduction to Row Sets
        Row Sets in GUI and J2EE programming
        Advantages of RowSets
        RowSet Specializations
        Using CachedRowSets
    Design Patterns
        What are Design Patterns?
        Singleton, Factory Method, Abstract Factory
        Adapter, Composite, Decorator
        Chain of Responsibility, Observer / Publish-Subscribe, Strategy, Template
        Data Access Object (DAO)

 

1. Generics: type parameter <>, wildcard type <?>, Bounds for Type Variables, type erasure

 

Generics allow "a type or method to operate on objects of various types while providing compile-time type safety."

 

  • A type variable is an unqualified identifier. Type variables are introduced by generic class declarations, generic interface declarations, generic method declarations, and by generic constructor declarations.
  • A class is generic if it declares one or more type variables. These type variables are known as the type parameters of the class. It defines one or more type variables that act as parameters. A generic class declaration defines a set of parameterized types, one for each possible invocation of the type parameter section. All of these parameterized types share the same class at runtime.
  • An interface is generic if it declares one or more type variables. These type variables are known as the type parameters of the interface. It defines one or more type variables that act as parameters. A generic interface declaration defines a set of types, one for each possible invocation of the type parameter section. All parameterized types share the same interface at runtime.
  • A method is generic if it declares one or more type variables. These type variables are known as the formal type parameters of the method. The form of the formal type parameter list is identical to a type parameter list of a class or interface.
  • A constructor can be declared as generic, independently of whether the class of the constructor is declared in is itself generic. A constructor is generic if it declares one or more type variables. These type variables are known as the formal type parameters of the constructor. The form of the formal type parameter list is identical to a type parameter list of a generic class or interface.

 

Type parameter:

Before Java SE 5.0, generic programming in Java was always achieved with inheritance.
The ArrayList class simply maintained an array of Object references:
    public class ArrayList // before Java SE 5.0
    {
        public Object get(int i) { . . . }
        public void add(Object o) { . . . }
        . . .
        private Object[] elementData;
    }
This approach has two problems. A cast is necessary whenever you retrieve a value:
    ArrayList files = new ArrayList();
    . . .
    String filename = (String) names.get(0);
Moreover, there is no error checking. You can add values of any class:
    files.add(new File(". . ."));
This call compiles and runs without error. Elsewhere, casting the result of get to a String
will cause an error.
Generics offer a better solution: type parameters. The ArrayList class now has a type
parameter that indicates the element type:
    ArrayList<String> files = new ArrayList<String>();

wildcard type:
The ArrayList class has a method addAll to add all elements of another collection. A programmer may want to add all elements from an ArrayList<Manager> to an ArrayList<Employee>. But, of course, doing it the other way around should not be legal. How do you allow one call and disallow the other? The Java language designers invented an ingenious new concept, the wildcard type, to solve this problem. Wildcard types are rather abstract, but they allow a library builder to make methods as flexible as possible.

NOTE: It is common practice to use uppercase letters for type variables, and to keep them short. The Java library uses the variable E for the element type of a collection, K and V for key and value types of a table, and T (and the neighboring letters U and S, if necessary) for “any type at all”.

C++ NOTE: Superficially, generic classes in Java are similar to template classes in C++. The only obvious difference is that Java has no special template keyword. However, as you will see throughout this chapter, there are substantial differences between these two mechanisms.
bounds for type variables:

Sample:public static <T extends Comparable> T min(T[] a) . . .

 

A type variable or wildcard can have multiple bounds. For example: T extends Comparable & Serializable

translate generics:

NOTE: The virtual machine does not have objects of generic types—all objects belong to ordinary classes. So compiler inserts casts to translate generic calls to virtual machine instructions.
type erasure:

 

 

Your programs may contain different kinds of Pair, such as Pair<String> or Pair<Gregorian-Calendar>, but erasure turns them all into raw Pair types. 

 

Restrictions and Limitations:
  1. Type Parameters Cannot Be Instantiated with Primitive Types (double, int, ...: eight primitive types)
  2. Runtime Type Inquiry Only Works with Raw Types
  3. You Cannot Throw or Catch Instances of a Generic Class
  4. Arrays of Parameterized Types Are Not Legal
  5. You Cannot Instantiate Type Variables
  6. Type Variables Are Not Valid in Static Contexts of Generic Classes
  7. Beware of Clashes After Erasure
  8. Inheritance Rules for Generic Types
  9. Wildcard Types
 

 

1.1 Generic class sample 

 

1.1.1 Sample 1

class Gen<T> {
    private T ob; //定义泛型成员变量
    public Gen(T ob) {
        this.ob=ob;
    }
    public T getOb() {
        return ob;
    }
    public void setOb(T ob) {
        this.ob = ob;
    }
    public void showType() {
        System.out.println("T的实际类型是: " + ob.getClass().getName());
    }
}

 

public class GenDemo {
    public static void main(String[] args) {
        //定义泛型类Gen的一个Integer版本
        Gen<Integer> intOb=new Gen<Integer>(88);
        intOb.showType();
        int i= intOb.getOb();
        System.out.println("value= " + i);
        System.out.println("----------------------------------");
        //定义泛型类Gen的一个String版本
        Gen<String> strOb=new Gen<String>("Hello Gen!");
        strOb.showType();
        String s=strOb.getOb();
        System.out.println("value= " + s);
    }
}


1.1 Sample 2

 

 

class Gen2 {
    private Object ob; //定义泛型成员变量
    public Gen2(Object ob) {
        this.ob=ob;
    }
    public Object getOb() {
        return ob;
    }
    public void setOb(Object ob) {
        this.ob = ob;
    }
    public void showType() {
        System.out.println("T的实际类型是: " + ob.getClass().getName());
    }
}

 

public class GenDemo2 {
    public static void main(String[] args) {
        //定义泛型类Gen的一个Integer版本
        Gen2 intOb=new Gen2(new Integer(88));
        intOb.showType();
        int i= (Integer)intOb.getOb();
        System.out.println("value= " + i);
        System.out.println("----------------------------------");
        //定义泛型类Gen的一个String版本
        Gen2 strOb=new Gen2("Hello Gen!");
        strOb.showType();
        String s=(String)strOb.getOb();
        System.out.println("value= " + s);
    }
}

 

Both samples' result is:

 

T的实际类型是: java.lang.Integer
value= 88
----------------------------------
T的实际类型是: java.lang.String
value= Hello Gen!

 

1.2 Generic method sample

 

public class genericMethod {
    public static <T> T getMiddle(T[] a){
        return a[a.length/2];
    }
    public static void main(String[] args) {
        String[] names = { "John", "Mark", "Public" };
        String middle = genericMethod.<String>getMiddle(names);
        System.out.println(middle);
    }
}
 

 

 

2. Reflection  

 

http://download.oracle.com/javase/tutorial/reflect/ 

 

Reflection is a feature in the Java programming language. It allows an executing Java program to examine or "introspect" upon itself, and manipulate internal properties of the program. For example, it's possible for a Java class to obtain the names of all its members and display them.

 

Java reflection relative API is in package java.lang.reflect.

 

 

A Simple Example

To see how reflection works, consider this simple example:

 

 

    import java.lang.reflect.*;
    public class DumpMethods {
      public static void main(String args[])
      {
         try {
            Class c = Class.forName(args[0]);
            Method m[] = c.getDeclaredMethods();
            for (int i = 0; i < m.length; i++)
            System.out.println(m[i].toString());
         }
         catch (Throwable e) {
            System.err.println(e);
         }
      }
   }

 

For an invocation of:

  java DumpMethods java.util.Stack

 

 

the output is:

  public java.lang.Object java.util.Stack.push(
    java.lang.Object)
   public synchronized
     java.lang.Object java.util.Stack.pop()
   public synchronized
      java.lang.Object java.util.Stack.peek()
   public boolean java.util.Stack.empty()
   public synchronized
     int java.util.Stack.search(java.lang.Object)

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/markjiao/archive/2011/11/07/2239164.html

内容概要:本文深入探讨了软件项目配置管理在汽车开发领域的应用及其重要性,强调配置管理不仅是版本控制,更是涵盖标识、追溯、结构化等多方面的深度管控。文章通过对比机械产品和软件产品的标签管理,揭示了软件配置管理的独特挑战。配置管理构建了一个“网”状体系,确保软件产品在复杂多变的开发环境中保持稳定和有序。文中还讨论了配置管理在实际工作中的困境,如命名混乱、文档更新不及时、发布流程冗长等问题,并提出了通过结构可视化、信息同源化、痕迹自动化和基线灵活化等手段优化配置管理的具体方法。 适合人群:具备一定软件开发和项目管理经验的工程师及项目经理,尤其是从事汽车电子软件开发的相关人员。 使用场景及目标:①理解配置管理在汽车软件项目中的核心作用;②学习如何通过工具链(如Polarion、JIRA、飞书等)优化配置管理流程;③掌握结构可视化、信息同源化、痕迹自动化和基线灵活化等关键技术手段,提升项目管理水平。 其他说明:配置管理不仅是技术问题,更涉及到项目管理和团队协作。文中强调了工具链的应用和优化的重要性,但同时也指出,工具本身并不能解决所有问题,关键在于如何合理使用工具并不断优化管理流程。文章呼吁读者成为长期主义者,相信时间的力量,持续改进配置管理工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值