2. When defining constants, the C language is defined as const and final in Java
3. When you declare member variables in Java, use static to define them.
4. The Boolean type in Java only includes true and false, but in C non-0 is true,0 false
5. In Java, Byte, short, int, long have their storage space of 1, 2, 4, 8 bytes respectively, and in C its char, short, int, long its storage space is 1, 2, 4, 4 bytes respectively. Where the long is an int long. There are unsign types in the C language, but not in Java.
The 6.long type must be represented in Java after the assignment, otherwise an error will occur. Or it will be an int type, but the int type will be less than long. There is no such rule in the C language.
The data types in 7.JAVA are sorted by capacity size (the size of the number represented), not by the amount of memory that is occupied.
8.int type data can be directly assigned to a byte type variable. The byte type variable is directly cut down to the length of the int type data, and the double type data cannot be directly assigned to the float type data because of the limit of the decimal point.
9. Logic and & Logic or | (Both values must be computed) short-circuit with && short-circuit or | | You can not calculate the second value
The judgment value after 10.switch should be of type int, which can be char,byte,short type in Java, because it can automatically rotate to int type data.
Chapter Two questions
1. The sum of the factorial of the output 1-10
2. Output 100 odd or less this and
3 loop output using while and Do-while 1-9
4. Output 1-100 or less 5 can be divisible by 3 of the number
5 prime numbers in the output 101-200
Chapter III Object-oriented
Note: Object-oriented thinking: 1 Those classes, those objects, 2. What are the properties and methods of these classes and objects 3 the relationship between classes and classes. The appropriate method should appear in the appropriate class.
Object and class relationships: classes can be seen as templates for a class of objects that can be seen as a concrete instance of the class.
Relationships between classes (objects)
Association relationship: The parameter of a method of a class is an object of another class. The relationship is not very close (weakest)
Inheritance relationship: xx is a kind of XX, you can consider using inheritance relationship encapsulation. (It is possible to create a spanning tree when designing, but it is also possible to inherit from several different classes.) C + + has multiple inheritance (it can be cumbersome to handle if there are member variables of the same name in the parent class), but Java has inherited multiple interfaces. Strong
Aggregation relationship: The relationship between the whole and the part (xx is part of XX). Subdivision can also be divided into aggregation (body and number of jobs) and the combination (inseparable) relationship. Strong
Implementing a relationship: When a subclass inherits a method from a parent class and implements its specific method by subclasses, this is called implementation.
Polymorphic relationships:
Static keyword:
The static method is not directly accessible to non-static variables and methods.
objects can be considered as attributes (member variables) and encapsulation of methods.
The difference between Java and C:
C is process-oriented programming, its properties and methods are separate, not aggregated, and Java is Object-oriented, the object encapsulates properties and methods together, and then reuse, that is, Java reusability (Methods and properties) is stronger, and process-oriented reuse is the method. In addition to reusability, scalability and maintenance and replacement are more convenient than process-oriented.
Java syntax
Reference: A variable type other than the base type (4 classes 8) is referred to as a reference type, and the initial value is null.
Overload: The method name is the same as the parameter type or the number of arguments, but the return value type does not constitute an overload.
Static methods cannot access non-static members, and static and other references should be placed in the data segment area
Packaging: When you package a class file in a DOS environment, enter JAR-CVF Test.jar *. * * to complete. When you copy it to someone else, the other person can use it and pack it up in the parent directory where the file needs to be packaged.
Access modifier: Private default (can only be accessed by a class within the same package) protected public (friend in C + +)
Modifier class inside the same bun class anywhere
Private YES
Default Yes Yes
Protected Yes Yes Yes
Public Yes Yes Yes Yes
Inherited:
A child can have only one father (extends), but he can have inherited (implement) multiple interfaces (interface). In general, children are bigger than their fathers.
Super inherits the method of the parent class.
How to construct in inheritance:
The construction method of its base class must be called during the subclass construction. Super. The parent class constructs the method, this. Subclass other constructor methods. If you call super, you must write the first line of the subclass construction method.
If the subclass does not display the constructor method that calls the parent class, the program automatically calls the parameterless constructor of its parent class, and then executes the child method. If the subclass does not display the constructor method that calls the parent class, and the parent class does not have parameterless constructor, the compilation will fail.
Overriding: The method name, argument list, return type of the inherited method must be the same, and its access should be greater than or equal to the method it inherits.
Hash coding: A unique representation of an object, and the location of that object can be found by hashing the code. map< key, Value >.
The Equals method definition for a Equals:object object is used when two variables refer to the same object and = =. When comparing two different objects but in other respects, you can override the Equals method to implement them.
Object transformation (can be either up or down and similar to a numeric type):
For example on the transition: Animal a=new Cat (); A.enjoy (); Under transformation: Animal a = new Cat (); Cat C = (cat) A; C.enjoy ();
Instanceof is followed by a class name to determine whether the object that the reference variable points to is a subclass of that class or class.
Note: The parent class reference points to the subclass object, and it sees only that the subclass inherits the methods and variables of the parent class and does not have access to the new additions to its child class objects. Extensibility can be generated in your code.
Polymorphic (Extensibility to the extreme)
Three conditions for using polymorphism: 1. To have inheritance 2 to have overrides 3 parent class references to child class objects
Dynamic binding: Who is actually called in the new one. Refers to the actual type of object being referenced during execution rather than during compilation, and calls its corresponding method according to who it actually calls. New is the method of who will call who.
The value of the final:final variable cannot be changed, the final method cannot be overridden, and the final class cannot be inherited
Abstract class: To implement abstract methods by subclasses. Interfaces are also a special kind of abstract class (the methods inside are abstract, and member variables are static final types)
Fourth Chapter exception Handling
Print exception occurs information location: E.printstacktrace () tracks the contents of the stack when an exception event occurs. GetMessage () Just prints the exception information.
Throwable includes error, Exception. Error is a system error, and exception is an exception that can be handled. Exception under the runtimeexception is can catch also can not catch, the remaining error must catch. However, if the throws errors in the program need to be caught.
Using a throws+ exception after the method name, inside the method is a throw+ exception
Finally, whether the catch or not catch the exception of the execution of the statement inside, so that the general removal of resources work.
Fifth Chapter Array
In C, you must specify the range of the array, which is the size, and its value is placed on the stack space, and Java cannot specify the size of the array, and its value is placed in the heap
Space.
Each array has a property of length table lengths, with. Length.
System.exit (0|-1);-1 is a non-normal exit, 0 is normal exit.
Here comes the problem of algorithms for Java sorting. Quick sort, bubble sort, hill sort, heap sort, select sort.
Sort:
Select sort: Sorts the values in the array by selection: Sort the values in the array from small to large, compare the first value to the subsequent value, position the exchange after finding the smallest value, and then proceed to the next loop until the end.
The modification makes the selection sort more efficient: Each loop finds the lowest value of the unsorted sequence and then swaps. (Do it Again)
Bubbling platoon: From back to forth, from bottom to top
Job: Bubble sort of shaping, date selection sort number three back 1500 people, the last person is the original position of the first
Bidirectional loopback Linked List
Search: Often built on the basis of an already sequenced order.
Binary Method Search
Two-dimensional arrays: In Java can not be defined in the static initialization of a few dimensions of the United States and several arrays, automatically assigned by Java, automatically defined.
In the array arraycopy, if you change the value in the array after the copy, the value of the copied array will also change.
Common classes:
String, StringBuffer difference: You can add strings directly after StringBuffer.
The String class represents an immutable sequence of characters.
StringBuffer represents a variable sequence of characters.
Cases:
String s1= "Hello";
String s2= "World";
S1+=s2;//helloworld Memory Analysis: A piece of memory in the data seg is Hello, and a piece of memory is world when the third sentence is executed, the value of the above two variables is copied to another memory range, and then the S1 points to the memory area.
The Append method of StringBuffer. Add to. Reverse reverse order
Round rounding of the math class is a long type
File class. Io.
Path separators separator In Windows backslashes, Linux forward slashes, or both with/forward slashes. A long type to store the last modified time.
Recursion: The key is to find the method, find the parameter and return the value.
Enumeration: Some types must take one of some values. Enum
7th Chapter Container (FOCUS) Set
Container: Loaded with a variety of other objects.
A diagram of a class, three points of knowledge six interfaces
Diagram: A diagram of a container. Util
<interface>
Collection (collection. External delivery method)
<interface> <interface> <interface>
Set (No Order
And can not be duplicated) List (sequential and repeatable equals) Map
HashSet LinkedList ArrayList HashMap
Container class objects need to compare objects for equality when calling remove, contains, and so on, which involves the Equals method of the object type and the Hashcode method to implement a custom object equality rule.
Note: Equal objects should have equal hash codes. Hash code is ideal for indexing.
Class: Java.util.Collections provides some static methods to implement some common algorithms based on the list container (such as sorting, binary lookup algorithms).
Knowledge Points: Enhanced for loop, generics, auto-pack/unpack
Interfaces: Collection, Iterator, Set, List, comparable, MAP
Iterator do traversal use, each container class that implements the collection interface has a iterator method that returns an object that implements the iterator interface. The iterator object becomes an iterator that facilitates the traversal of elements within the container. Traverse the collection in a unified way
The Remove method of the Iterator object is the only security method that removes the element during the iteration. That is to say, the iterator remove method can only be seen by itself, others can not.
Enhanced for loop for (int i:array)
Cons: Arrays (cannot easily access subscript values), collections (it is not easy to delete the contents of the collection compared to using iterator).
Set no order, no repetition.
Retain intersection
List is sequential and repeatable
The elements in the container all correspond to an integer ordinal indicating their position in the container, and the elements in the container can be accessed according to the sequence number.
The elements in the list container correspond to an integer ordinal indicating their position in the container, and the elements in the container can be accessed according to the ordinal, which is about the same as array, but the list can change its size.
Array read fast change slow linked that fast read slow hash between the two
ArrayList uses an array as the underlying storage space to provide an interface to the list externally.
LinkedList lists as the underlying storage space, providing external interfaces to the list
The Object set (int index,object element) returns the old value.
Map is used to store key-value pairs (red-black trees)
When comparing multiple elements, hashcode can be used to compare them, and the efficiency is higher. That is, overriding the Equals method must override the Hashcode method
The Put method returns the original value
Automatic packaging (automatically converting the underlying type to an object) and unpacking (automatically converting an object to the underlying type)
Generics are exactly what you're going to put in it. The same as the type in <>, you do not need to use casts when printing.
Generics can be used as long as the class is followed by <>, otherwise it cannot be used.
When you define a collection, you define the types of objects in the collection at the same time, and you can specify them at collection time as well as iterator, which increases the readability and stability of the program.
Eighth Io Stream (two bytes of one character)
By Data direction: input stream (byte stream: InputStream; character stream: Reader), output stream (byte stream: OutputStream, character stream: Writer).
By processing data units: byte stream, character stream
By Function: node flow (direct pipeline to the data source, you can read and write data from a specific data source (node) (such as: file, memory)), processing flow (nested pipeline, that is, through the processing of data to provide more powerful read and write function of the program).
Remember to close the data when you are reading it, and remember that the flush buffer data is written out to the destination and then closed
It has been experimentally verified that an shaping variable must be defined outside, and the read data will be stored in that variable and then written, and the file written will be in the same order as the read file.
Processing Flow:
1. Buffer stream: with buffer. On the corresponding node stream, the buffer function is provided to read and write data, and the efficiency of reading and writing is improved, and some new methods are added. Buffer
2. Conversion stream: is to convert the byte stream directly into a character stream for input or output, there is a ReadLine method can read or write a line, thereby increasing its speed. InputStreamReader
3. Data Flow
The DataInputStream is nested on the node stream of the InputStream type. It provides a way to access the machine-independent Java primitive type data (such as: int,double, etc.). Its construction method DataInputStream (InputStream in)
First Read first, FIFO, queue.
4.print Stream (only output stream, no input stream, print)
Both the PrintWriter and the Printreader are output streams, respectively, for characters and bytes, and do not throw exceptions. It is used for output of various data types and has auto flush function.
5.Object Stream
The serializable interface, which refers to serialization, a labeled interface, does not need to implement its methods.
ObjectOutputStream
Transient transparent modified member variables are not considered when serializing, that is, when writing on the hard disk is its default value.
The Externalizable interface is a sub-interface of the serializable. You can use its methods to control reading or writing.
Chapter 9th Threading
Thread: A different execution path in a program.
Process: a static concept. class file, the. exe file is a process. Process execution means that the main method inside the process starts running
You can create threads by creating a thread object, use the Run method to complete the operation, and start a thread using the start () method.
Thread start must call the start () method of the Thread class
There are two ways to create a new thread:
1. Implement the Runnable interface.
2. Define a subclass of thread and override its Run method
Try to inherit from the interface when you turn on the thread.
State Transitions for threads
Blocking state
| | Up
Blocking events that cause blocking
| (Down) |
Create-->start ()--Ready state <--> Schedule <--> Run state--Terminate
static method of Sleep:thread (throw exception). Use a flag to end a call to a child thread.
Jion: Merges the thread, executes the child thread, and then proceeds to the original thread.
Yield () yields the CPU, and the current thread enters the ready queue for scheduling.
The thread priority range is from 1-10, and the default value is 5
Thread synchronization
Synchronized (this) {} or public synchronized void Add (String name) {} is the current object that is locked during the execution of this method
One way to resolve deadlocks: to reduce the granularity of synchronization, which is to lock the current entire object without locking the child objects inside.
Note: A thread accesses a method with a lock, locks the current object, and another thread cannot execute the lock method in the object, but can access the method without locking in the object.
When accessing a resource in a database in a program, it is generally locked on the "modified method" and not locked on the Read method.
The tenth Chapter Network programming Technology + Management + communication
A good book on network Programming "TCP/IP detailed"
TCP: protocol specifically designed to provide reliable, end-to-end byte-stream communication on unreliable Internet, is a connection-oriented protocol. A TCP connection is a byte stream, not a message flow. (TCP three-time handshake)
UDP: Provides a way for an application to send an encapsulated raw IP datagram, and is not a reliable connection when it is sent without establishing a connection.
The Socket is used to implement client----server connection java.net
Two Java applications realize data exchange through a two-way network communication connection, one end of this bidirectional link is called a socket.
The two class sockets and ServerSocket (TCP server-side connections) defined in the java.net package are used to implement both client and server sides of the two-way connection. It is the implementation of TCP, only TCP has c-s, UDP does not.
The addressing information required to establish the connection is the IP address and port number of the remote computer (65,536 port numbers, or 65,536 applications, used to distinguish different applications on the same machine, with more than 1024)
Port number can be divided into UDP and TCP
When using eclipse testing, you need to use two eclipse to test, if DOS then need to open two windows, first open the server and then open the client.
UDP delivers fast, but unreliable, TCP delivery information is slow but reliable
UDP Bytearrayoutputstream
Chapter 11 GUI Programming (Database, HTML, CSS, java Script, JSP, Servelet, EE, Spring, structs, Hibernet, EJB)
AWT (Abstract Window Toolkit) Programming for Java application GUI (graphics user interface graphical UI)
Java Graphics compare the old development package, javax.swing This is a newer window development package (the AWT group of important pictures)
Self-Study Java summary