<java基础学习>RE 基础语法(2)
Java Modifiers(java修饰符):
Like other languages, it is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers(两类修饰):
Access Modifiers(可访问): default, public , protected, private
Non-access Modifiers(不可访问): final, abstract, strictfp
We will be looking into more details about modifiers in the next section.
Java Variables(变量):
We would see following type of variables in Java:
- Local Variables(局部变量)
- Class Variables (Static Variables) 类变量-静态变量
- Instance Variables (Non-static variables) 实例变量-非静态变量
Java Arrays(数组):
Arrays are objects that store multiple variables of the same type. However, an array itself is an object on the heap(堆). We will look into how to declare, construct and initialize(初始化) in the upcoming chapters.
Java Enums(枚举):
Enums were introduced in java 5.0. Enums restrict a variable to have one of only a few predefined values(预定义的值). The values in this enumerated list are called enums.
With the use of enums it is possible to reduce the number of bugs in your code.
For example, if we consider an application for a fresh juice shop, it would be possible to restrict the glass size to small, medium and large. This would make sure that it would not allow anyone to order any size other than the small, medium or large.
Example:
class FreshJuice { enum FreshJuiceSize{ SMALL, MEDIUM, LARGE }
FreshJuiceSize size;
} public class FreshJuiceTest { public static void main(String args[]){
FreshJuice juice = new FreshJuice();
juice.size = FreshJuice. FreshJuiceSize.MEDIUM ;
System.out.println("Size: " + juice.size);
}
}
Above example will produce the following result:
Size: MEDIUM
Note: enums can be declared as their own or inside a class. Methods, variables, constructors can be defined inside enums as well.
Inheritance(继承):
In Java, classes can be derived from classes. Basically if you need to create a new class and here is already a class that has some of the code you require, then it is possible to derive(源于,得自,起源) your new class from the already existing code.
This concept allows you to reuse the fields and methods of the existing class without having to rewrite the code in a new class. In this scenario the existing class is called the superclass and the derived class is called the subclass.
Interfaces(接口):
In Java language, an interface can be defined as a contract between objects on how to communicate with each other. Interfaces play a vital role when it comes to the concept of inheritance.
An interface defines the methods, a deriving class(subclass) should use. But the implementation of the methods is totally up to the subclass.
<java基础学习>RE 基础语法(2)的更多相关文章
- java基础学习总结——基础语法1
一.标识符
- <java基础学习>RE 基础语法
public class MyFirstJavaProgram{ public static void main(String[] args ){ System.out.println("H ...
- java基础学习总结——基础语法2
一.语句
- 吴裕雄--天生自然 JAVA开发学习:基础语法
package test; public class temp { /* 第一个Java程序 * 它将打印字符串 Hello World */ public static void main(Stri ...
- Java 基础学习1 -- 基础语法
1.变量
- Java Script 学习笔记 -- 基础知识
Java script 概述 java Script 的简介 JavaScript一种直译式脚本语言,是一种动态类型.弱类型.基于原型的语言,内置支持类型.它的解释器被称为JavaScript引擎,为 ...
- JAVA基础学习day24--Socket基础一UDP与TCP的基本使用
一.网络模型 1.1.OIS参考模型 1.2.TCP/IP参考模型 1.3.网络通讯要素 IP地址:IPV4/IPV6 端口号:0-65535,一般0-1024,都被系统占用,mysql:3306,o ...
- JAVA基础学习day23--GUI基础
一.GUI概述 1.1.GUI概述 Graphical User Interface(图形用户接口) 用图形的方式,来显示计算机操作的界面, CLI: Command line User Interf ...
- Java基础学习之基础概念与环境搭建(1)
1.Java基础概念 1.1.Java语言的特点 Java语言是简单易学的 Java语言是面向对象(封装.继承和多态) Java语言是平台无关的(一次编译,到处运行) Java语言是可靠的.安全的(异 ...
随机推荐
- web前端面试题总结
HTML Doctype作用? 严格模式与混杂模式如何区分?它们有何意义? (1).<!DOCTYPE> 声明位于文档中的最前面,处于 <html> 标签之前.告知浏览器的解析 ...
- boost学习笔记(七)---date_time库
date_time库的日期基于格里高利历,支持从1400-01-01到9999-12-31之间的日期计算 #define BOOST_DATE_TIME_SOURCE #include <boo ...
- 遗传算法在JobShop中的应用研究(part4:变异)
下面,我们以车间调度为例来谈谈遗传算法中的另一个重要操作变异.变异操作通常发生在交叉操作之后,它的操作对象是交叉得到的新染色体.在本文中我们通过随机交换染色体的两个位置上的值来得到变异后的染色体,变异 ...
- mysql 语句的索引和优化
一.基本语句优化 1.尽量避免在列上进行运算,这样会导致索引失败.例如: select * from table where DATE_FORMAT(`customer_regtime`,'%Y')& ...
- 在WebBrowser中截获弹出对话框内容并将其屏蔽
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- RDCManager(远程登录工具)
1: 2: 3: 4: 5 6 写文不易,转载请注明出处:http://www.cnblogs.com/zszs/p/5662752.html
- fullpage 单屏高度超过屏幕高度,实现单屏内可以滚动并解决手机端单屏高度不正确的问题
最近接触了好几次jquery.fullpage.js这个插件,实现整屏的滑动,效果很炫,用fullpage来实现也很简单,但是也碰到了一些问题和大家分享一下 1.单屏高度超过屏幕高度,实现单屏的滑动 ...
- 误删除libc.so.6 恢复
一.我是怎样一步一步毁掉系统的 最近在centos 7上进行开发.由于需要使用高版本linux内核的特性,需要将linux内核升级.按照教程:centos 7升级内核 进行升级的时候发现在安装elre ...
- 通过页面调用APP【H5与APP互通】
现在H5和App原生的内容原来越互通,所涉及的业务也越来越复杂和融合,所以如何互相之间方便的调用才是王道. 场景1 比如用hybrid获取地理位置和短信信息,这当然需要框架封装好,比如利用框架的bri ...
- vue的选项
这篇是我自己看着方便整理的,请直接看官方api:http://cn.vuejs.org/v2/api/ 数据 data,props,computed 注意,不应该使用箭头函数来定义计算属性函数 (例如 ...