Chapter 1 A Quick Tour

本文深入探讨了Java的基本数据类型、对象与引用的区别、数组特性、异常处理机制、泛型使用方法及注解的应用,并提供了丰富的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1)      boolean  /ˈbuliən/

2)      char: 16-bit Unicode UTF-16 character(unsigned)

3)      long: 64-bit integer(signed)

4)     A final field or variable is one that once initialized can never have its value changed.

Named Constants: static final int MAX = 50;

The order of the modifiers final and static makes no difference.

5)     Java program is written in Unicode Characters, that means the statement:

static final int 年龄=27;

is legal.

6)     DO NOT CONFUSE object with object reference.

Object o; //declare a reference without initialization

Object o = new Object(); //declare and initialize an object of Object

Code:

public class Point {
       private int x, y;
       Point(int x, int y){ this.x = x; this.y = y; }
       void set(int x, int y){ this.x = x; this.y = y; }
       void print(){  System.out.println( x +"," + y ); }
      
       public static void main(String[] args){
              Point p1 = new Point(1,1);
              Point p2 = new Point(2,2);
              p1.print();
              p2.print();
             
              p2 = p1; // now object p1 and p2 refer to the same object
              p1.print();
              p2.print();
             
              p1.set(3, 3);
              p1.print();
              p2.print();
       }
}

Output:

1,1

2,2

1,1

1,1

3,3

3,3

7)     An array’s length is fixed when it is created and can never change, and array objects have a length field that tells how many elements the array contains.

8)     Comparing String objects:

a)     if( str1.equals(str2) ) // test whether str1 and str2’s contents are same

b)     if( str1==str2 ) //test whether str1 and str2 refer to the same String object

Code 1:

public class StringTest {
	public static void main(String[] args) {
		String str1 = "JavaBeta";
		String str = "Java";
		String str2 = str + "Beta";
		if (str1.equals(str2))
			System.out.println("Content Identical");
		else
			System.out.println("Content NOT Identical");

		if (str1 == str2)
			System.out.println("Reference Identical");
		else
			System.out.println("Reference NOT Identical");
	}
}

Output 1:
Content Identical

Reference NOT Identical

Code 2:

public class StringTest {
	public static void main(String[] args) {
		String str1 = "JavaBeta";
		String str2 = "JavaBeta";
		if (str1.equals(str2))
			System.out.println("Content Identical");
		else
			System.out.println("Content NOT Identical");

		if (str1 == str2)
			System.out.println("Reference Identical");
		else
			System.out.println("Reference NOT Identical");

		str1 += "Beta";

		if (str1.equals(str2))
			System.out.println("Content Identical");
		else
			System.out.println("Content NOT Identical");

		if (str1 == str2)
			System.out.println("Reference Identical");
		else
			System.out.println("Reference NOT Identical");
		System.out.println(str1);
		System.out.println(str2);
	}
}


Output 2:
Content Identical
Reference Identical
Content NOT Identical
Reference NOT Identical
JavaBetaBeta
JavaBeta


Explanation:
Initially, str1 and str2 refers to the same object “JavaBeta”, while str1 is changed, so str1 and str2 has their own copy.


9)    Get used to using %n instead of \n to insert a line-separator.
10)  Classes that do not explicitly extend any other class implicitly extend the Object class.
11)  In Java, you can define multiple top level classes in a single file, providing that at most one of these is public.
12)  Wild Card:
Code:

public interface Lookup<T> {
	T find(String str);
}

public class IntegerLookup implements Lookup<Integer>{
	public Integer find(String str) {
		if(str == null || str.length() == 0) return null;
		return new Integer(1);		
	}
}

public class Run {
	public static void processValues(String str, Lookup<?> table) {
		Object o = table.find(str);
		if(o != null) System.out.println(o.toString());
		else System.out.println("null String");
	}
	
	public static void main(String[] args) {
		String str1 = null;
		String str2 = "JavaBeta";
		IntegerLookup tmp = new IntegerLookup();
		Run.processValues(str1, tmp);
		Run.processValues(str2, tmp);
	}
}

Output:
 null String
1

The wild card is written as ? and is read as “of unspecified type”, or just as “of some type”. Bounded wild card could be written as? extends Number, that is the type of the Generic Type has to be subtype of Number.

13)  Checked Exceptions and Unchecked Exceptions:
Code:

class BadDataSetException extends Exception{ }
 
class MyUtilities {
    public double[] getDataSet(String setName) throws BadDataSetException {
        String file = setName +".dset";
        FileInputStream in = null;
        try {
            in = new FileInputStream(file);
            return readDataSet(in);
        } catch (IOException e) {
            throw new BadDataSetException();
        } finally {
            try {
                if (in != null)
                    in.close();
            } catch (IOException e) {
                ;    // ignore: we either read the data OK
                     // or we're throwingBadDataSetException
            }
        }
    }
    // ... definition of readDataSet ...
}

If a method's execution can result in checked exceptions being thrown, it must declare the types of these exceptions in a throws clause, as shown for the getdataSet method. A method can throw only those checked exceptions it declares. This is why they are called checked exceptions.  It may throw those exceptions directly with throw or indirectly by invoking a method that throws exceptions. Exceptions of type RuntimeException, Error, or subclasses of these exception types are unchecked exceptions and can be thrown anywhere, without being declared.


14)  Annotations provide information about your program, or the elements of that program, in a structured way that is amenable to automated processing by external tools.
Example:

@interface Author {
	String author();
	int date();
}

@Author(author = "JavaBeta", date = 20140218)
public class Annotation {
	public static void main(String[] args) {
		System.out.println("Annotation");
	}
}

后文代码无意义,是博客系统错误。





























                
内容概要:本书《Deep Reinforcement Learning with Guaranteed Performance》探讨了基于李雅普诺夫方法的深度强化学习及其在非线性系统最优控制中的应用。书中提出了一种近似最优自适应控制方法,结合泰勒展开、神经网络、估计器设计及滑模控制思想,解决了不同场景下的跟踪控制问题。该方法不仅保证了性能指标的渐近收敛,还确保了跟踪误差的渐近收敛至零。此外,书中还涉及了执行器饱和、冗余解析等问题,并提出了新的冗余解析方法,验证了所提方法的有效性和优越性。 适合人群:研究生及以上学历的研究人员,特别是从事自适应/最优控制、机器人学和动态神经网络领域的学术界和工业界研究人员。 使用场景及目标:①研究非线性系统的最优控制问题,特别是在存在输入约束和系统动力学的情况下;②解决带有参数不确定性的线性和非线性系统的跟踪控制问题;③探索基于李雅普诺夫方法的深度强化学习在非线性系统控制中的应用;④设计和验证针对冗余机械臂的新型冗余解析方法。 其他说明:本书分为七章,每章内容相对独立,便于读者理解。书中不仅提供了理论分析,还通过实际应用(如欠驱动船舶、冗余机械臂)验证了所提方法的有效性。此外,作者鼓励读者通过仿真和实验进一步验证书中提出的理论和技术。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值