[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 ...
随机推荐
- 微信小程序学习——框架视图层(view)
视图层是有WXML与WXSS编写的,由组件来进行展示. WXML(WeiXin Markup Language)用于写页面结构的. WXSS(WeiXin Style Sheet)用于页面的样式. 组 ...
- CSS:盒模型和position定位
盒模型 页面上显示的每个元素(包括内联元素)都可以看作一个盒子,即盒模型( box model ).请看Chrome DevTools 里的截图: 可以显而易见的看出盒模型由 4 部分组成.从内到外分 ...
- Amazon Aurora: Design Considerations for High Throughput Cloud-Native Relational Databases
INTRODUCTION In modern distributed cloud services, resilience and scalability are increasingly ach ...
- 操作系统->数组越界(待完善)
工作中无意间发现了一段可能存在数组越界的代码, 就在本地仿者写了一段越界的小程序, 先记录下,待以后看操作系统知识的时候,再深入分析 #include <stdio.h> #include ...
- 《Redis 数据操作》
一:字符串类型(string) - 应用场景 - 用于常规计数,常规的 key-value 存储. - 常用操作 常用操作 设置一个值为(字符串类型) SET key value 设置一个值并设置过 ...
- Appium入门(8)__控件定位
部分摘自:http://www.testclass.net/appium/appium-base-find-element/ appium 通过 uiautomatorviewer.bat 工具来查看 ...
- 自动化测试:java + testng + maven + reportng + jenkins + selenium (一)_基于win环境
集成环境:jdk1.7 + tomcat1.7+ eclipse mars + maven + testng6.14.2 + selenium-java2.40.0 + reportng1.1.4 + ...
- Mybatis批量insert 返回主键值和foreach标签详解
Mybatis批量insert 返回主键 Mybatis从3.3.1版本开始,支持批量插入后返回主键ID.首先对于支持自增主键的数据库使用useGenerateKeys和keyProperty,对于不 ...
- 实现用 jquery 禁用浏览器的前进后退按钮
- 产品列表中使用v-lazyload插件懒加载img图片,但是当产品列表重新排序(人气,销量,价格...),产品info信息改变,但是 img 图片没有发生变化;
1.控制台查看 DOM 结构,发现 DOM 绑定的图片链接也没有发生变化: 2.查阅资料找到解决方法,只需要在 img 标签中增加 :key='imgUrl',即可实现 img 图片随数据排序的改变动 ...