Java复习笔记

Generic 泛型
access 访问
the custom thread 自定义线程
Missing parentheses 缺少括号
synchronized 同步
simulation 模拟

linkedList removeFirst addFirst

javac 是编译器
java 是解释器

子类 = (子类)父类;
父类 = 子类;

注意throws && throw的区别

线程互斥共享变量:

class Sell extends Thread {
	public static int current = 0;
	public int threadID;
	public Sell(){
		current++;
		threadID = current;
	}
	public void run() {
		while (list.size() > 0) {
			sellTicket();
		}
	}
	public synchronized void sellTicket() {
		if (list.size() > 0) {
			ticket = List.removeFirst();
			System.out.println()	
		}	
	}
	
}

java 使用集合和map不能使用基本数据类型

java sleep的时候注意catch异常

Thread类中执行线程体的方法是start( ) ,run()是定义

在map没指明数据类型时使用get方法时需要使用强制类型转换

java io操作需要try catch 语句

文件操作需要import java.io.*

Programs written in Java can be directly interpreted(解释型) and executed, which is an interpreted programming language(x)

A class can produce multiple objects. Each object instantiated by the reserved word “new” will have its own heap(堆) memory space(√)

java path用于设置Java编译解释工具的路径
java classpath用于设置应用程序类路径
Java虚拟机 JVM是用于执行Java字节码的机器

In dos command line, the way to view and configure classpath and path environment variables is different(x)

JDK contains JRE, JRE contains JVM(√)

Overloaded constructors defined in the same class can call each other(√)

Java命名规则:
由26个英文字母大小写,0-9 ,_或 $ 组成

java %运算:
y % x = y - y / x * x

Java switch不能选择float

注意判断switch是否有break

Java 抽象类中可以不含抽象方法

接口是一种引用类型(√)

finally 语句被用来is used for handling exception process, such as releasing resources, closing files, etc…

For the order of catch clauses,子类在前,父类在后

Try block that catch the exception will be terminated(终止) when an exception occurred.

Java异常抛出的顺序是在finally语句执行完毕之后抛出的,如图:
在这里插入图片描述

【单选题】
Which one of the following problems can cause runtime(运行) errors in Java programs?
A、Incorrect case of letters
B、Missing static before main () method
C、Missing parentheses
D、Using a full-width semicolon at the end of the statement
正确答案: B

Which of the following is not a Java primitive data type?
A、int
B、Boolean
C、float
D、char
正确答案: B

The output after the execution of the following code segment is:
int x=-3;
int y=-10;
System.out.println(y%x);
A、-1
B、2
C、1
D、3
正确答案: A
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
异常类型:
在这里插入图片描述
在这里插入图片描述
结果:345
在这里插入图片描述
编译错误

输入负数检测:

import java.util.InputMismatchException;
import java.util.Scanner;

public class Sum {

    private static void test(int i) throws Exception {
        if(i < 0) {
            throw new Exception("输入负数");
        }
    }

    static public void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int input = 0, sum = 0;
        while (input != 999) {
            try {
                input = scanner.nextInt();
                test(input);
                sum += input;
            } catch (InputMismatchException e) {
                scanner.next();
            } catch (Exception ignored) {
            }
        }
        System.out.println(sum - 999);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值