Java Basic string theory

Source: Internet
Author: User


Today took some time to read the data to review the basics of Java, and now tidy up the notes in order to consolidate.

Java main application areas

–Enterprise-Class applications: Mainly refers to the complex large enterprise software system, various types of Web sites. Java's security mechanism and its cross-platform advantages make it widely used in the field of distributed system development. Application areas include finance, telecommunications, transportation, e-commerce and so on.
–Android Platform App: Android applications are written in the Java language. The level of Android development depends largely on whether the core capabilities of the Java language are solid.
–Mobile Domain Applications, mainly in the field of consumption and embedded, refers to the application of a variety of small devices, including mobile phones, PDAs, set-top boxes, automotive communications equipment.

The origin and characteristics of the Java language

Origin:When Java's father Jgosling and his team developed "Green" projects, they found that C lacked a garbage collection system, portable security, distributed programming, and multithreading capabilities. Finally, they want a platform that is easily ported to a variety of devices.

Features:Java inherits many components from the C and C + + languages, and can even consider Java as a product of the development and derivation of C language. For example, the Java language variable declaration, operator form, parameter transfer, flow control and other aspects and C language, C + + language is exactly the same. So the Java language is easy to learn. The syntax of the Java language is close to the C and C + + languages, making it easy for most programmers to learn and use Java.

But at the same time, Java is a purely object-oriented programming language, which inherits the core of C + + language object-oriented technology. Java discards features such as the C language prone to error pointers (superseded by references), operator overloading (operator overloading), multiple inheritance (superseded by interfaces), and adds the garbage collector function to reclaim memory space occupied by objects that are no longer referenced.

JDK1.5 introduces generic programming (Generic programming), type-safe enumeration, variable-length parameters, and automatic loading/unpacking.

The Java language is mandatory for object-oriented. The Java language provides primitives such as classes, interfaces, and inheritance, and for simplicity, only single inheritance between classes is supported, but multiple inheritance between interfaces is supported, and the implementation mechanism between classes and interfaces is supported (the keyword is implements).

The Java language is distributed. The Java language supports the development of Internet applications and has a network application programming interface (Java net) in the basic Java application programming interface, which provides a class library for network application programming, including URLs, URLConnection, sockets, ServerSocket and so on. The RMI (remote method Activation) Mechanism of Java is also an important tool for developing distributed applications.

The Java language is robust. Java's strong typing mechanism, exception handling, and garbage collection are important guarantees of Java program robustness. Discarding pointers is a wise choice for Java.

The Java language is secure. Java is typically used in a network environment, and Java provides a security mechanism to prevent malicious code from attacking. Such as: Security guard mechanism (class ClassLoader), such as assigning different namespaces to prevent the substitution of local class, byte code check.

The Java language is interpreted and cross-platform. Java programs (files that are suffixed with Java) are compiled into an architecture-neutral bytecode format (a file with a suffix of Class) on the Java platform and can then be run in an interpreter for any system that implements the Java platform.

The Java language is native to multithreaded support. In the Java language, a thread is a special object that must be created by the thread class or its child (grandchild) class.

Java Basic module diagram


Object oriented

object-oriented and process -oriented



Learn about object-oriented contentthree main lines:

1. Members of Java classes and classes;
2. Three main characteristics of object-oriented;
3. Other keywords.

1. Members of Java classes and classes

The focus of object-oriented programming is the design of classes. In Java, classes are used to describe things, and classes consist mainly of attributes, methods (behaviors), and concepts related to properties and methods can be easily understood as:
Field = attribute = member variable, method = (member) methods = function

The basic composition of a class member is as follows:

Write a picture description here"Title=" ">

This can also be the case:



With members of classes and classes, how do you use them? By instantiating a Java class, you create an object of the class. In general development,

First go to the object with the desired function to use
? If the object does not exist, create an object with the required functionality
? This simplifies development and improves reuse

Class and object relationships:



Use members of classes and classes through object instances:

? Use the new + constructor to create an object;
Access object members (including properties and methods) by using the object name, Object member.
? If you create multiple objects of a class, each object has its own set of replicas for the properties defined in the class and does not interfere with each other.
? In a class: A method in a class can directly access a member variable or other method in a class. (Exception: Static method accesses non-static, compilation does not pass.) )

2. Three main features of object-oriented

? package (Encapsulation)
Inheritance (inheritance)
? polymorphism (polymorphism)

Package(encapsulation)

The direct operation of a consumer on a property defined within a class (a member variable of an object) can result in errors, confusion, or security problems with the data, such as:



In Java, by declaring the data private (private), the public method is provided: GetXxx () and setxxx () implement the operation of the property for the following purposes:

Hide implementation details in a class that do not need to be provided externally;
The user can only access the data by a pre-customized method, it is convenient to add the control logic and restrict the unreasonable operation of the attribute;
Easy to modify, enhance the maintainability of the Code;

 Public classanimal{//attribute legs is defined as private and can only be accessed within the animal class   Private intLegs//define Method Eat () and move ()    Public void Setlegs(inti) {if(I! =0&& I! =2&& I! =4) {System. out. println ("Wrong number of legs!");return;   } legs=i; } Public int Getlegs(){returnLegs }} Public classzoo{ Public Static void Main(string[] args) {Animal xb=NewAnimal (); Xb.setlegs (4);//xb.setlegs ( -1000);xb.legs=- +;//IllegalSystem. out. println (Xb.getlegs ()); }}

Four types of access modifiers:



Inheritance (inheritance)

When the same properties and behaviors exist in multiple classes, the content is extracted into a single class, so that multiple classes do not need to define these properties and behaviors, as long as they inherit that class. Many of the classes here are called subclasses, and a separate class is called a parent class (a base class or a superclass). Can be understood as: "Subclass is a parent class".



Class inheritance Syntax rules: Class subclass extends superclass{}









polymorphic (polymorphism)

Polymorphism, the most important concept in object-oriented, has two kinds of embodiment in Java:

1. Overloading of methods (overload) and overrides (overwrite).
2. Object polymorphism: A reference to the parent class is directed to the subclass object entity (which can be applied directly on abstract classes and interfaces)







3. Other keywords

? This
? super
? static
? final
? abstract
? interface

Java Basic thread

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.