对于corejava阶段,无论是新手还是大牛,都需要了解的几个点?
1)面向对象的三大特性,四大原则
封装,继承,多态
各司其职,可复用性,可拓展性,弱耦合性
2)java来源于生活,java中的对象等都可以使用生活中的各种例子来佐证,主要是需要看你平时的生活阅历是否丰富。
3)编程始终需要把握的是:高内聚,低耦合。
4)接口铸就java(后面有讲解)
以上几项是我在学习corejava的时候,总结的几点,用于与大家相互交流思想和心得。
我的博客从这里开始对java,会进行一个阶段性,细致性的论述(阶段:corejava->web->struts2->mybatis->spring->springMvc 以及html/css->js->jquery->ajax->easyui)
1)int [] a = new int[3]{1,2,3}; error!
int []a = new int[]{1,2,3}; true
2)冒泡排序
- public class BubbleSort{
- public static void main(String[] args){
- int [] arr = {5,1,2,3,4};
- BubbleSort(arr);
- printResult(arr);
- }
- //冒泡排序算法
- public static void BubbleSort(int[] arr){
- //控制趟数
- for(int i=0;i<arr.llength-1;i++){
- //控制每趟比较的次数
- for(int j=0;j<arr.length-1-i;j++){
- if(arr[j] > arr[j+1]){
- int temp=arr[j];
- arr[j]=arr[j+1];
- arr[j+1]=temp;
- }
- }
- }
- }
- //输出语句
- public static void printResult(int []arr){
- for(int i=0;i<arr.length;i++){
- System.out.print(arr[i]+" ");
- }
- }
- }
2)选择排序
- public class BubbleSort{
- public static void main(String[] args){
- int [] arr = {6,4,5,3,2,1};
- SelectSort(arr);
- printResult(arr);
- }
- //选择排序算法
- public static void SelectSort(int[] arr){
- //控制趟数
- for(int i=0;i<arr.llength-1;i++){
- //控制每趟比较的次数
- for(int j=0;j<arr.length-1-i;j++){
- if(arr[j] > arr[j+1]){
- int temp=arr[j];
- arr[j]=arr[j+1];
- arr[j+1]=temp;
- }
- }
- }
- }
- //输出语句
- public static void printResult(int []arr){
- for(int i=0;i<arr.length;i++){
- System.out.print(arr[i]+" ");
- }
- }
- }
4)类的简单概述
5)成员方法可以直接使用成员变量和局部变量
6)实参和形参的理解
7)写一个在输入时候的遇到的小错误
8)9*9乘法表
- public class NineToNine{
- public static void main(String[] args){
- NineToNineMethod();
- }
- //9*9
- public static void NineToNineMethod(){
- //控制趟数
- for(int i=1;i<10;i++){
- //控制每趟比较的次数
- for(int j=1;j<=i;j++){
- Sysout.out.print(i+"*"+j+"="i*j+" ");
- }
- System.out.println(" ");
- }
- System.out.println("\t");
- }
- }
首先对递归思想进行一下分析
第一种递归算法
- public class jiecheng{
- public static void main(String [] args){
- int result = TwoMethod(3);
- System.out.println(result);
- }
- //递归求值
- public static int TwoMethod(int number){
- if(number==1){
- return 1;
- }else{
- return number*TwoMethod(number-1);
- }
- }
- }
第二种循环算法
- public class jiecheng{
- public static void main(){
- double result = jiechengMethod(4);
- System.out.println(result);
- }
- //循环求阶乘
- public static double jiechengeMethod(int input){
- double num = 1;
- for(int i=1;i<=input;i++){
- number *=i;
- }
- return num;
- }
- }
12)构造方法(允许重载)
13)数据类型
byte short int long float double char boolean
1B 2B 4B 8B 4B 8B 2B 1B
14)自动类型提升
15)字符创相加问题
16)局部变量
①先赋值,后使用
②作用域从定义位置开始,到代码块结束截止
③重合范围内,不允许两个局部变量命名冲突
17)函数特点
①避免冗余
②可维护性提高
③重用性提高
④灵活性提高
18)局部变量和实例变量(成员变量)
19)编程思想及其重要性
高内聚,低耦合
台式电脑:主机损坏,整个淘汰
笔记本电脑:主机内聚,接口连接,可任意更换配件
20)为什么实例变量不用赋初始值?
21)面向对象思想:
各司其职 弱耦合性 可重用性 可拓展性
22)成员变量不可以先定义后赋值
int age;
age=10; error!
23)基本变量和引用变量的区别?
24)this关键字(当前对象)
25)堆和栈的认识:
以上内容,纯属手工,难免有漏洞之处,希望能和大家互相交流,共同进步!