1. Java Basics

Source: Internet
Author: User
Tags float double

Three technical architectures for Java:

1, the Java EE: the Development enterprise Environment application, mainly for the Web program development.

2, J2SE: The development of desktop applications, is the basis of the other two.

3, J2ME: The development of electronic consumer products and embedded equipment.

Jdk:java Development Kit, installation-time path do not have Chinese and white space.

Jre:java the operating environment.

Configure environment variables: Let the Java jdk\bin directory of tools, can be run in any directory.

New java_home=% Installation Path%\JAVA\JDK

Add%java_home%\bin in Path again, notice that there is a number on the front;

Javac: Compile, when executing Javac, will start the Java compiler program, compile the. java file with the specified extension, and generate a bytecode file that the JVM can recognize, that is, the class file (Java running program).

Java: Run, start the JVM. Load the class library that is required by the runtime and execute on the class file.

Identifiers: Numbers, letters, underscores, $, cannot start with a number.

Constant: The amount that will not change during the run.

Variable: storage space in memory, used to store constants.

Data type:

Basic data type: byte short int long float double char Boolean

Reference data types: arrays, classes, interfaces

%: modulo (take rest), any number%2 is not 0 is 1, can be used for switching operations.

i++: First use and then minus.

>>>: Unsigned right shift.

^: XOR, different sides are true.

>>: Shift Right, divided by 2

(conditional expression)? Expression 1: Expression 2;

1 Switch (expression) {2      Case value 1: 3     execute the statement; 4      Break ; 5     default : 6     execute the statement; 7      Break ;     8 }

Choose the type of four kinds: byte,short,int, char. The enumeration is added later.

While and for: can be interchanged, if you define a variable to control the number of cycles with for, an infinite loop with while (true).

Break: End loop for the for switch

Continue: End this loop and go to the next loop.


Overloading: In the same class, the function name is the same, the parameter type or parameter list is different, regardless of the return value.

Array: Starting with 0, numbering the elements

int[] arr = new INT[4];

int[] arr = new int[]{1,2,3,4};

Exception: Array out of bounds, null pointer exception.

Direct sort:

  Public Static voidSelectsort (int[] arr) {     for(intx = 0; x < arr.length-1; X + +) {        //Why is the initialization value of y x+1? Because every comparison is marked with an X-angle.element is compared with the next element.          for(inty = x + 1; Y < arr.length; y++) {            if(Arr[x] >Arr[y]) {                inttemp =Arr[x]; ARR[X]=Arr[y]; Arr[y]=temp; }        }    }}

Bubble Sort:

1  Public Static voidBubblesort (int[] arr) {2 3      for(intx = 0; x < arr.length-1; X + +) {4         //-X: Let each participating comparison of the meta minus,-1: Avoid the corner mark out of bounds. 5          for(inty = 0; Y < arr.length-x-1; y++) {6             if(Arr[y] > arr[y + 1]) {7                 inttemp =Arr[y];8Arr[y] = arr[y + 1];9Arr[y + 1] =temp;Ten             } One         } A     } -}

Dichotomy (binary search)

1   Public Static intHalfseach (int[] arr,intkey) {2 3     intmin, Mid, Max;4Min = 0;5max = Arr.length-1;6Mid = (max + min)/2;7 8      while(Arr[mid]! =key) {9         if(Key >Arr[mid])TenMin = mid + 1; One         Else if(Key <Arr[mid]) Amax = Mid-1; -  -         if(Min >max) the             return-1; -  -Mid = (max + min)/2; -     } +     returnmid; -}

Array rollover
 1  public  static  void  reversearray (int  [] arr) { 2  for  (int  start = 0, end = arr.length-1; Start < end; start++, End-- 3  int  temp = Arr[start];  4  Arr[start] = Arr[end];  5  arr[end] = temp;  6  7  }  8 } 

Register, local method area, method area, heap, stack

Heap: Local variables (variables in functions, arguments on functions, variables in statements)

Stacks: Arrays and objects

1. Java Basics

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.