『Java』最简教程

最简单的Java教程,全是代码。不适合零基础的同学。只为提醒记忆而用。

不定时更新……

package demo;

// Must be the first row!

import demo.ClassName;
public class process extends Object {
 public static void main(String[] args) {
  System.out.println("Hello, This is Java!");
  System.out.println("-----------------------------------------------");

  // if sentence

  boolean condition = true;
  if (condition) {
   System.out.println("This is if sentence! The condition is true");
   System.out.println("-----------------------------------------------");
  } else if (condition) {
   System.out.println("This is if sentence! The condition is another true");
   System.out.println("-----------------------------------------------");
  } else {
   System.out.println("This is if sentence! The condition is false");
   System.out.println("-----------------------------------------------");
  }

  // max = (a>b)?a:b

  int a = 2;
  int b = 1;
  int max = (a > b) ? a : b;
  System.out.println("This is max=(a>b)?a:b! Now, max is " + max);
  System.out.println("-----------------------------------------------");

  // switch sentence

  char switch_condition = 'a';
  switch (switch_condition) {
   case 'a':
    System.out.println("This is switch sentence! The case is '" + switch_condition + "'");
    System.out.println("-----------------------------------------------");
    break;
   case 'b':
    break;
   default:
    break;
  }

  // while sentence

  int while_condition = 5;
  while (while_condition > 0) {
   while_condition--;
   if (while_condition != 1) {
    System.out.println("This is the the continue sentence!");
    continue;

    // Go to the next cycle!

   } else {
       
    System.out.println("This is the break sentence!");
    break;
    
    // Jump out of the cycle!

   }
  }
  System.out.println("End of the while sentence! while_condition is " + while_condition + " now.");
  System.out.println("-----------------------------------------------");
  
  // do ... while

  do {
   while_condition++;
  } while (while_condition < 5);

  // While the condition expression is
  // true, go on the cycle!

  System.out.println("This is do...while sentence! while_condition is " + while_condition + " now.");
  System.out.println("-----------------------------------------------");

  // for sentence

  for (int for_condition = 0; for_condition < 5; for_condition++) {
   System.out.println("This is for sentence! for_condition is " + for_condition + " now.");
  }
  System.out.println("-----------------------------------------------");
  try {
   throw new Error("try...catch(error)...");
  } catch (Error ee) {
   System.out.println(ee.getMessage());
  } finally {
   System.out.println("Finally!");
  }
 }
 void array_about() {
  int[] array_int;
  array_int = new int[10];

  // Array must be initialed!

  array_int[0] = 1;
  int array_int_2[];
  array_int_2 = new int[10];
  char[] array_char = {
   'a',
   'b',
   'c'
  };
 }
}
class class_about extends process {
 demo.ClassName cn = new demo.ClassName();
 void array_about() {
  System.out.println("Overwrite the array_about method!");
  super.array_about();

  // process.array_about()

 }
}
abstract class abstract_class_about {

 // Only statement in the abstract class!

 int i;
 abstract void abstract_method();
 void abstract_method_2() {

  // ...

 }
}
interface interface_about {
 final int i = 1;

 // Must be final! Must be initial!

 abstract void interface_abstract_method();

 // Must be abstract!

}

 

转载于:https://my.oschina.net/skyler/blog/706177

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值