Home > Backend Development > C#.Net Tutorial > Is there any difference between c language and java syntax?

Is there any difference between c language and java syntax?

青灯夜游
Release: 2019-12-26 16:51:28
Original
3536 people have browsed it

Is there any difference between c language and java syntax?

#Is there any difference between c language and java syntax?

There are grammatical differences between C language and Java. The difference is:

1. C language has pointers, but Java does not have pointers;

The syntax of C language is relatively simple, but its highlight pointer is easy to make mistakes. It is difficult to make good use of pointers. If used well, it will be very helpful to the program. On the contrary, it will make The program crashes, and Java does not have the concept of pointers. Java is more practical and practical for developing things. Therefore, it also effectively prevents a series of operating layer errors caused by pointers (such as system crashes caused by dangling pointers), which is more conducive to Security of Java programs.

2. Identifiers

The identifiers available in C language are numbers, uppercase and lowercase letters, and underscores, and cannot start with numbers; the identifiers available in Java are except C. In addition to the three types, there is one more dollar sign ($), which also cannot start with a number.

3. Keywords:

The keywords in C are:

auto break case char const

continue default do double else

##enum extern float for goto

##if int long register return

short signed sizeof static struct

##switch typedef union unsigned void

volatile while

The keywords in Java are:

abstract boolean break byte case

catch char class continue default

do double else extends false

final finally float for if

implements import instanceof int interface

long native new null package

private protected public return short

this throws transient true

try static super switch synchronized

void volatile while

##4. Data type :

The data types in C are: 1) Basic types: integer type (basic integer type int, short integer type short[int] and long integer type long [int ] and signed type [signed], unsigned type unsigned), character type [signed/unsigned] char, floating point type (single precision float, double precision double and long double precision long double), enumeration type

2) Construction type: array type, structure type, union type

3) Pointer type

4) Empty type

Note The general number of bytes occupied by each type:

int: 2 bytes

short: 2 bytes

long: 4 bytes

char: 1 byte

float: 4 bytes

double: 8 bytes

long double: 16 bytes

The above storage is except char Except for the type, other systems are slightly different, but the number of low-precision digits cannot exceed that of high-precision.

Data types in Java:

1) Basic types: character type (char), numerical type (integer type (byte type byte, short integer type short, integer type int, long type) Integer type long), floating point type (single precision type float, double precision type double)), Boolean type (boolean (true or false))

2) Composite type: class, interface, array

Note the number of bytes occupied by each type of storage:

byte: 1 byte

short: 2 bytes

int: 4 bytes

long: 8 bytes

char: 2 bytes (Unicode encoding)

float: 4 bytes

double: 8 bytes

The storage space corresponding to the above data types has nothing to do with the platform and is fixed to this value.

5. Logical operators and bitwise operators

The logical operators &&, ||, ! both in C and Java. There are three types, and they have the same meaning. The difference is that the operation result in C is 0 and non-0, while in Java it can only be true or false. There are also &, |, ^ (XOR) in Java. The difference between & and &&, | and || is that the former is a non-shortcut operator and the latter is a shortcut operator, that is, judgments are made before and after &, and if false before &&, no judgment is made. For the subsequent judgment, |judges both before and after. If || is true before, the subsequent judgment will not be made. ^ means both are the same and false.

The bitwise operators in both C and Java are: &, |, ^, ~ (reverse), << (left shift), >> (right shift), and their meanings are basically the same. The right shift operation of negative numbers in C differs depending on the system (it may be an arithmetic right shift or a logical right shift), while in Java, >> represents an arithmetic right shift, that is, the highest bit is filled with the sign bit. The logical right shift (unsigned right shift) operator in Java is >>>, which uses two's complement right shift and adds 0 to the high bit.

Recommended learning: Java video tutorial

The above is the detailed content of Is there any difference between c language and java syntax?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template