【2015.5.21 Core Java Volume 1】教程文章相关的互联网学习教程文章

【JAVA SE基础篇】20.类的定义,对象和类的关系,以及类的写法和调用【图】

1.类是什么? 比如我们想认知汽车这个东西,想知道什么是汽车,我们观察了各种各样的汽车后,总结出来汽车都是四个轱辘一个壳子,而总结的过程是我们抽象的过程。 通过抽象发现,车有以下特点: 1.带四个轱辘 2.带方向盘 3.有座椅 4.有个壳子 通过各种各样的汽车,我们抽象出来几个汽车的特征,我们就可以归纳出一个汽车类,通过这一过程,类就是对象的抽象 抽象就可以理解为,抽出像的部分,抽出类似的部分,归纳共同点 2.类和对...

Java.20

import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set;public class ss {public static void main(String[] args) {Map<String,String> map=new HashMap();map.put("亚亚","Q妹");map.put("菲菲","Q妹");map.put("欧欧","Q仔");map.put("美美","Q妹");Set<String> keyset = map.keySet();Iterator<String> iter = keyset.iterator();while (iter.hasNext()){String key = iter.next(...

Java基础50道经典练习题(20)——求前20项之和

【程序 20 求前 20 项之和】 题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前 20 项之和。 ? 程序分析:请抓住分子与分母的变化规律。 ? 源码:package com.homework.test;/* 【程序 20 求前 20 项之和】 题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前 20 项之和。 程序分析:请抓住分子与分母的变化规律。*/ public class Test20 {public static void main(String [] args){...

[20-05-26][Thinking in Java 45]Java String 3 - Replace【代码】

1 package test_21_3;2 3 import java.util.regex.Matcher;4 import java.util.regex.Pattern;5 6 public class ReplaceString {7 8 public static void main(String[] args) {9 10 String str = "Twas brillig, and the slithy toves\n" + 11 "Did gyre and gimble in the wabe.\n" + 12 "All mimsy were the borogoves,\n" + 13 "Beware the Jabberw...

[20-05-26][Thinking in Java 44]Java String 2 - Regular Exception 2【代码】

1 package test_21_2;2 3 import java.util.HashSet;4 import java.util.Set;5 import java.util.regex.Matcher;6 import java.util.regex.Pattern;7 8 public class RegularTest {9 10 public static void main(String[] args) { 11 12 String str = "Twas brillig, and the slithy toves\n" + 13 "Did gyre and gimble in the wabe.\n" + 14 "All mimsy were ...

[20-05-24][Thinking in Java 42]Java Container 14 - Summary of Collection【图】

黄底表示接口 白底表示普通类 红框表示常用容器 三角箭头表示某个类可以生成箭头所指向类的对象 菱形箭头表示一个特定的类实现了一个接口 Utilities表示实用工具

[20-05-17][Thinking in Java 22]Java Inner Class 6 - Anonymous Inner Class 1【代码】

1 package test_15_1; 2 3 public interface Contents { 4 5 int value(); 6 } 1 package test_15_1;2 3 public class Wrapping {4 5 private int i;6 7 public Wrapping(int x) {8 i = x;9 } 10 11 public int value() { 12 return i; 13 } 14 } 1 package test_15_1;2 3 public class Outer {4 5 public Contents contents() {6 // 创建一个继承自Contents的匿名类的对...

[20-05-15][Thinking in Java 17]Java Inner Class 1 - Inner Class 2【代码】

1 package test_13_2;2 3 public class Outer {4 5 private String str;6 7 public Outer() {8 9 } 10 11 public Outer(String str) { 12 13 this.str = str; 14 } 15 16 class Inner { 17 18 // 内部类不止是一种名字隐藏和组织代码的模式 19 // 当生成一个内部类的对象时,此对象与制造它的外围对象(enclosing object)之间就有了一种联系 20 // 所以它能访问其外...

一脚踩进java之基础篇20——面向对象 (匿名对象、内部类)【代码】

一、匿名对象 1.1 匿名对象是指创建对象时,只有创建对象的语句,却没有把对象地址值赋值给某个变量。 如:已经存在的类:public class Person{public void eat(){System.out.println();} }创建一个普通对象Person p = new Person();创建一个匿名对象new Person();1.2 匿名对象的特点1)创建匿名对象直接使用,没有变量名。new Person().eat() //eat方法被一个没有名字的Person对象调用了。  2)匿名对象在没有指定其引用变量时...

[20-05-04][Thinking in Java 6]Java Inheritance 4 - Upcasting【代码】

1 package test_1_4;2 3 public class Amphibian {4 5 public Amphibian(int i) {6 7 System.out.println("this is Amphibian");8 }9 10 public void print(Amphibian i) { 11 12 System.out.println("print Amphibian"); 13 show(); 14 } 15 16 public void show() { 17 18 System.out.println("show"); 19 } 20 21 } 1 pack...

[20-05-02][Self-test 32]Java GuessNum【代码】

1 package test_7_2; 2 3 public class Number { 4 5 public final int value = 100; 6 7 } 1 package test_7_2;2 3 import java.util.Scanner;4 5 public class GuessNum {6 7 /*8 * 猜数字游戏:一个类A有一个成员变量v,初值100。9 * 定义一个类对A类的成员变量v进行猜测。如果大了则提示大了小了则提示小了。等于则提示猜测成功 10 */ 11 12 public static void main(String[] args) ...

[20-05-01][Self-test 30]Java MyArray【代码】

1 package test_6_4;2 3 public class MyArray {4 5 /**6 * 封装一个动态数组类,可以根据用户传递的数据,动态的对数组的长度进行扩展;7 * 方法有:8 * 扩展数组9 * 追加一个值10 * 根据索引,获得元素的值11 * 根据索引,删除一个值12 * 根据索引,修改一个值13 * 在指定位置插入一个值14 * 获得动态数组中元素的个数15 */16 17 public int[] array = new int[0...

[20-05-01][Self-test 27]Java BankAccount【代码】

1 package test_6_1;2 3 import java.util.Date;4 5 public class BankAccount {6 7 /**8 * 设计一个BankAccount类,实现银行某账号的资金往来账目管理,包括建账号、存入、取出等。9 * BankAccount类包括,账号(BankAccountId)、开户日期Date(日期),Rest(余额)。 10 * 另有一个构造函数和三个成员函数BankIn()(处理存入账),BankOut()处理取出账和一个负责生成账号的自动增长的函数。 11 */ 12 1...

[20-04-29][Self-test 23]Java CountsOfUnevenNum【代码】

1 package test_4_2;2 3 public class CountsOfUnevenNum {4 5 public static void main(String[] args) {6 7 /** 求0,1,2,3,4,5,6,7所能组成的8位奇数个数。 */8 9 int[] numArray = {0, 1, 2, 3, 4, 5, 6, 7}; 10 11 int unevenNum = countUneven(numArray); 12 int zero = countZero(numArray); 13 int midNum = numArray.length - zero - 1; 14 ...

[20-04-29][Self-test 21]Java Excursion【代码】

1 package test_3_5;2 3 import java.util.Scanner;4 5 public class Excursion {6 7 public static void main(String[] args) {8 9 /** 有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数 */ 10 int[] numArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 11 12 System.out.println("请输入要偏移的个数:"); 13 Scanner sc = new Scanner(System.in); 14 i...