Java Learning Journey-1

Source: Internet
Author: User
Tags class definition java format

Learned Java almost two days, to say and C language difference, still have a lot of, but have to say, the first to learn C language to learn other languages really has a lot of help.
First of all, take a look at the basic Java and C language formats.
Java format:

public class  Demo{    public static void main(String[] args)     {    }}

C Language Format:

#include <stdio.h>int main(){return 0;}

Java does not have a header file, there is a class definition (I compile now, the file name and the class name, but now do not know the specific requirements of the Class), string[] args at this stage do not know what is, first used to say, like this basic format first remember.
Second, the integer type in Java is to be divided into a bit finer, with byte (1 bytes), short (2 bytes), int (4 bytes), Long (8 bytes), and C not so much, at most +long.
At the same time in learning Java, I finally understand the original code, complement and anti-code is what, the original code is its own binary code, the highest bit is the symbol bit, 0 for positive, 1 for negative, positive for the original code, anti-code, complement the same, negative anti-code is the original code of the symbol bit unchanged, the remaining bit 0 The complement is based on the inverse code of the addition of 1 (with 10 and 10 for example):

10的原码,反码和补码均为00001010。而-10的原码为10001010,其反码为11110101,补码为11110110.

In addition, Java's binary representation is peculiar:

1,二进制整数:0B或0b开头,如:int a = 0B110;2,八进制整数:要求以0开头,如:int a = 012;3,十进制整数:如:int a = 17;4,十六进制整数:要求0x或0X开头,如int a =0x12;

Java represents the character type of the constant method is also quite a lot of, can directly represent the symbol, can also be expressed in ASCII code, or with the hexadecimal representation of ASCII code (C language can also), the most amazing is incredibly can also put Chinese characters to assign value!

public class CharDemo {    public static void main(String[] args)     {        char c1 = ‘A‘;//直接表示符号        System.out.println(c1);        char c2 = 65;//表示符号对应的10进制顺序        System.out.println(c2);        char c3 = ‘\u0041‘;//表示符号对应的十六进制顺序(补全四位)        System.out.println(c3);        char c4 = ‘哥‘;//表示汉字        System.out.println(c4);    }}

Continue the Java Learning Path!

Java Learning Journey-1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.