[Java in NetBeans] Lesson 06. Custom classes
这个课程的参考视频和图片来自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的更多相关文章
- [Java in NetBeans] Lesson 04. Class / Objects
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Class: Blueprint for an object. (e.g. dog is a class) Object: cust ...
- [Java in NetBeans] Lesson 09. Switch / If-Else Ladder
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. Nested If-else statement (if-else ladder) /** * 90 and above == ...
- [Java in NetBeans] Lesson 07. JavaDoc and Unit Tests
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. organize code into packages Create a package if want to make th ...
- [Java in NetBeans] Lesson 05. Method/function
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Define a method:(motivation: write one time, but use it many times ...
- [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 ...
- [Java in NetBeans] Lesson 17. File Input/Output.
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...
- [Java in NetBeans] Lesson 16. Exceptions.
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...
- [Java in NetBeans] Lesson 15. Sorting and Searching.
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Build in functions in java.util.Collections Need to implement a co ...
- [Java in NetBeans] Lesson 01. Java Programming Basics
这个课程的参考视频在youtube. 主要学到的知识点有: Create new project, choose Java Application. one .jar file/ package(.j ...
随机推荐
- 网络通信协议三之TCP/IP模型详解
TCP/IP模型 注:PDU:Protocol Date Unit:表示对等层之间传递的数据单位 TCP:Transmission Control Protocol:传输控制协议 UDP:User D ...
- textarea 固定大小,滚动条,限制拖动,文字对齐
取值:$("#ID").val(); 控制大小:加width,height限制(style="width:100px;height:200px;");或row, ...
- ThinkPHP框架 【 AJAX方法返回 】 例子:简单添加一条数据 和 查询一个表里的数据
注:thinkphp使用ajax和之前使用ajax的方法一样,不同点在于之前的ajax中的url指向了一个页面,而thinkphp里面的url需要指向一个操作方法. 在模块控制器Controller文 ...
- 启动elk中elasticsearch服务报错which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
解决办法: vi /etc/sysconfig/elasticsearch JAVA_HOME=/usr/local/java sudo systemctl restart elasticsearch ...
- zabbix监控主机CPU使用率
zaibix默认模板针对CPU只有监控负载(load)没有监控CPU使用率 选择配置-模板-Template OS Windows-监控项 创建监控项 创建监控图形 查看图像结果
- LeetCode 112 Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- [No0000D5]便利所有子目录更改后缀名bat
pause for /r %%i in (.) do ( cd %%i ren *.txt *.dll ) pause
- 生成树协议(STP)
首先了解一下环路问题: 两个交换机将两个局域网同时连接起来的时候,不幸地出现了环路: 这两个交换机还是都能够收到广播包的.交换机 A 一开始是不知道机器 2 在哪个局域网的,所以它会把广播消息放到局域 ...
- nginx反向代理服务器获取不到端口的问题的解决办法
使用nginx为反向代理服务器时,后端应用程序获取不到请求端口的解决办法. 以下是nginx 简单的配置 server { listen 81; serve ...
- 存储过程收集统计信息ORA-20000报错解决记录
存储过程如下: create or replace procedure ad.table_analyse_bill( p_BillMonth in number,--bill_month p_tail ...