java小结

int i=1;int j;j=i++;(结果i=2,j=1);减法同理

int i=1;int j;j=++i;(结果i=2,j=2);

 int i=5;
  do {
System.out.println(i);
} while (i-->3);输出5,4,3

 int i=5;
  do {
System.out.println(i);
} while (--i>3);输出5,4

2.

arithmetic right shift operator,算术右移运算符,>>表示带符号右移,左边补上符号位 

logical right shift operator,逻辑右移运算符;>>>无符号右移无符号,左边补0 

3正确表达

    float a=2.0f;double a=2.0;    double b=2;    int c=2; long d=2;  long d=2L;
    long f=2;    float y=2;
    long h=2l;

4正确的创造数组

   float f[][]=new float[6][6];

   float []f[]=new float[6][6];

   float [][]f=new float[6][6];后面两个不能为空。

5

 int m[]={0,1,2,3,4,5,6};属性
  String n="asiaking";方法
  System.out.println(m.length+"to"+n.length());7to8

6

 boolean m=true;
  if (m=false) (m==false也对)
 System.out.println("False");
  else  
  System.out.println("true");

结果为true,if到else中间这段不执行。

7

outer:for (int i = 0; i < 3; i++) 
inner:for (int j = 0; j < 2; j++) {
if (j==1) continue outer;
System.out.println(j++ +"to"+ ++i);


}结果0to1
0to3;

8

     switch(m){
     case 0:System.out.println("0");
     case 1:System.out.println("1");
     case 2:System.out.println("condition2");break;
     case 3:System.out.println("condition3");break;
     default:System.out.println("other condintion");
     }注意break,m=0输出0,1,condition2;

m=1输出,1,condition2;

m=2输出condition2;

9

public class test{
private float f=1.0f;
int m=12;
static int n=1;
public static void main(String args[]) {  
     test t=new test();
     System.out.println(t.f);
    // System.out.println(this.n);//错
    // System.out.println(test.m);//错
     System.out.println(test.n);
     
}  
  }
10

public class Example{
Double d1=new Double(1.0);
Double d2=new Double(1.0);
public static void main(String args[]) {  


Double d1=new Double(1.0);
Double d2=new Double(1.0);
Float f=new Float(1.0F);
System.out.println(d1==d2);
System.out.println(d1.equals(d2));
System.out.println(f.equals(d1)); 
}  
  }

false
true
false

11





Java多线程是指在一个Java程序中同时执行多个线程,每个线程都是独立的执行流。Java中创建线程的方式有三种:继承Thread类、实现Runnable接口和实现Callable接口。每种方式都有其优缺点。 1. 继承Thread类创建线程类: ```java class MyThread extends Thread { public void run() { // 线程执行的代码 } } // 创建线程对象并启动线程 MyThread thread = new MyThread(); thread.start(); ``` 优点:简单易用,可以直接重写Thread类的run()方法。 缺点:由于Java不支持多继承,继承了Thread类就无法再继承其他类。 2. 实现Runnable接口创建线程类: ```java class MyRunnable implements Runnable { public void run() { // 线程执行的代码 } } // 创建线程对象并启动线程 Thread thread = new Thread(new MyRunnable()); thread.start(); ``` 优点:避免了单继承的限制,可以继续继承其他类或实现其他接口。 缺点:需要额外创建Thread对象,并将Runnable对象作为参数传递给Thread对象。 3. 实现Callable接口创建线程类: ```java class MyCallable implements Callable<Integer> { public Integer call() throws Exception { // 线程执行的代码 return 0; } } // 创建线程池对象 ExecutorService executor = Executors.newFixedThreadPool(1); // 提交Callable任务并获取Future对象 Future<Integer> future = executor.submit(new MyCallable()); // 获取线程执行结果 int result = future.get(); ``` 优点:可以获取线程执行的结果,并且可以抛出异常。 缺点:相对于前两种方式,使用Callable需要更多的代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值