Chapter 1 Identifiers, Keywords, and Types

1.1.   Comments

Three permissible styles of comment in a Java technology program are:

// comment on one line

/* comment on one

or more lines */

/** documenting comment */ use the javadoc tool to create documentations

 

1.2.   Identifiers

Identifiers are used to identify variables, classes, or methods. Simply speaking, identifiers are names given to variables, classes, or methods.

A.       Identifiers are composed with letters (characters), numbers, underscores (_), or dollar signs ($), but cannot start with number. Java language uses Unicode characters. So letters are not only Latin letters but also characters in other languages, such as Chinese characters.

B.        Other signs are not accepted.

C.        Identifiers are case sensitive. Upper case and lower case are not the same.

D.       Identifiers have no maximum length. We can create an identifier as long as we want without limitation.

 

1.3.   Keywords and reserved words

Keywords are some words which are for special use in Java languages. These words cannot be used as identifiers or for others purposes. Keywords are all lower cases. There are 53 keywords and reserved words in Java language:

abstract: an abstract class or method

assert: used to locate internal program errors

boolean: the Boolean type

break: breaks out of a switch or loop

byte: the 8-bit integer type

case: a case of a switch

catch: the clause of a try block catching an exception

char: the Unicode character type

class: defines a class type

const: not used

continue: continues at the end of a loop

default: the default clause of a switch

do: the top of a do/while loop

double: the double-precision floating-number type

else: the else clause of an if statement

extends: defines the parent class of a class

final: a constant, or a class or method that cannot be overridden

finally: the part of a try block that is always executed

float: the single-precision floating-point type

for: a loop type

goto: not used

if: a conditional statement

implements: defines the interface(s) that a class implements

import: imports a package

instanceof: tests if an object is an instance of a class

int: the 32-bit integer type

interface: an abstract type with methods that a class can implement

long: the 64-bit long integer type

native: a method implemented by the host system

new: allocates a new object or array

null: a null reference

package: a package of classes

private: a feature that is accessible only by methods of this class

protected: a feature that is accessible only by methods of this class, its children, and other classes in the same package

public: a feature that is accessible by methods of all classes

return: returns from a method

short: the 16-bit integer type

static: a feature that is unique to its class, not to objects of its class

strictfp: Use strict rules for floating-point computations

super: the superclass object or constructor

switch: a selection statement

synchronized: a method or code block that is atomic to a thread

this: the implicit argument of a method, or a constructor of this class

throw: throws an exception

throws: the exceptions that a method can throw

transient: marks data that should not be persistent

try: a block of code that traps exceptions

void: denotes a method that returns no value

volatile: ensures that a field is coherently accessed by multiple threads

while: a loop

 

1.4.   Types

Types are primitive types, and classes and objects. We are only discussing primitive types.

1.4.1.               Logical Types

The boolean data type has two literals, true and false. Integers cannot sign a boolean variable.

 

1.4.2.               Numeric Types

1.4.3.               

char

The char data type is a special numeric type. It can be considered as textual because it represents a 16-bit Unicode character. Its literal can be an unsigned short integer (16 bits) or a character enclosed in single quotes (’ ’).

Integral – byte, short, int, and long

A.       The default is int. If an integer does not define a type, it must be int type.

B.        Uses three forms – Decimal, octal, or hexadecimal

C.        Defines long by using the letter L or l: long num = 1000L

Floating Point – float and double

A.       The default is double

B.        Defines float by using the letter F or f:

 

1.4.4.               Declare and assign variables

int a; /*declare an int variable*/ a = 10; /*assign value to the variable*/

int b = 5; // declare and assign int

In a method, variables of primitive types are allocated memory spaces while declaring. So, variables of primitive types must be assigned in a method.

 

1.4.5.               Convert types

Automatic

byte --> short(char) --> int --> long --> float --> double

forcible

byte <-- short(char) <-- int <-- long <-- float <-- double

 

1.4.6.               String

String is a class, not a primitive type. But it can be used like a primitive type.

String str = “Hello”; // declare like a primitive type

String str = new String(“Hello”); // declare like an object.

But the two way are not the completely same. The first way will allocate memory space in a String pool, and the other way will allocate memory space directly.

String is an class. So however to declare the variable, the variable is always an object. Two Sting variables cannot use “==” to compare, because it will compare the memory space addresses, not values.

 

The differences between primitive types and classes while declaring and assigning:

Declaration of primitive types allocates memory space

Declaration of nonprimitive types (classes) does not allocate memory space

Declared object variables are not the data itself, but references (or pointers) to the data

An object declaration allocates storage only for a reference and use the new operator to allocate and initialize storage

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值