『Java』最简教程
最简单的Java教程,全是代码。不适合零基础的同学。只为提醒记忆而用。
不定时更新……
最简单的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! }
版权声明:
作者:莫不逢
出处:http://www.cnblogs.com/sitemanager/
Github:https://github.com/congjf
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。