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. C#常用开源类库

    一.AOP框架        Encase 是C#编写开发的为.NET平台提供的AOP框架.Encase 独特的提供了把方面(aspects)部署到运行时代码,而其它AOP框架依赖配置文件的方式.这种 ...

  2. 《与小卡特一起学Python》 Code2

    下边是一个猜数字的小游戏: 几乎所有语言都这样做的…… here we go! import random secret = random.randint(1,99) guess = 0 tries ...

  3. [地图SkyLine二次开发]关于IE内存限制问题(1G)

    相信很多人也遇到过同样的问题,地图加载中,IE占用的内存一直增加,到了1G多一些的时候,IE就崩溃了. 在网上查阅了一番,有很多结果,下面归纳一下: a).64bit的IE最多可达到4G的内存,但Sk ...

  4. leveldb 学习。

    1)大概浏览了leveldb文档的介绍.本想逐步看代码,想想还是自己先实现一个看看如何改进. 2)完成了一个非常丑陋的初版,但是还是比初初版有进步. 3)key value的数据库,不允许有key重复 ...

  5. Bootstrap之Carousel不能自动播放的解决办法(转)

    Bootstrap是一个非常好的css/javaScript框架,尤其对于移动端的自适应和适配能力都比较强. 用Bootstrap自带的Carousel写了一个图片轮播的广告部分,用js调用后却出现了 ...

  6. linux下使用多线程编写的聊天室

    自从开始学linux网络编程后就想写个聊天室,一开始原本打算用多进程的方式来写,可是发觉进程间的通信有点麻烦,而且开销也大,后来想用多线程能不能实现呢,于是便去看了一下linux里线程的用法,实际上只 ...

  7. 14TH本周工作量及进度统计

      14TH本周工作量及进度统计    本周psp:                    C(类别) C(内容) S(开始时间) ST(结束时间) I(中断时间) T(实际时间) 活动 本周会议 1 ...

  8. 01.JavaScript 面向对象精要--原始类型和引用类型

    一.什么是类型 JavaScript 虽然没有类的概念.但依然存在两种类型:原始类型和应用类型. 原始类型保存为简单的数据值,引用类型则保存为对象,其本质是指向内存位置 的引用.也就是说:原始值被直接 ...

  9. tar 解压常用压缩文件格式命令大全

    常用压缩文件格式就那么几种,解压命令总结在此:   1 2 3 4 5 6 7 8 tar xzf filename.tar.gz tar xjf filename.tar.bz2 tar xzf f ...

  10. Toolbar设置回退箭头的方法

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); //关键下面两句话,设置了回 ...