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)的更多相关文章

  1. java基础学习总结——基础语法1

    一.标识符

  2. <java基础学习>RE 基础语法

    public class MyFirstJavaProgram{ public static void main(String[] args ){ System.out.println("H ...

  3. java基础学习总结——基础语法2

    一.语句

  4. 吴裕雄--天生自然 JAVA开发学习:基础语法

    package test; public class temp { /* 第一个Java程序 * 它将打印字符串 Hello World */ public static void main(Stri ...

  5. Java 基础学习1 -- 基础语法

    1.变量

  6. Java Script 学习笔记 -- 基础知识

    Java script 概述 java Script 的简介 JavaScript一种直译式脚本语言,是一种动态类型.弱类型.基于原型的语言,内置支持类型.它的解释器被称为JavaScript引擎,为 ...

  7. JAVA基础学习day24--Socket基础一UDP与TCP的基本使用

    一.网络模型 1.1.OIS参考模型 1.2.TCP/IP参考模型 1.3.网络通讯要素 IP地址:IPV4/IPV6 端口号:0-65535,一般0-1024,都被系统占用,mysql:3306,o ...

  8. JAVA基础学习day23--GUI基础

    一.GUI概述 1.1.GUI概述 Graphical User Interface(图形用户接口) 用图形的方式,来显示计算机操作的界面, CLI: Command line User Interf ...

  9. Java基础学习之基础概念与环境搭建(1)

    1.Java基础概念 1.1.Java语言的特点 Java语言是简单易学的 Java语言是面向对象(封装.继承和多态) Java语言是平台无关的(一次编译,到处运行) Java语言是可靠的.安全的(异 ...

随机推荐

  1. divmod(a,b)函数是实现a除以b,然后返回商与余数的元组、eval可以执行一个字符串形式的表达式、exec语句用来执行储存在字符串或文件中的Python语句

    #!/usr/bin/env python a = 10/3 print(a) #divmod计算商与余数 r = divmod(10001,20) print(r) #eval可以执行一个字符串形式 ...

  2. 合并文件夹里多个excel

    Sub 合并当前目录下所有工作簿的全部工作表() Dim MyPath, MyName, AWbName Dim Wb As workbook, WbN As String Dim G As Long ...

  3. python非递归全排列

    刚刚开始学习python,按照廖雪峰的网站看的,当前看到了函数这一节.结合数组操作,写了个非递归的全排列生成.原理是插入法,也就是在一个有n个元素的已有排列中,后加入的元素,依次在前,中,后的每一个位 ...

  4. 《BI那点儿事—数据的艺术》目录索引

    原创·<BI那点儿事—数据的艺术>教程免费发布 各位园友,大家好,我是Bobby,在学习BI和开发的项目的过程中有一些感悟和想法,整理和编写了一些学习资料,本来只是内部学习使用,但为了方便 ...

  5. winpcap抓包原理

    winpcap抓包原理 WinPcap 是由伯克利分组捕获库派生而来的分组捕获库,它是在Windows 操作平台上来实现对底层包的截取过滤.WinPcap 是 BPF 模型和 Libpcap 函数库在 ...

  6. Memcached的使用

    为什么要使用Memcached? 1)高并发访问数据库的痛:死锁 2)磁盘IO之痛 3)读写性能完美 4)超简单的集群搭建Cluster 5)开源 6)性能最佳 7)丰富的成功案例 Memcached ...

  7. [Java] Java解析XML格式Response后组装成Map

    //Get and Parse Response def response = context.expand(‘${TestStepName#Response}’) def xmlParser = n ...

  8. android持久化技术

    Android系统提供了3种持久化技术,所谓持久化技术是指将内存中的书籍保存在存储设备中. 1.文件存储 2.sharedPreference存储 3.数据库存储 除此之外,还可以将数据保存在SD卡中

  9. TestNG BeforeClass BeforeMethod Test AfterClass AfterMethod

    http://topmanopensource.iteye.com/blog/1983729 1.TestNG测试注解和Junit注解的不同以及生命周期: TestNG测试的一个方法的生命周期: @B ...

  10. 使用Kylin构建企业大数据分析平台的4种部署方式

    本篇博客重点介绍如何使用Kylin来构建大数据分析平台.根据官网介绍,其实部署Kylin非常简单,称为非侵入式安装,也就是不需要去修改已有的 Hadoop大数据平台.你只需要根据的环境下载适合的Kyl ...