Getting Started with Java (ii): Comments and basic data types

Source: Internet
Author: User

The last time I output hello world through Eclipse on the console, isn't it a little bit exciting, and today we're going to introduce Java basics.

One, Java annotations

1, Java comment Statements will not be run by the compiler, do not worry about the code because many comment statements appear bloated and affect the speed of the program.

2, Java comments have three kinds of writing.

One is double slash//. You need to note which line to add to the front of which line, when adding Chinese comments, in the double slash//After adding a space, write the comment content, this is the encoding specification.

Two is */* */. Such comment tags can annotate multiple lines without having to use single-line comments for each row.

Three is/** * *. Such comments can also comment on multiple lines, more than the class name, the method name.

 Packagejavalearningday01;/*** Use of Java annotations *@authorAdministrator * @date January 14, 2018*/ Public classUsecommentstag { Public Static voidMain (string[] args) {/** Annotation Method Two * can comment multiple lines*/System.out.println ("This is the Main method"); }        /*** Comment Method Three *@returnstring returns a string*/     PublicString Usetag () {//Comment Method Two, single-line comment        return"It's a common method."; }        /*** Here's what you can do about this method *@paramSTR parameter name, which describes what parameters are passed in *@returnreturns a value that indicates what data is returned*/     Publicstring Usemethod (String str) {return"Hello" +str; }}

Second, Java basic data types

Before you understand the basic data types, talk about storage units. The computer will not know you input Chinese, kanji and other content, but convert it to machine can read the binary code, is composed of 0 and 1 of the number of long strings, so there are different numbers, we often use decimal numbers (such as 2,3,100, etc.), but there are binary, octal, hexadecimal.

Bit (bit): A bit represents the space used to store 1 or 0, which is the smallest unit of data.

Byte (byte): Compare common data units, 1 byte = 8 bit.

KB (k): 1 K = 1024x768 byte.

megabytes (m): 1 M = 1024x768 K.

G byte: 1 g = 1024x768 M.

T byte: 1 t = 1024x768 G.

Java has 4 kinds of data types, one is the integer type, two is floating point type, three is the character type, four is the Boolean type.

The following steps go directly to the underlying data type.

 Packagejavalearningday01;/*** Java basic data type *@authorOgawa 94 * @date January 14, 2018*/ Public classDataType { Public Static voidMain (string[] args) {DataType dt=NewDataType ();        Dt.viewchar ();        Dt.viewbyte ();        Dt.viewshort ();        Dt.viewlong ();        Dt.viewfloat ();        Dt.viewdouble ();    Dt.viewboolean (); }        /*** Character type: Char, two bytes, 16 bits*/     Public voidViewchar () {System.out.println ("=========== View char method start ============="); //character is a wrapper class for Char        CharCharmaxvalue =Character.max_value; System.out.println ((int) charmaxvalue);//65535        CharCharminvalue =Character.min_value; System.out.println ((int) charminvalue);//0//conversion between char and int        CharCharNumber = ' A '; System.out.println ((int) charnumber);// $        CharCharNumber2 = 65; System.out.println (CHARNUMBER2); //A//To view the corresponding Unicode encoded value        CharCharNumber3 = ' Medium '; System.out.println ((int) charNumber3);//20013System.out.println ("=========== view char method End ============="); }        /*** Integer: Byte, 1 bytes, 8 bits * 1 byte (1 bytes) = 8 bit (8 bits, 8 binary encoded) * Eight-bit binary 1 1 1 1 1 1 1 1 * Eight-bit binary corresponding integer 128 64 32 16 8 4 2 1 * 02-binary is 0000 0000 * Eight-bit binary representation: 1 + 1 = 2 * 000 00001 + 00000001 = 00000002 = 00000010 This is the every two in a*/     Public voidViewbyte () {System.out.println ("=========== View byte method Start ============="); //byte is the wrapper class for byte        byteBytemaxvalue =Byte.max_value; System.out.println (Bytemaxvalue); //Bytemaxvalue = 127        byteByteminvalue =Byte.min_value; System.out.println (Byteminvalue); //Byteminvalue = -128System.out.println (integer.tobinarystring (Byteminvalue)); //convert 3 into 8-bit binary, 0000 0011,System.out.println (Integer.tobinarystring (3));// OneSystem.out.println ("=========== view byte method End ============="); }        /*** Integral type: Short, 2 bytes, 16 bits*/     Public voidViewshort () {System.out.println ("=========== See Short method Start ============="); //Short is the packing class for short         ShortShortmaxvalue =Short.max_value; System.out.println (Shortmaxvalue); //32767         ShortShortminvalue =Short.min_value; System.out.println (Shortminvalue); //-32768         ShortShortnumber = 323+4343; System.out.println (Shortnumber); //4666System.out.println ("=========== view short method End ============="); }        /*** integer: int,4 byte, 32-bit*/     Public voidViewint () {System.out.println ("=========== View int method Start ============="); //view the maximum and minimum values of int, which is the wrapper class for int        intMaxintnumber =Integer.max_value; System.out.println (Maxintnumber); //Maxintnumber = 2147483647        intMinintnumber =Integer.min_value; System.out.println (Minintnumber); //Minintnumber = -2147483648//value overflow, reasonable estimation of the size of the calculation, the appropriate range of data types        intOverFlow = 1299999999+1299999999; System.out.println (OverFlow); //OverFlow = -1694967298//Replace int with a long type        LongSuitrange = 1299999999l+1299999999l; System.out.println (Suitrange); //Suitrange = 2599999998//1299999999 literal or int,1299999999+1299999999 calculated value or int type        LongSuitRange2 = 1299999999+1299999999; System.out.println (SuitRange2); //suitRange2 = -1694967298//The literal of the 1299999999L is the literal of the long,1299999999, which is the sum of the two, taking the large side as the result value of the literal        LongSuitRange3 = 1299999999l+1299999999; System.out.println (SuitRange3); //SuitRange3 = 2599999998//conversions between strings and int can only be used for conversions between a pure number and a suitable range valueString intstr = "1278098"; intIntnumber =Integer.parseint (INTSTR); System.out.println (intnumber); //intnumber = 1278098System.out.println ("=========== view int method ends ============="); }        /*** Integer: Long, 8 bytes, 64 bits * When assigning, you need to add an L (lowercase l) or L to the trailing value*/     Public voidViewlong () {System.out.println ("=========== View Long method start ============="); //Long is a long type of wrapper class        LongLongmaxvalue =Long.max_value; System.out.println (Longmaxvalue); //9223372036854775807        LongLongminvalue =Long.min_value; System.out.println (Longminvalue); //-9223372036854775808        LongLongnumber = 3999+7328328323728332l; System.out.println (Longnumber); //7328328323732331System.out.println ("=========== view long method ends ============="); }        /*** float: Float, 4 bytes, also known as single-precision type, 32-bit * when assigning, you need to add an F or F to the trailing value*/     Public voidviewfloat () {System.out.println ("=========== View Float method Start ============="); //Float's maximum value, minimum value, float is the packing class of float        floatFloatmaxvalue =Float.max_value; System.out.println (Floatmaxvalue); //Floatmaxvalue = 3.4028235E38        floatFoatminvalue =Float.min_value; System.out.println (Foatminvalue); //Foatminvalue = 1.4E-45        floatFloatnumber = 3.14f+3;        System.out.println (Floatnumber); System.out.println ("=========== View Float method End ============="); }        /*** Floating-point type: Double, 8 bytes, also known as double type, 64-bit * When assigning, you need to add a D or D to the end of the value*/     Public voidviewdouble () {System.out.println ("=========== View Double method start ============="); //double the maximum value, minimum value, double is the wrapper class of double        DoubleDoublemaxvalue =Double.max_value; System.out.println (Doublemaxvalue); //Doublemaxvalue = 1.7976931348623157E308        DoubleDoubleminvalue =Double.min_value; System.out.println (Doubleminvalue); //Doubleminvalue = 4.9E-324        DoubleDoublenum = 3.1d+3.2d; System.out.println (Doublenum); //doublenum = 6.300000000000001System.out.println ("=========== view double method ends ============="); }        /*** Boolean: Boolean, only true, false two value, for logical judgment*/     Public voidViewboolean () {System.out.println ("=========== View Boolean method Start ============="); BooleanBoo =true; BooleanBoo2 =false; //Boolean is a Boolean wrapper class        BooleanBoo3 =boolean.true; BooleanBoo4 =Boolean.false; System.out.println (Boo= = Boo3);//trueSystem.out.println (Boo2 = = Boo4);//true        BooleanBoo5 = 2 > 3; System.out.println (BOO5); //Boo3 = FalseSystem.out.println ("=========== View Boolean method ends ============="); }    }

Getting Started with Java (a) and getting Started with Java (ii) The source code has been uploaded git, address:https://github.com/XiaoChuan94/javalearning, you can refer to.

The article starts with my personal public number: Yue Lok book . I like to share the songs I've heard, the movies I've seen, the books I've read, the code I've been reading, the deep-night meditation. Look forward to your attention!

Public number backstage Enter the keywords "java learning ebook ", you can get 12 Java learning related e-book resources, if the economic capacity allows, but also to support the book author of the original paper books, creation is not easy.

Getting Started with Java (ii): Comments and basic data types

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.