1. Quick start of Java

Source: Internet
Author: User

First Lesson Java Basics
1. Setting up the environment on Ubuntu (we recommend using the VMware image file we provide)
If you want to install Ubuntu yourself, refer to the < Vedon android Video user manual .pdf>
Ubuntu 12.04.5 This is a long-supported version
Hard disk space reserved at least 80G
A. Root partition: 20G, from which 6G is used as swap
B. Work Partition: 60G
C. Memory: 4G

Installing the Java Development environment
sudo apt-get update
sudo apt-get install OPENJDK-7-JDK
sudo apt-get install Openjdk-7-jre

2.1th Java Program (vs. C)

Method of compiling: Javac Hello.java

How to run: Java Hello

3. Java Data type
Basic data type: Boolean, Byte, char (2 bytes), short, int, long, float, double
Reference data type: Array, class object, interface (the reference data type refers to the data that the variable points to in the heap, such as: int p2[] = {1,2,4}, the data 1,2,4 in the heap, p2 on the stack, its value is the address of the heap), the reference and the pointer in the C language are comparable

The reference data type is allocated using new, does not need to be freed, and the variable is set to NULL

Stack memory, heap memory
Data type conversions (automatic conversions (which occur if data is not lost after conversion), cast)

Short s=1;s=s+1 error, because for the byte,short operation, in order to guarantee the precision, will be automatically converted to int, it can not be directly assigned to the short type, instead of s= (short) (s+1)

Sourceinsight files are compiled in ASCII code, the Java compiler is to parse characters with UTF-8, so if there is a character in the file, there will be unresolved situation, so need to use UE to convert the file to UTF-8 format

4. Statement: Exactly like C

5. Methods (Functions)

6. Method overloading, parameter passing

Overloading refers to the same function name, parameter type or number of arguments, the difference between the return value type is not overloaded

int p[] = new Int[1];p [0]=123;fun2 (P); the value of p[0] changes at this time (public static void Fun2 (int[] p) {p[0]=100})

Lesson two object-oriented programming
1. Introduction of Classes
C language is process-oriented
A problem: Write a program, output Zhang San, Li 42 person's name

Define a Class (a), instantiate the variable (a a), and a is an object

Constructor format: public class name (type parameter ...) )//It has no return value and can have multiple construction methods

{

Statement

}

The static decorated class method belongs to the class and is called by the class name. method.

In a class, the construction block is surrounded by a curly brace "{}", and code that is expanded by building blocks is called before any constructors are called to execute

The curly brace "{}" before the addition of a static code block, which instantiates the first object before executing, and executes only once, after the construction block and construction method is executed, and then the instantiation will not execute the static code block again.

The main function in the class is modified by static to allow the virtual machine to execute the main function without instantiating the object

2. Encapsulation

Private modified variables and methods can only be accessed by the internal methods of the class and cannot be accessed externally

Private this class is accessible; default this package is accessible; protected this package, other packages, etc. accessible; public all accessible

3. Inheritance

When instantiating a subclass object, the constructor of the parent class is called, and then the constructor of the subclass is called (such as no super in the fruit class constructor, and a super () is added by default in the first row of the constructor of the subclass); The default parameterless constructor that invokes the parent class);

If the parent class has a constructor that is "class name (Parameter 1)", then the first sentence in the subclass constructor is prefixed with "super (Parameter 1)", and the parent class's constructor method "class name (Parameter 1)" is invoked when an object is instantiated.

The final class cannot have subclasses; The final method cannot be overwritten; The final variable becomes constant and cannot be modified

Inheritance restrictions: 1, the parent class's private property and methods cannot be inherited, corresponding to the private property, if there is a public method to obtain a private property, the subclass can call the method

2, sub-class overwrite the method can not narrow the permissions, such as the public method a parent class, the subclass can only be covered as public;

The class preceded by class is abstract, and its class has an abstract method in addition to its attributes, ordinary methods (), and the method of abstracting the access and return values of the method), the abstract method needs only declaration and does not need to be implemented;

Abstract classes cannot instantiate objects, and subclasses must overwrite all abstract methods;

Interface: Interface interface name {global constant; abstract method}

Interfaces are similar to abstract classes, and their template functions, subclasses can inherit multiple interfaces, subclasses must overwrite all abstract methods

(subclasses can inherit only one parent class extends)

Class A extends D implements B,c{}//b and C are interfaces, D is the general class fire abstract class

4. Polymorphism

5. Exceptions
Reference article:
In-depth understanding of Java exception handling mechanisms
http://blog.csdn.net/hguisu/article/details/6155636


6. Packages and Permissions
Javac A.java//will be generated in the current directory A.class
Can you store these class files in a different directory?

JAR-CVF My.jar A//create the package A as a compressed file My.jar

Export Classpath=.:my.jar

7. Inner class

Third Lesson JNI (Java Native Interface)
1. Java calls C
Linux is written in C language, you can write an app to simply call Open,read,write to access the driver;
Android is written in Java, how does Java access C function?

Jni.pdf P117

Introduction to Android JNI knowledge
http://blog.csdn.net/linweig/article/details/5417319

Android JNI (implement your own jni_onload function)
http://jjf19850615.blog.163.com/blog/static/356881472013342153912/


View "jni field descriptors" (JNI fields Descriptor)
Javap-s-P Var.class
Parameter resolution of Jninativemethod
http://carywei.iteye.com/blog/1075647
Http://cs.fit.edu/~ryan/java/language/jni.html
http://blog.csdn.net/conowen/article/details/7524744


2. C Call Java
Jni.pdf P97

http://blog.csdn.net/lhzjj/article/details/26470999

4 Steps:
A. Creating a virtual machine
B. Get class
C. Instantiating the object: Get the constructor method (method named "<init>"), construct the parameter, call the method
D. Call method: Also divided into the acquisition method, construct the parameters, call the method

Read/Set properties in class:
A. Obtaining a property ID
B. Read/Set

Lesson Four Java Advanced applications
1. Generics (generics)

2. Reflection (Reflect)

1. Quick start of Java

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.