[Java in NetBeans] Lesson 06. Custom classes

时间:2022-10-08 23:01:46

这个课程的参考视频和图片来自youtube

主要学到的知识点有:

  • Constructors: A special method called when an object of the class is created
  • property pattern and encapsulation(封装): hide the implementation details from the user, so when the class is been inherited, only the methods, but not the members.
  • this: simply refers to the current class.
  • Also allow us to call other constructor in one constructor
public class Foo
{
private int _x; // if class members, and not public, start with underscore. public Foo()
{
this(1);
} public Foo(int x)
{
_x = x;
}
}
  • Overload: The method with different parameter but same method name. (for example, the constructors. Java will automatic search for the constructors that fits the parameters passed in)

e.g. Foo foo = new Foo(8); will automatic search for the second constructor "public Foo(int x)".

  • Every class should have a constructor. But the body can be empty.
  • Declare variables as private as possible. Can create getter and setter for the variables to control access to private variables.  based on the encapsulation(封装) concept.
  • Initialize all private variables in constructor. (if not, make them final)
  • this disambiguates method parameters from private members, but will name the members with _(unless it is public). Below is an example without "_".
public class Foo
{
private int x; public Foo()
{
this(1);
} public int setX(int x)
{
this.x = x;
}
}
  • Use get/set methods to control access to private variables.

[Java in NetBeans] Lesson 06. Custom classes的更多相关文章

  1. [Java in NetBeans] Lesson 04. Class / Objects

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Class: Blueprint for an object. (e.g. dog is a class) Object: cust ...

  2. [Java in NetBeans] Lesson 09. Switch / If-Else Ladder

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. Nested If-else statement (if-else ladder) /** * 90 and above == ...

  3. [Java in NetBeans] Lesson 07. JavaDoc and Unit Tests

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. organize code into packages Create a package if want to make th ...

  4. [Java in NetBeans] Lesson 05. Method/function

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Define a method:(motivation: write one time, but use it many times ...

  5. [Java in NetBeans] Lesson 00. Getting Set-up for Learning Java

    这个课程的参考视频在youtube. 主要学到的知识点有: set up needs Java SE JDK, NetBeans IDE class name should be the same l ...

  6. [Java in NetBeans] Lesson 17. File Input/Output.

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...

  7. [Java in NetBeans] Lesson 16. Exceptions.

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...

  8. [Java in NetBeans] Lesson 15. Sorting and Searching.

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Build in functions in java.util.Collections Need to implement a co ...

  9. [Java in NetBeans] Lesson 01. Java Programming Basics

    这个课程的参考视频在youtube. 主要学到的知识点有: Create new project, choose Java Application. one .jar file/ package(.j ...

随机推荐

  1. Mysql上手

    使用Mysql,打开 相应的服务.启动-- 打开命令窗口.此处有多种方法,我是在开始菜单(Mysql5.6 Command Line Client)打开的(简单). mysql -h localhos ...

  2. Spark Application的调度算法

    要想明白spark application调度机制,需要回答一下几个问题: 1.谁来调度? 2.为谁调度? 3.调度什么? 3.何时调度? 4.调度算法 前四个问题可以用如下一句话里来回答:每当集群资 ...

  3. 2014 ACM/ICPC Asia Regional Xi'an Online

    03 hdu5009 状态转移方程很好想,dp[i] = min(dp[j]+o[j~i]^2,dp[i]) ,o[j~i]表示从j到i颜色的种数. 普通的O(n*n)是会超时的,可以想到o[]最大为 ...

  4. 百度云管家 5.3.6 VIP破解不限速版下载分享|百度云管家破解提速

    百度云管家PC客户端v5.3.6绿色版本,属于VIP破解不限速版.百度网盘为您提供文件的网络备份.同步和分享服务.空间大.速度快.安全稳固,支持教育网加速,支持手机端.它支持便捷地查看.上传.下载云端 ...

  5. LeetCode40 Combination Sum II

    题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combination ...

  6. 如何使用event 10049分析定位library cache lock and library cache pin

    Oracle Library Cache 的 lock 与 pin 说明 一. 相关的基本概念 之前整理了一篇blog,讲了Library Cache 的机制,参考: Oracle Library c ...

  7. android压缩解压zip文件

    网上各种方法的收集: 1.上次写了个解压缩功能,但有局限性,比如压缩文件xx.zip 里包括子目录的情况下,执行上次解压缩的功能就不能实现我们想要的效果,于是在网上参考了一下java的解压缩功能.对上 ...

  8. Spring、Spring MVC、MyBatis

    Spring.Spring MVC.MyBatis整合文件配置详解 使用SSM框架做了几个小项目了,感觉还不错是时候总结一下了.先总结一下SSM整合的文件配置.其实具体的用法最好还是看官方文档. Sp ...

  9. 编写简单的hashCode方法

    为什么要编写hashCode方法 hashCode在平时不常自己去编写,但是在真正高质量的代码中却是必不可少的. 看看Java中的Object对hashCode方法的描述: 1.返回对象的哈希码,是为 ...

  10. Express4.x API (四):Router (译)

    Express4.x API 译文 系列文章 Express4.x API (一):application (译) -- 进行 Express4.x API (二):request (译) -- 完成 ...