Java Learning Note (Core Java) 1-3

Source: Internet
Author: User
Tags array sort

To prepare to learn the next Java, according to the "core Java" content, simply made a note. There are many places in this book that compare the syntax of C + + and Java, so it's very advantageous for those who turn from C + + to Java!

Javac Xxx.java
java XXX

Java Applet:appletview xxx.html (browser loading)

Chapter III Basic Types
1) Case sensitive emphasis on the main method when the public
2) Java does not have unsigned type
3) float must be followed by F mark, double can also be added D
4) Error overflow: positive Infinity negative Infinity NaN (non-digital 0/0=nan)
You can use Double.isnan (x) to determine if it is not a number
5) Char type conversion Unicode encoding easy to use not recommended
32→ spaces
48→0
65→a
97→a

6) constant final similar to const
7) Bitwise operation with or XOR (can be used to mask certain bits)
Shift Operation << >> (fast calculation or shielding bit)
>>> to fill the highest bit

8) Math Library contains mathematical methods and symbols

9) Casting Cast

Ten) String This is a predefined class
Intercept string substring (int index,int length)
Stitching +
Interception and stitching can dynamically change the length of a string

Do not compare the string size with the = = Number (C:STRCMP)
Because a string is a class, it will re-point to the new string when it is changed, and the original string will be freed

The string length is 0 and null is not matter, and null means that no object is associated with it
Character data type is a code unit that uses UTF-16 encoding to represent Unicode code points
Because some characters are different encoding, the character length is different
Length () Returns the code unit under UTF-16
/////////////////////////////////////////////////////
CharAt () returns the code point at the specified location, note that it is not a character!!
Codepointcount (0,str.length ()) returns the number of string char (code point)
/////////////////////////////////////////////////////

String APi
CompareTo (String Other)//sequential comparison
Startwith (String prefix)
EndsWith (String suffix)
SUBSTRING ()//several overloaded partitions
Equal (Object Other)
Equalignorecase (String Other)//ignoring case
IndexOf ()//a number of overloaded functions return the first matching position
LastindexOf () returns the last matching position
Length ();
toLowerCase () lowercase
toUpperCase () Uppercase
Trim () Remove the end-to-end blanks
Replace (charsequence oldstring,charsequence newstring)//String substitution, you can use Stringbuild or string to do charsequence

One) stringbuild (formerly StringBuffer) constructs a string if the string length is changed frequently
Stringbuild s = new Stringbuild ();
S.append (CH);
String ss = s.tostring ();

Stringbuild Api
Length ()
Append ()//several overloads
Appendcodepoint (ing CP) append code point and convert to code unit
Setcharat (int i,char c) The I code point is replaced by C
Insert (int pos, String/char) inserts
Delete (int start,int end) deletes the code unit Srat start to End-1
String toString () flushes the buffer contents into a string

12) Input/output
Output System.out.println ()
Enter import java.util.*//Ingest package
Scanner in = new Scanner (system.in);//system.in input stream
String name = In.nextline (); Console input one line
In.next ()
In.nextint ()/nextdouble ()

Using console processing is not as convenient as scanner. Console does not handle entering a single word or number of methods

Formatted output printf (similar to C:%S,%D.%F...%TC (Time output, C full time, other letters will have different meanings))
You can also use String.Format (similar to C:%S,%D.%F...%TC) to create a formatted string
(C # uses placeholders, index starting at 0, Java starting from 1, avoiding mash-up)

13) file input/output
Read file:
Use scanner to build a file object
Scanner in = new Scanner (Paths.get ("MyFile.txt"))//Use double backslash escape, then you can read a file using the Scanner general method
Write file:
PrintWriter out = new PrintWriter ("" MyFile.txt "")
You can then write a file using the System.out general method (println, print, printf)

Scanner (File f);
Printwrite (String filename);
Static path Get (String parhname)//Build a path based on the specified path name

///////////////////////
Control Flow Skip
///////////////////////

14) Large values are located in the Java.math library
Biginterger implementation of arbitrary precision integer Operations
BigDecimal realization of arbitrary precision floating-point number arithmetic

!!! Operation symbols cannot be overloaded and there is no way to customize operator overloading
(Build objects first, call methods, omit examples)
ValueOf () converts a normal value into a large value

15) The array new operator creates a space size because he is created into the heap
You cannot use the = array for simple assignment, which is to point two references to the same memory. One change, the other changes at the same time. At the same time, the original array memory will be discarded and recycled

When allocating space on a heap, use = Change the Reference object (or recreate the new object) while discarding the original object space

() for loop and for Each loop
17) array initialization and anonymous array (default: Value: 0,boolean:false,string:null)
18) Array Copy
When using = Copy, two variables point to the same piece of memory

To copy a value, use arrays. CopyOf (array name, new array length), returns a new array
Usually used to change the size of an array

Similar to C + + array pointer int* a = new int[100];(I say how much like!! )
Int[] A = new int[100];

19) command line parameter public static void main (string[] args);
20) Random number of array sort random number math.random () [0-1]
Arrays.sort ()//Quick-line

////////////////////////////////////////
Arrays Api
Static String toString (type[] a)
Static type CopyOf (type[] a,int length)
Static type CopyOf (type[] a,int start,int end)
static void sort (type[] a) quick-line
static int BinarySearch (type[] A,type v)
static int BinarySearch (type[] a,int start,int end,type v) Binary lookup method
static void Fill (type[] A,type v) fills the V value
Static Boolean equal (type[] a,type[] b)
////////////////////////////////////////
21) Two-dimensional array fast print two-dimensional array a
System.out.println (Arrays.deeptostring (a))
23) Jagged array Java multidimensional arrays are like arrays of arrays, arrays in arrays
for (int i = 0;i < a.length;i++) {
for (int j = 0; j< a[i].length; j + +) {
A[I][J] = 1;
}
}

Double [] [] D = new Double[10][6]
Equivalent to:
Double **d = new DOUBLE*[10];
for (int i = 0; i <; i++)
D[i] = new DOUBLE[6];

Java Learning Note (Core Java) 1-3

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.