ChaseDream
搜索
12
返回列表 发新帖
楼主: 珍妮王小钰

Java 打怪今天开始了!

[复制链接]
 楼主| 发表于 2019-9-7 06:20:49 | 显示全部楼层
Jû ]   khuen  FJKLC6unhqtwxAop←→ ←→


Java 是静态语言, 每个引用的时候(不能单独存在) 引用的东西要有类型:
firstStudent  = û
Student firstStudent = 要告诉引用的类型√
reference: firstStudent refer 的type 是 student√
= new Student("Tom") :实际refer的object√
eg: Student Tom = new Student('Tom')
tom是引用,实际指的就是object  Student('Tom')


The object-oriented paradigm in java (class 是Java 里你写的逻辑的基本单元)(object-oriented 是Java的编程哲学;)

wJava object 车---- 行为    开车刹车(up down 速度)
               ----- 特点属性  速度

      class:   blueprint
      object: building ---------------new int [2][3]

wStudent firstStudent 变量现在没有实际的意义 需要 =

w Student(type) firstStudent变量名引用右边的student object(variable: reference(引用实际存在的object~) = new Student("Tom");// 实际的Student object
new这句话结束后得到一个实际的student object
new : create an object;


//Student student = new Student();
THere are actually three important operations happened in this statement.
Declaration: associate a variable name with an object type.
Student firstStudent;



class (name){}
firstly行为: setAGE
public int getAge(){
    return age;
}





 楼主| 发表于 2019-9-12 02:40:03 | 显示全部楼层
flag
ArrayFormula:
= fruit ='apple' X
new : crtil shift enter
(=1*(Fruit = 'apple'))


逻辑层面;
Class 8 Hash Table & StringI
(数据结构&算法)
Hash Table
逻辑层面的数据结构
(like stack queue后面可能是array linkedlist 或者queue实现,queue背后也可能是array,linkelist,stack,都是逻辑层面的东西呢)
1. <key, value> pairs, not allow duplicate keys
       fast search, insert/ update, remove
2. principle <key = string/ int/ obj..., value = obj, string,int...>  eg,<string,int>
sollow!  Arraylist<Pair<string, int>>
Hashtable<key = 人的名字, value = 票数≥   O(1)只能从左到右 从key找value
example:
<tom, 1>   <john,2> <jerry, 5>







 楼主| 发表于 2019-9-13 00:29:07 | 显示全部楼层

我的听力训练

面向对象是干什么的。VS:抽象成函数角度建模(面向过程写法没有class 方法单独写代码不知道哪些函数可以去修改它,不方便把概念一样的东西分开)
好处:用户只用focus在 public aveliable接口,设计的好,class user 和class
//API :  Acc 方法的接口;之后发现新的算法可以改,而user可以不用管(实现细节完全没有在interface暴露除出)
一个人和电脑交互(鼠标 屏幕)状态+行为;
面向对象语言上 class;


public class ClassExample {
        public void type(char[]array) {..}
        public void display(..) {..}
       
//描述的是我们能进行的行为,why放在class 对这个概念的一系列状态(特征状态进行交互)从原来一个值转化成另一个值;
}

实际obj
1.
Car(车type=class,这个类型支持什么类型) car = new Car() 右边是实际的carobj;它会去调用Car类型特殊的方法constructor2.
new ="I  want to create a new Car object that follows the Car class definition 左边的小car 是名字"‘


1Car car = new Car()构建一个实际的对象Car()调用 constructor构造方法(1首先java在内存单元来开空间allocate memory(给的内存还没初始化,来装实际的Car obj)
2.在这个内存上调用constructor 会在我们刚刚内存相对初始化。
public Student(String name) {//Constructor  在还没分配的初始化上面,去做相应的初始化  然后就得到意义的初始化值的Car obj
                this.name = name;//name = n; // 用户传进来的name来初始化,内部叫name的状态属性

ex  Student stu = new Stu();

//Class提供一个统一的地方,对现实生活中一个对象而言它涉及到它独有的特征 我们在上面能做的操作以统一的一种方式在代码里面表现出来
//把乱乱代码good structure 反应现实生活中 抽象建模(对象和对象交互)
//一个概念用class来建模;和class它相关的属性值:declare申明时候访问权限ziyou;
public class Car {//private对于一个field(属性or方法)
        private int speed;//speed 属性/禁止除了class本身任何其他人访问,好控制speed的物理含义:只有CAR本身方法Acc,把changelocalized到class内部
        public void Accelerate(int speed//速度值) {this.speed = speed;}
//把speed这个属性值 把它从原来的值根据我们用户的一个输入,换成另一个
    public void Deacc() {//before classCAR for the state we have assumption(写清晰代码逻辑链)
                if(desired_speed < 0) {
                        throw Exception(.);
                }
                this.speed = ;
        }
}//这个转化不是让用户直接操作用户值的(状态:private)而是通过某一个方法 ACC

public class Student{//属性值:placeholder(得到实际object前不预先决定) declare 变量- 赋予初始值        public int age; //class definition;(member)field 得到student integer后再说age究竟说多少        private final String name; // (constant)field        private static String school; //(static)field        privated static final String GREETING = “Hello”;//static constant field                                                public Student(String name) {//Constructor                this.name = name;//name = n;                        }        public int getAge() {//(                return age;        }                              }

 楼主| 发表于 2019-9-14 04:23:54 | 显示全部楼层

我的听力训练

default initalize ...默认初始化class 是封装 想把隐藏的东西隐藏起来,写成private;把和外部用户交互的地方暴露出来;
public class Student{//属性值:placeholder(得到实际object前不预先决定) declare 变量- 赋予初始值
        public int age; //class definition;(member)field 得到student integer后再说age究竟说多少
        private final String name; // (constant)field
        private static String school; //(static)field
        privated static final String GREETING = “Hello”;//static constant field

                        public Student(String name,int age) {//Constructor
                this.name = name;//name = n;// this.name属性里面定义的!
//传进来的参数右边这个是string name int age
                this.age = age; (因为默认不一定是你想要的,所以嘿嘿这里)

        }
        public int getAge() {//(
                return age;
        }

Student stu = new Student("123"); new 做了两件事情 ,1.首先得到Student obj 2.然后再在studentobj去call constructor对它进行初始化;(写这句话的时候constructor就会被call)
stu 是obj :new Student("123");取的名字
其实是initial构造方法和class名字一样  + 构造函数没有返回值;反例:public int getAge()  返回 int;public void setAge(int age){}

public Student(String name, int age){ // Constructor 在这个方法被调用的时候,你已经有了一个obj 上面public class 里Stuent{属性}



this.name = name;
this.age = age;
}
//this 就是stu 代表的东西;
Student stu1 = new Student("123");
Student stu2 = new Student("4556");

foo(){
    this.property = ...;
}
a.foo(); 取决于现在run的方法在哪个对象上? 现在是b
b.foo(); 在b上面运行foo 这里this就指b


class A只有同一package能看见;当把一个class 写进另一个,就可以写成private; public class MergeSort 「 private class A
package lll;
public class TEST{}


class TM {
     public T















 楼主| 发表于 2019-9-15 00:39:53 | 显示全部楼层
用户程序 内核 底层

访问操作系统/bash是其中一种访问内核的方式/工具

shell是lINX命令:让内核干一些事情(脚本是命令的集合)来执行~~~


cd ~ 根目录,回到 home/ubuntu  
//打指令传到内核 ls文件,bash实现过程
//
//操作系统LINX: 底层根目录:ls就像遍历树来找文件;
ls 当前路径下面所有的文件;
ls -la 会把文件下面有啥信息全部告诉你 :bin 什么时候创建的  4096 文件的大小等 包括隐藏文件和文件所有信息;
pwd 查看当前位置在什么地方;
/(现在的路径)
cd bin 然后pwd 告诉你/bin 你现在的位置在什么路径下面

dir 完整的路径
cd/etc
cd 。。相对路径回到上面级(。是自己)
pwd = present working directory

less 来文件的内容,vim来修改;

mkdir make directory: 右键创建新文件夹!节点父节点; mkdir demo
ls
demo
touch 创建单独的文件; 叶子节点;(比VIM 创建保存方便一点)






 楼主| 发表于 2019-9-15 09:07:24 | 显示全部楼层
-f 时时显示内容;
history make assumption ~~
怎么获得推荐?之前不知道的可能引起喜欢的)
YouTube 登陆界面:

用postman测试;
itemHistory 's servlet

when data is not very big. make a assumption: assume user like;(history)

+search and itemfavorite serlvet;




计算机里面 用score 表示喜不喜欢~


How to address this question
1. Content-based Recommendation本身特点(大小颜色玩法相似 是本身的特点!)
Key point: You will like people or things of similar characteristics.
Given item profiles (category, price, etc.) of your favorite, recommend items that are similar to what you liked before. This is what we’ll use in our application.
  • Content-based method是不同于Item-based method的推荐系统设计思想.
  • 它是通过物品”本身的特点”, 而不是“购买这个物品的用户的信息”, 来计算物品之间的相似度.
  • 在系统没有足够数据的时候, 一般先使用content-based method.

2. Item-based method 喜欢它的用户决定它们相似度而不是它们本身特点决定相似度!
Filter based on the similarity of Items.
Item A is liked by User A, User B, User C
Item B is liked by User B.
Item C is liked by User A, User B
=> Item A and Item C are alike     (overlap交集 比较多;有喜欢它们的用户决定的而不是它们本身决定)
Item C is liked by users who like Item A, so recommend it to user C (another user who likes Item A).


面试  不会用ML Dl  这些model的区别;但是overlap交集 比较多;有喜欢它们的用户决定的而不是它们本身决定!
















 楼主| 发表于 2019-9-16 05:08:37 | 显示全部楼层
一个方法  自己调用自己;
数学问题 可能的bebug
1.sign
2.type
2. precision
4. c/0
5. 0^0...
6.overflow
7.   3/2 = 1  3.0 /2.0 = 1.5 (double)3/2

2. Recursion 与 1D or 2D Array 的结合
    1. 1D array:  二分法比较常见
     1.1  MergeSort
     1.2  QuickSort

2. 2D array:
    2.1  逐层(row by row ) 递归: 8 Queen  ——> n queen
八个皇后不会互相攻击;
//DFS 画出 recursion tree

第一层有8node 8层
                                                               root
                   /                       |                    |                  |                |               |                \

L0     Q0 is out on (o                    

L1

L2

。。。

L7


time = O(n!) 是判断在一行列, 所以要eterate  Time = O(n! *n)???/


index  是行, 「{}  列

current_row == N  
???
不是 背代码; 皇后是新的 放进去  没有swap 没有换 要变通,明白物理意义;

障碍物;
if there are obstacles on the board

                                                      root

L0    Q0(0,0)





Q2.2 how to print 2D array in spiral order (N x N)]
打印最外面一圈(offset +1 :0,0)(size:5) 然后里面 剥洋葱;(1,1)(size:3)(2,2) recursion -2


3.

返回value

123 步曲  1 问你左孩子和右孩子要int value, 高度 of left subtree and right
2 拿到返回值后,在当前层需要什么 max(left,right)+1
~~
LCA
lowest Common Ancestor(LCA)

a,b  如果是隶属关系,就直接返回a 上去;
case 1 . a and b 直接隶属关系
左右都是null 返回null ; 如果其中一个不是 null ,返回不为空的那个;


if both left and right are not null: return myself(c)

return left == null? right:left  ( else  or



































 楼主| 发表于 2019-9-18 05:11:16 | 显示全部楼层
static method不需要 object来调用;object free;每个obj都可以改一下它-,- global scope
public class MergeSort {//class
        public int[] mergeSort(int[]array) {// class里面都public mergesort方法,
//给一个数组,然后排好序后 把reference返回给你~
                //check  null array first
                if(array == null) {
                        return array;
                }
                //allocate helper array to help merge step.
                //so that we guarantee no more than O(n)in this case.
                int[]helper = new int[array.length];
                mergeSort(array,helper,0,array.length - 1);
                return array;       
        }
}

private void mergeSort(int[]array, int[]helper, int left,int right) {
        if (left >= right) {
                return;
        }
        int mid = left + (right - left)/2;
        mergeSort(array,helper,left, mid);
        mergeSort(array,helper,mid + 1, right);
        merge(array,helper,left,mid,right);       
}

private void merge(int[] array,int[]helper,int left,int mid,int right) {
        //copy the content to helper array and we will merge from the helper array
        for (int i = left; i <= right; i++) {
                helper = array;
        }
        int leftIndex = left;
        int rightIndex = mid + 1;
        while(leftIndex <= mid && rightIndex <= right) {
                if(helper[leftIndex] <= helper[rightIndex]) {
                        array[left++] = helper[leftIndex++];
                } else {
                        array[left++] = helper [rightIndex++];
                }
        }
       
        //if we still have some elements at left side,we need to copy them
        while(leftIndex <= mid) {
                array[left++] = helper [leftInde++];
        }
       
        // if there are some elements at right side, we do not to copy them because they are already in the position/
public static void main (String[] args){
        int[]array = {3,5,1,6,2};
        MergeSort sorter = new MergeSort();//new 一个对象出来;
        array = sorter.mergeSort(array);//然后我门在对象sorter上边来call方法;
       
       

您需要登录后才可以回帖 登录 | 立即注册

Mark一下! 看一下! 顶楼主! 感谢分享! 快速回复:

手机版|ChaseDream|GMT+8, 2024-3-29 01:56
京公网安备11010202008513号 京ICP证101109号 京ICP备12012021号

ChaseDream 论坛

© 2003-2023 ChaseDream.com. All Rights Reserved.

返回顶部