JavaBlog1
前言
在这里总结一下这三次作业题量和难度。对我来说,第一阶段的三次作业集相对来说都比较轻松,特别是第一次题目集,虽然题量很大,但基本上都是让我们掌握一些基本的print、if else语句和循环,大部分都和C语言差不多;对于第二次题目集,题量也挺大的,有九道题,也增加了一点点难度,题目涉及了if else语句的使用与嵌套,switch结构,引入了字符串处理String.用for循环对字符串的遍历处理,考察了部分算法问题,大大增加了计算难度,也逐渐使用到了类设计和一些封装知识。对于作业三一共有三道编程题,题量虽然不多,但是这三道题目主要考察了我们对于类的设计以及对于字符串的处理,在作业三中,第一题的定义账户类,和第二题的日期类,让我对类的概念有了很好的认识。
知识点:
第一次作业:对于应用备注和快捷编码更熟练了,对于循环if-else,equals方法和char方法更加游刃有余;
第二次作业:学到和运用了split分割字符串,和创建对象;
第三次作业:需要对类有一定理解才能上手,类里面的属性,构造方法,类方法调用这些都让我对Java面向对象有了新的理解,是和c语言两种不同的编程思维,初次接触时我不自主地将Java中类与结构体联想在一起,感觉有很多相似的地方。
设计与分析
在这里我只给出部分比较有意思和有难度的题目做出讲解,以下是部分题目:
第一次作业:
7-1 九九乘法表(双重循环)
打印九九乘法表。
输入格式:一个整数n。
输出格式:乘法表的前n行。
思路:这道题唯一的难度就是如何实现双重循环,就是通过: for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) 实现
代码如下:
1 import java.util.Scanner; 2 3 public class Main { 4 public static void main(String[] args) { 5 Scanner scanner = new Scanner(System.in); 6 int n = scanner.nextInt(); 7 8 for (int i = 1; i <= n; i++) { 9 for (int j = 1; j <= i; j++) { 10 System.out.print(j + " * " + i + " = " + i * j + "\t"); 11 } 12 System.out.println(); 13 } 14 } 15 }
类图过于简单就不给出了
7-2 去掉重复的字符
输入一个字符串,输出将其中重复出现的字符去掉后的字符串
输入格式:一行字符串
输出格式:去掉重复字符后的字符串
思路:我们首先使用Scanner类来读取用户输入的字符串。然后,我们定义了一个removeDuplicates方法,它接收一个字符串作为输入并返回去重后的字符串。
代码如下:
import java.util.LinkedHashSet; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); String result = removeDuplicates(input); System.out.println(result); } public static String removeDuplicates(String str) { LinkedHashSet<Character> set = new LinkedHashSet<>(); for (char c : str.toCharArray()) { set.add(c); } StringBuilder sb = new StringBuilder(); for (char c : set) { sb.append(c); } return sb.toString(); } }
7-3 有重复的数据
输入格式:你的程序首先会读到一个正整数n,n∈[1,100000],然后是n个整数。
输出格式:如果这些整数中存在重复的,就输出:YES 否则,就输出:NO
思路:先读取整数的个数n,并创建一个int数组来存储输入的数字,然后,使用双重for循环来逐个比较数组中的数字。对于每个数字nums[i],将其与后面的数字nums[j]进行比较,如果找到相等的数字,则返回true表示存在重复。最后,如果循环结束仍然没有找到重复的数字,则返回false。
代码如下:
1 import java.util.Scanner; 2 3 public class Main{ 4 public static void main(String[] args) { 5 Scanner scanner = new Scanner(System.in); 6 int n = scanner.nextInt(); 7 8 int[] nums = new int[n]; 9 for (int i = 0; i < n; i++) { 10 nums[i] = scanner.nextInt(); 11 } 12 13 String result = hasDuplicates(nums) ? "YES" : "NO"; 14 System.out.println(result); 15 } 16 17 public static boolean hasDuplicates(int[] nums) { 18 for (int i = 0; i < nums.length; i++) { 19 for (int j = i + 1; j < nums.length; j++) { 20 if (nums[i] == nums[j]) { 21 return true; 22 } 23 } 24 } 25 return false; 26 } 27 }
第二次作业:
7-1 长度质量计量单位换算
长度、质量的计量有多重不同的计算体系,有标准的国际单位制:千克与米,也有各个国家自己的计量方法如:磅、英寸;1磅等于0.45359237千克,1英寸等于0.0254米,请编写程序实现国际单位制与英制之间的换算。
输入格式:两个浮点数,以空格分隔,第一个是质量(以千克为单位)、第二个是长度(以米为单位)。例如:0.45359237 0.0254。
输出格式:两个浮点数,以空格分隔,第一个是质量(以磅为单位)、第二个是长度(以英寸为单位)。例如:1.0 1.0。
思路:直接将质量(以千克为单位)乘以2.20462来进行从千克到磅的换算。同样地,将长度(以米为单位)除以0.0254来进行从米到英寸的换算。最后,我们将转换后的质量和长度打印出来。
代码如下:
1 import java.util.Scanner; 2 3 public class Main{ 4 public static void main(String[] args) { 5 Scanner scanner = new Scanner(System.in); 6 double massKg = scanner.nextDouble(); 7 double lengthM = scanner.nextDouble(); 8 9 double massLb = massKg * 2.20462; 10 double lengthInch = lengthM / 0.0254; 11 12 System.out.println(massLb); 13 System.out.println(lengthInch); 14 } 15 }
7-2 判断三角形类型
输入三角形三条边,判断该三角形为什么类型的三角形。
输入格式:
在一行中输入三角形的三条边的值(实型数),可以用一个或多个空格或回车分隔,其中三条边的取值范围均为[1,200]。
输出格式:
(1)如果输入数据非法,则输出“Wrong Format”; (2)如果输入数据合法,但三条边不能构成三角形,则输出“Not a triangle”; (3)如果输入数据合法且能够成等边三角形,则输出“Equilateral triangle”; (3)如果输入数据合法且能够成等腰直角三角形,则输出“Isosceles right-angled triangle”; (5)如果输入数据合法且能够成等腰三角形,则输出“Isosceles triangle”; (6)如果输入数据合法且能够成直角三角形,则输出“Right-angled triangle”; (7)如果输入数据合法且能够成一般三角形,则输出“General triangle”。
输入样例1:
在这里给出一组输入。例如:
50 50 50.0
输出样例1:
在这里给出相应的输出。例如:
Equilateral triangle
输入样例2:
在这里给出一组输入。例如:
60.2 60.2 80.56
输出样例2:
在这里给出相应的输出。例如:
Isosceles triangle
输入样例3:
在这里给出一组输入。例如:
0.5 20.5 80
输出样例3:
在这里给出相应的输出。例如:
Wrong Format
思路:这题挺有意思的,有很多易错点,主要还是设定辨别三角形的条件。
代码如下:
1 import java.text.DecimalFormat; 2 import java.util.Scanner; 3 4 public class Main{ 5 public static void main(String[] args) { 6 Scanner scanner = new Scanner(System.in); 7 scanner.useDelimiter("\\s+"); 8 9 System.out.print("请输入三角形的三条边:"); 10 double side1 = scanner.nextDouble(); 11 double side2 = scanner.nextDouble(); 12 double side3 = scanner.nextDouble(); 13 14 String triangleType = getTriangleType(side1, side2, side3); 15 System.out.println(triangleType); 16 } 17 18 public static String getTriangleType(double side1, double side2, double side3) { 19 // 判断输入数据是否合法 20 if (side1 <= 0 || side2 <= 0 || side3 <= 0) { 21 return "Wrong Format"; 22 } 23 24 // 判断是否能构成三角形 25 if (side1 + side2 <= side3 || side1 + side3 <= side2 || side2 + side3 <= side1) { 26 return "Not a triangle"; 27 } 28 29 // 判断三角形的类型 30 DecimalFormat decimalFormat = new DecimalFormat("#.##"); 31 if (decimalFormat.format(side1).equals(decimalFormat.format(side2)) 32 && decimalFormat.format(side1).equals(decimalFormat.format(side3))) { 33 return "Equilateral triangle"; 34 } else if (decimalFormat.format(side1).equals(decimalFormat.format(side2)) 35 || decimalFormat.format(side1).equals(decimalFormat.format(side3)) 36 || decimalFormat.format(side2).equals(decimalFormat.format(side3))) { 37 if (Math.pow(side1, 2) + Math.pow(side2, 2) == Math.pow(side3, 2) 38 || Math.pow(side1, 2) + Math.pow(side3, 2) == Math.pow(side2, 2) 39 || Math.pow(side2, 2) + Math.pow(side3, 2) == Math.pow(side1, 2)) { 40 return "Isosceles right-angled triangle"; 41 } else { 42 return "Isosceles triangle"; 43 } 44 } else if (Math.pow(side1, 2) + Math.pow(side2, 2) == Math.pow(side3, 2) 45 || Math.pow(side1, 2) + Math.pow(side3, 2) == Math.pow(side2, 2) 46 || Math.pow(side2, 2) + Math.pow(side3, 2) == Math.pow(side1, 2)) { 47 return "Right-angled triangle"; 48 } else { 49 return "General triangle"; 50 } 51 } 52 }
7-3 求下一天
输入年月日的值(均为整型数),输出该日期的下一天。 其中:年份的合法取值范围为[1820,2020] ,月份合法取值范围为[1,12] ,日期合法取值范围为[1,31] 。
要求:Main类中必须含有如下方法,签名如下:
public static void main(String[] args);//主方法
public static boolean isLeapYear(int year) ;//判断year是否为闰年,返回boolean类型
public static boolean checkInputValidity(int year,int month,int day);//判断输入日期是否合法,返回布尔值
public static void nextDate(int year,int month,int day) ; //求输入日期的下一天
思路:根据输入的年、月、日,调用checkInputValidity方法检查输入的日期是否合法。若日期不合法,则输出错误提示信息。对于合法的日期,根据日期的大小进行递增操作,
考虑到平年和闰年的2月份以及各月份的天数。最后,将计算结果以"年-月-日"的格式打印出来。
代码如下:
1 import java.util.Scanner; 2 3 public class Main{ 4 public static void main(String[] args) { 5 Scanner scanner = new Scanner(System.in); 6 7 int year = scanner.nextInt(); 8 int month = scanner.nextInt(); 9 int day = scanner.nextInt(); 10 11 nextDate(year, month, day); 12 } 13 14 public static boolean isLeapYear(int year) { 15 return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); 16 } 17 18 public static boolean checkInputValidity(int year, int month, int day) { 19 if (year < 1820 || year > 2020 || month < 1 || month > 12 || day < 1 || day > 31) { 20 return false; 21 } 22 23 if (month == 2) { 24 if (isLeapYear(year)) { 25 return day <= 29; 26 } else { 27 return day <= 28; 28 } 29 } 30 31 if (month == 4 || month == 6 || month == 9 || month == 11) { 32 return day <= 30; 33 } 34 35 return true; 36 } 37 38 public static void nextDate(int year, int month, int day) { 39 if (!checkInputValidity(year, month, day)) { 40 System.out.println("Date Format is Wrong"); 41 return; 42 } 43 44 if (day < 28) { 45 day++; 46 } else if (day == 28) { 47 if (month == 2 && isLeapYear(year)) { 48 day++; 49 } else { 50 day = 1; 51 month++; 52 } 53 } else if (day == 29) { 54 if (month == 2 && isLeapYear(year)) { 55 day = 1; 56 month++; 57 } else { 58 day++; 59 } 60 } else { 61 if (day == 30) { 62 if (month == 4 || month == 6 || month == 9 || month == 11) { 63 day = 1; 64 month++; 65 } else { 66 day++; 67 } 68 } else { 69 if (month == 12) { 70 day = 1; 71 month = 1; 72 year++; 73 } else { 74 day = 1; 75 month++; 76 } 77 } 78 } 79 } 80 81 System.out.println("Next date is:" + year + "-" + month + "-" + day); 82 } 83 }
第三次作业:
7-1 创建圆形类
编写一个圆形类Circle,一个私有实型属性半径,要求写出带参数构造方法、无参构造方法、属性的getter、setter方法以及求面积、输出数据等方法,具体格式见输入、输出样例。
思路:在main方法中,先创建了一个Scanner对象scanner,然后通过nextDouble()方法获取用户输入的半径值。接着,使用用户输入的半径值创建一个Circle对象circle,并调用display()方法输出圆的半径和面积
代码如下:
import java.text.DecimalFormat; import java.util.Scanner; class Circle { private double radius; public Circle(double radius) { this.radius = radius; } public Circle() { this.radius = 0.0; } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } public double getArea() { return Math.PI * radius * radius; } public void display() { DecimalFormat decimalFormat = new DecimalFormat("#.##"); System.out.println(decimalFormat.format(radius)); System.out.println(decimalFormat.format(getArea())); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double radius = scanner.nextDouble(); Circle circle = new Circle(radius); circle.display(); circle.setRadius(radius); System.out.println(circle.getRadius()); System.out.println(circle.getArea()); } }
7-2 创建账户类
描述:
设计一个名称为Account的类,具体包括:
id:账号,整型,默认值为0;
balance:余额,实型,默认值为0;
annualInterestRate:当前利率,实型,默认值为0,假设所有帐户均有相同的利率;
dateCreated:账户开户时间,LocalDate类型,默认为2020年7月31日;
一个能创建默认账户的无参构造方法;
一个能创建带特定id和初始余额的账户的构造方法;
id、balance、annualInterstRate的getter及setter方法;
dateCreated的getter方法;
一个名为getMonthlyInterestRate()的方法返回月利率(月利率计算公式:余额*(年利率/1200));
一个名为withDraw的方法从账户提取特定数额,当提取数额大于余额或为负数系统返回WithDraw Amount Wrong提示;
一个名为deposit的方法向账户存储特定数额,当存储数额大于20000元或为负数系统返回Deposit Amount Wrong提示。
编写一个测试程序:
创建一个账户,其账户id、余额及利率分别有键盘输入,账户开户时间取系统当前时间;
输入取钱金额,系统进行取钱操作,如果取钱金额有误,则输出提示信息后系统继续运行;
输入存钱金额,系统进行存钱操作,如果存钱金额有误,则输出提示信息后系统继续运行;
系统输出,以如下格式分别输出该账户余额、月利息以及开户日期(输出实型数均保留两位小数)
输入格式:
在一行内分别输入账户id、初始余额、当前利率、提取金额、存储金额,数据间采用一个或多个空格分隔。
输出格式:
共分三行输出,分别为约、计算的月利息以及开户日期,格式如下:
The Account'balance:余额
The Monthly interest:月利息
The Account'dateCreated:年-月-日
输入样例1:
1122 20000 0.045 800 600
输出样例1:
The Account’balance:19800.00
The Monthly interest:0.74
The Account’dateCreated:2020-07-31
输入样例2:
1122 20000 0.045 8000 30000
输出样例2:
Deposit Amount Wrong
The Account’balance:12000.00
The Monthly interest:0.45
The Account’dateCreated:2020-07-31
思路:做类设计,计算利率,比较简单。
代码如下:
1 import java.time.LocalDate; 2 import java.util.Scanner; 3 4 public class Main { 5 public static void main(String[] args){ 6 Scanner in=new Scanner(System.in); 7 Account a=new Account(); 8 //输入 9 a.id=in.nextInt();//账户id 10 a.balance=in.nextDouble();//初始余额 11 a.annuallnterestRate=in.nextDouble();//当前利率 12 double withdraw=in.nextDouble();//提取金额 13 double deposit=in.nextDouble();//存储金额 14 double newbalance;//新余额 15 16 //存、取金额有误 17 if(a.withDraw(withdraw)==false||a.deposit(deposit)==false) 18 { 19 newbalance=a.balance; 20 //提取金额 21 if(a.withDraw(withdraw)==true) 22 newbalance=newbalance-withdraw; 23 else 24 System.out.println("WithDraw Amount Wrong"); 25 //存储金额 26 if(a.deposit(deposit)==true) 27 newbalance=newbalance+deposit; 28 else 29 System.out.println("Deposit Amount Wrong"); 30 //输出 31 System.out.printf("The Account'balance:"+"%.2f\n",newbalance); 32 System.out.printf("The Monthly interest:"+"%.2f\n",(a.getMonthlylnteresRate(newbalance,a.annuallnterestRate))); 33 a.getDateCreated(); 34 } 35 //存、取金额无误 36 if(a.withDraw(withdraw)==true&&a.deposit(deposit)==true) 37 { 38 //输出 39 newbalance=a.balance-withdraw+deposit; 40 System.out.printf("The Account'balance:"+"%.2f\n",newbalance); 41 System.out.printf("The Monthly interest:"+"%.2f\n",(a.getMonthlylnteresRate(newbalance,a.annuallnterestRate))); 42 a.getDateCreated(); 43 } 44 } 45 } 46 47 class Account{ 48 int id;//账户id 49 double balance;//余额 50 double annuallnterestRate;//初始利率 51 LocalDate dateCreated;//2020 7 31 52 ) 53 public int getId(int id){ 54 return id; 55 } 56 public void setId(){ 57 this.id=id; 58 } 59 60 public double getBalance(double balance){ 61 return balance; 62 } 63 public void setBalance(){ 64 this.balance=balance; 65 } 66 67 public double getAnnuallnterestRate(double annuallnterestRate){ 68 return annuallnterestRate; 69 } 70 public void setAnnuallnterestRate(){ 71 this.annuallnterestRate=annuallnterestRate; 72 } 73 //开户日期 74 public void getDateCreated(){ 75 System.out.println("The Account'dateCreated:2020-07-31"); 76 } 77 //月利率 78 public double getMonthlylnteresRate(double balance,double annuallnterestRate){ 79 double monthlyInterestRate; 80 return monthlyInterestRate=balance*(annuallnterestRate/1200.0); 81 } 82 //提取金额 83 public boolean withDraw(double withdraw){ 84 boolean result=true; 85 if(withdraw>balance||withdraw<0) 86 result=false; 87 return result; 88 } 89 //存储金额 90 public boolean deposit(double deposit){ 91 boolean result=true; 92 if(deposit>20000||deposit<0) 93 result=false; 94 return result; 95 } 96 }
7-3 定义日期类
定义一个类Date,包含三个私有属性年(year)、月(month)、日(day),均为整型数,其中:年份的合法取值范围为[1900,2000] ,月份合法取值范围为[1,12] ,日期合法取值范围为[1,31] 。
思路:Date类新增了一个get nextDay()方法,用于计算下一天的日期。首先,通过nextDay()方法中的逻辑,计算出下一天的日期、月份和年份。在main方法中,创建了Scanner对象scanner,然后通过nextInt()方法分别获取用户输入的年、月、日值。之后,使用用户输入的年、月、日值创建一个Date对象date,调用nextDay()方法计算并输出下一天的日期。
代码如下:
1 import java.util.Scanner; 2 class Date{ 3 private int year; 4 private int month; 5 private int day; 6 7 public Date(int year,int month,int day){ 8 this.year=year; 9 this.month=month; 10 this.day=day; 11 } 12 public Date() { 13 int year,month,day; 14 } 15 public int getYear(){ 16 return year; 17 } 18 public int getMonth() { 19 return month; 20 } 21 public int getDay() { 22 return day; 23 } 24 public void setYear(int year) { 25 this.year = year; 26 } 27 public void setMonth(int month) { 28 this.month = month; 29 } 30 public void setDay(int day) { 31 this.day = day; 32 } 33 public static boolean isLeapYear(int year) { 34 boolean y; 35 y = ((year % 4 == 0 && year % 100 !=0 )||year % 400 == 0); 36 return y; 37 } 38 public static boolean checkInputValidity(int year, int month, int day) { 39 boolean x; 40 int[] a=new int[]{0,31,29,31,30,31,30,31,31,30,31,30,31}; 41 if(!isLeapYear(year)) 42 a[2] = 28; 43 x=(year>=1900&&year<=2000&&month>0&&month<=12&&day<=a[month]&&day>0); 44 return x; 45 } 46 public static void getnextDate(int year,int month,int day) { 47 int[] a=new int[]{0,31,29,31,30,31,30,31,31,30,31,30,31}; 48 if(!isLeapYear(year)) 49 a[2] = 28; 50 if(checkInputValidity(year,month,day)) { 51 if(month==12) { 52 if(day==a[month]) { 53 year = year+1; 54 month=1; 55 day=1; 56 } 57 else{ 58 day++; 59 } 60 } 61 else { 62 if(day==a[month]) { 63 month++; 64 day=1; 65 } 66 else{ 67 day++; 68 69 } 70 } 71 System.out.println("Next day is:"+year+"-"+month+"-"+day); 72 } 73 else System.out.println("Date Format is Wrong"); 74 } 75 } 76 public class Main { 77 public static void main(String[] args) { 78 Scanner input=new Scanner(System.in); 79 Date a=new Date(); 80 a.setYear(input.nextInt()); 81 a.setMonth(input.nextInt()); 82 a.setDay(input.nextInt()); 83 a.getnextDate(a.getYear(), a.getMonth(),a.getDay()); 84 } 85 }
踩坑心得
-
输入合法性检查:在接受用户输入时,一定要进行合法性检查。比如,在Date类中,对年份、月份和日期进行了合法取值范围的检查,这是非常重要的,可以避免后续计算和处理时出现错误。
-
封装和访问控制:正确地使用private修饰符可以确保数据的封装性,并提供public的getter和setter方法来访问私有属性,以控制对属性的访问和赋值。
-
功能单一性原则:在设计类时,推荐遵循单一职责原则,确保每个类只负责单一的功能。例如,Date类只包含与日期相关的属性和方法,而不包含与其他功能无关的代码。
-
使用Scanner类:Scanner类可以方便地获取用户的输入。在使用Scanner时,要确保使用完之后及时关闭。可以考虑使用try-with-resources语句块或手动调用close()方法来关闭Scanner。
-
方法的命名:在命名方法时,使用有意义的名字,能够清晰地表达方法的功能。比如,isValidDate()方法用于判断日期是否合法,nextDay()方法计算下一天的日期。
-
注释和文档:为了提高代码的可读性和可维护性,建议在代码中添加注释,解释代码的用途、实现方法和逻辑思路。此外,在公共接口和重要方法上添加文档注释,可以方便其他开发人员理解和使用代码。
-
异常处理:考虑到代码的健壮性,应该在合适的地方捕获和处理可能发生的异常。尤其是涉及用户输入和文件操作的代码,需要特别注意异常处理。总的来说,良好的编码习惯、合理的分层设计以及合理的数据校验和异常处理是开发过程中避免踩坑的重要因素。不断积累经验和思考问题背后的原因,可以帮助我们更好地进步和提高。
总的来说,良好的编码习惯、合理的分层设计以及合理的数据校验和异常处理是开发过程中避免踩坑的重要因素。不断积累经验和思考问题背后的原因,可以帮助我们更好地进步和提高。
改进建议
使用面向对象的设计原则:遵循面向对象的设计原则,如单一职责原则、开闭原则等,可以提高代码的可维护性和可扩展性。合理划分模块和类,降低类之间的耦合度。考虑边界情况和异常处理:在计算下一天日期时,要考虑边界情况,如闰年、月底和年底,同时需要适当处理这些情况,以避免出现错误或异常。将输入合法性检查代码封装到独立的方法中:将对年、月、日的合法取值范围进行检查的代码封装到一个方法中,例如isValidValue(int value, int minValue, int maxValue),这样可以提高代码的重用性。添加更多的注释:在代码中添加注释来解释代码的用途、实现方法和逻辑思路。尤其是对于复杂的逻辑和算法,详细的注释可以帮助其他开发人员理解代码并进行维护。
总结
通过第一阶段的学习我也学到很多经验,包括:
1. 输入合法性检查:了解了输入合法性检查的重要性,以及如何在代码中进行合法性检查,避免在后续的计算和处理中出现错误。
2. 封装和访问控制:学会使用private修饰符来封装私有属性,并提供公共的getter和setter方法来访问和修改属性值,实现了良好的封装性。
3. Java中的基础类和方法:学会了使用Scanner类来获取用户输入,以及使用System.out.println()方法来输出结果,在实践中掌握了一些基础的Java语法知识。
4. 异常处理:学会了基本的异常处理,如捕获和处理异常,以提高程序的健壮性和可靠性。
需要进一步学习和研究的地方包括:
1. 更多的Java核心知识:深入学习Java编程语言的核心概念,如类、对象、方法、继承、接口、异常处理等,以及更高级的主题,如集合框架、多线程、IO操作等,以扩展和巩固自己的Java编程能力。
2. 面向对象设计原则:学习和理解面向对象设计的原则,如单一职责原则、开闭原则、依赖倒置原则等,以便更好地设计和组织代码,提高代码的可维护性和可扩展性。
3. 测试方法和单元测试:学习如何编写有效的单元测试,并了解测试驱动开发的概念和实践,以保证代码的质量和正确性。
4. 继续探索Java类库和框架:在实践中,逐渐熟悉Java的类库和框架,如日期时间类、正则表达式、文件操作等,以及一些常用的第三方库和框架,在实际开发中能够熟练使用它们。
5. 阅读和理解他人的代码:阅读他人的优秀代码,学习他们的设计思想和编码风格,提高自己的代码阅读和理解能力。
通过不断学习和实践,不仅能够提高编程能力和技术水平,还能够提高解决问题的能力和思维能力,成为一个更好的开发者。

浙公网安备 33010602011771号