2020 On the Getting Started with Java

Learn how Java technology for many beginners, is a key issue. If you can get a good guide in addition to their own efforts can be more effective. For the novice how to upgrade their Java technology?

One: On the java application and
to learn java unwittingly also been three years

I do not know why the matter from java and now a project manager j2ee small

Although it can not master this road, probably considered a little weight it

Every time the Internet bubble bbs visiting the forum, no less relevant to the java layout

The overall feeling for beginners, less expert, less proficient

Because of our higher education system obsolete materials, plus java own development but a decade or so

There is also a very important reason is that java the language more suitable for commercial applications

So in most Universities, Dr. teachers understand this language, even undergraduates and more than

In this environment, many people feel a loss of java, overwhelmed, do not know what to do java

Even know java very useful, I do not know where to start

So there is this statement difficult java entry

ok, then we chatted in the end what to do from java

Let me talk about what is java

java is an object-oriented language, object-oriented real, functions and variables in any class (class) encapsulated

As for what the object is what is class, I do not nonsense

An explanation of any of these two concepts inside an object-oriented language textbooks have

Know what is the java, it will naturally be interested to java can do

Java before saying what to do, start with the advantages of java as a true object-oriented language

First first, since it is a true object-oriented, it would have to do a thorough package

This is the biggest difference between java and c ++, java source code and all of the compiled class files are present in the form of

No java class called external definition, all of the functions (methods) and variables (attributes) must be defined within the class

This class does not appear to be a cut here, a case where a, c ++ can be, is not it?

Doing so makes the whole process very clear structure, clear

Secondly second, most people cheered the pointer is completely shielded, while the introduction of garbage collection mechanism

Any written c / c ++ code, people will hate memory management

Because it allows us not to focus on the things we care about

The need to consider a few things inside the computer as a software engineer

I do not think a person is willing to put a lot of time spent on memory management, after all, we are not electronic engineers

At this java advantage is manifested, it is completely shielded memory management

That is, if you write a program using java, write out a program memory overhead on any, you are not subject to control

At first glance, it seems that you have been bound, but in fact is not the case

Because although your program can not manage memory, reducing certain speed

But your program will be very, very safe, because you can not call a null pointer

And unlike the previous time to write c as all day because of a null pointer and fear

Of course, if you understand this line, you will find java fact, there is no guarantee programs do not call empty pointer

But it will avoid calling a null pointer to the maximum extent

This has been very good, safe, and this is the most prominent advantages of java

Third, cross-platform virtual machine, which is the greatest feature of java, cross-platform

Perhaps all we know windows, but not everyone knows unix

And java, as many people do not know what to do with the operating system unix this

I do not want to say unix application, this is not a major, but I have to say, most of the minicomputer

Workstations, operating systems are run on unix family, such as linux / solaris

unix windows than have one of the most significant features, stability, this good than Cisco and Huawei

Cisco's slow but steady the machine, the machine Huawei's fast but unstable, as a server for the end

To the unix server side of the market is still very

And it is important windows insecurity in ms publicity I think everyone seldom see the word security

Because the windows operating system for a pc user, pc crashes on the crash slightly, big deal to restart

95 most frequently plague that came out of the blue screen, on the server-side because this ms not have its own chip

So do system bloated ah. Pulling away, then compile java can be done on windows

Then run on unix, which is c / c ++ can not do

Here then, java can do clear up

Just I said, java program has a feature is safe

This is a must for your security system, the system after running java program will be particularly stable

But also cross-platform, then obviously, java mainly used in all platforms except windows operating system

Such as mobile phones, server

Think about it, if you write a program to run on the phone, and the phone number of models use the windows?

Even if there is, that if you use c / c ++, is not to write a program for each of these handsets do?

Exhausted, and that cross-platform java do not, do compile once, run at any time

Similarly, in the server side, if I want to give a web portal sites, such as sina

Write an application, pc's performance certainly can not satisfy such a large number of concurrent sina site requirements

Then it needs to buy a server, the server market is not ms, and windows not safe

So in all likelihood will buy a sun / ibm machines or hp, but no matter who the machine

It installed the operating system will not be the windows, because windows too unsafe, and support for multi-core bad

This free again, so if you want to write a program to run on such machines

Are we on the development of this machine to do it? Of course not, generally programmers are used in pc, windows

So how to do? Write a program, and then get up the server compiler, debugging go?

After certainly can not, so we wanted to find a language, compiled generator

On the pc debug, and then transplanted directly into the server up, so this time, we will not hesitate to choose java

Because it is cross-platform and security, java is always the first choice

Shortcoming ok, said the following of java

A slow, this is actually a misunderstanding, which is like a goto statement as

java also abandoned the pointer, although seemingly slow, but in this era of 2023 will be able to double the performance of the hardware

Speed ​​is not the issue we are concerned about it, and use it for enterprise-class

Nothing is more important than security and stability, in other words, we can endure slow, but can not stand crashes and blue screens

And the more large-scale applications, such slow disadvantage reflect the more vague

Because the case when the system project bigger and bigger, do not have any link that may affect the overall

Security is especially important, and just as the goto statement

This proposition will give over the pursuit of speed error correction system development and maintenance as well as irreparable or even inevitable losses

The memory to the computer to manage it, this is worth the price

We do not pc games, no need to put the memory of the little consumption when Qindie

Two ugly, is a misunderstanding, a lot of people even come up with java swing control interface is drawn

Oh, in fact, not java can not draw well look, IDEA is written in java IDE, pretty

But why is it ugly, it is because the swing control unix itself a product of the times, swing control close to the unix interface

Foreigners see unix interface is actually quite pleasing to the eye, they just grew up eating rice unix

The unix is ​​100 meals to eat, unlike ms so mercenary, so less of the Chinese people-friendly

Plus our country and no company is doing the operating system, so it looks is not very pleasing to the eye

In fact, played the people know unix, unix support has been very good for Chinese

C I did not think that others supplement

Two: Java based learning summary
object-oriented three characteristics

Inheritance: general class can only single inheritance, multiple inheritance inner classes, interfaces can be multiple inheritance

Package: Access Control public> protected> Package> private internal class is an encapsulation

Polymorphism: polymorphism compile-time, reflected in the upward transition and the downward transition, which is determined by the reference method call type (static assignment).

Runtime polymorphism, embodied in multiple ways to implement the function of the same name (dynamic dispatch) by different parameters.

Basic data types

1 digit basic types, automatic packing, constant pool

2, for example, a byte is 8 1byte i.e., the digital representation may be -128 to 127, because there is a 0, a combined total of 256, which is the eighth power 2.

32-bit and 64-bit machine int 4 bytes i.e. 32, char is one byte is eight, float 4 bytes, double is 8 bytes, long 8 bytes.

3 basic data types of packaging used only in the constant pool numbers -128 to 127 range, will automatically packing unpacking, the numerical ranges of the remaining packaging new instance will

String and packaging

1 String type is final, the memory address can not be changed after the heap space.

2 is a bottom modified final char [] array of the memory address, the same array is immutable.

But actually can be performed by modifying char [n] = 'a' modified without changing the memory value of a String instance, in jdk but the user can not directly char [], there is no way that the array can be operated.

So immutable fact of type String theory is immutable. So in the future we assign String object, if it = "abc", it was only to change the reference point, in fact, does not change the original object.

3 StringBuffer and StringBuilder underlying variable char [] array, inherited from the parent class AbstractStringBuilder various members and methods, in fact, the operations are completed by the method of the parent class.

final keyword

1 final modification of the basic data types guaranteed immutable

2 final modifications to ensure that references cited can not point to other objects, otherwise it will error.

3 final modified class, the class instance of the address space assigned immutable, all subclasses can override inherited methods. Therefore cglib dynamic agents, do not function as a final modification of the class of agents, as cglib To proxied class as a parent class, then generate bytecode.

final modification method, a subclass can override this method.

Abstract classes and interfaces

1 can abstract class method implementation. An abstract class can have non-final member variables. Abstract methods modified to use abstract. An abstract class can have a constructor, but only instantiated by subclasses.

2 interface can add multiple interface extends multiple inheritance. Interface has only public final member variable. Interface has only abstract methods, a method can not have a body, an interface can not be instantiated, but can be used as a reference type.

Code block and loading sequence

Suppose the first class is instantiated. Then the following order of the static loading is always better than non-static priority order from morning to night is: a static block of code sequence and subsequently static member variable determined by the previous code location. 2 code blocks and sequences of member variables can be determined finally 3 constructor method call the constructor code location

Package, internal type, the external type

1 Java projects generally start from the src directory has com ... A.java such a directory structure. This is the package structure. So the general structure is compiled with exactly the same package structure, such structure ensures can find the right class reference packet access refers to the same class under the package visible import.

import generally add the full path, and use all the class files contain only the current directory * when, not including subdirectories.

2 external public and default classes only two modifications, either globally accessible or accessible within the package.

3 inner class can have full access because its concept is a member variable, so the same access permissions with the general member variables.

Non-static inner class is a class member variable external only related with the instance of the outer class.

Static inner class is a class independent external class exists, regardless of the external class instance, can be internal-based direct access by an external type class Class.

abnormal

The top 1 abnormal system Throwable class is a subclass of Error and Exception Exception there are subclass RuntimeException and there may be other specific abnormalities.

2 Error System Error jvm is completely unable to deal with, can only terminate.

Refers to the abnormal run-time compiler is correct but the runtime error exception, such as an array bounds exception, generally caused by human error, such anomalies do not try catch, but requires the programmer to check.

Abnormalities can usually jvm can not deal with some unusual, but it often happens, such as Ioexception, Sqlexception, is caused by abnormal external realization.

Abnormal process over three threads are independent of each other. Sub-modules generally require large modules of abnormal external re-packaged as an exception is thrown again, or only see the outermost exception information, it is difficult to debug.

Logging framework is the best helper exception reports, log4j, slf4j, the indispensable at work.

Generics

1 Java generics is a pseudo-generics, only take effect at compile time, runtime generics automatically erased, replaced by the generic type is actually passed.

With the generic class classA {

}

2 represents such a form, which the member variables and methods can be used to indicate the type T. It is similar generic interface, but can choose to continue or the actual type of injection to use generic generic interface implemented when the generic class.

3 can be built generic generic method such as void go ();

Generics can use the? Wildcard can accept any type of generalization Object

May be limiting in this way the use of upper and lower boundaries.

Class and class Object class

1 Java reflection is based Class class that encapsulates all other types of information classes, each class and generates a Class <class name> instance heap after each class loader configured to instantiate that class.

2 Java can be obtained through a variety of ways Class types, such as A.class, new A (). GetClass () method and Class.forName ( "com.?.?. A") method.

3 Object is the parent of all classes, with some of their own private methods, as well as nine methods inherited all the classes.

Almost anyone know the discussion and Class Object type who should loader to load because each class must inherit Object, but it must first be loaded into the heap, in fact, this issue will be solved when the JVM initialization is not necessary think.

javac java 和

1 javac compiler java file a basic commands, parameters may be accomplished by a variety of different configurations, such as introducing other classes, designated compiled paths.

2 is the implementation of a java file java basic commands, parameters may be performed by a java program in a different manner or a jar package.

3 javap is a class file decompiler, you can get results decompile class file, or even every step of the code jvm execution of the program implementation.

reflection

1 Java reflection packet encapsulation type of reflection provided Class, Method, field, constructor1 other information.

2 can easily obtain various kinds of information by which a class can be instantiated and api, other method calls.

private class parameters can be obtained by forcibly setaccessible method.

3 can be described reflection effect profound, the bytecode generated JDK dynamic proxy proxy class, the first class definition into a class by defineclass, then loaded onto class will jvm with class.for (name), then we have by, A.class.GetMethod () gets its way then invoke its method call, when you call this method, the original method invocation will actually go through the proxy class references.

Enum class

1 Enumeration Enum class inheritance and each instance of the enumeration class is unique.

2 may be used for enumeration class encapsulates a set of constants, the value taken from the set of constants, such as seven days a week, twelve months of the year.

3 enumeration class underlying implementation is actually syntactic sugar, each instance of the class can be converted into the interior. And using static code block is initialized, while ensuring that the internal member variable immutable.

Serialization

1 sequence of the interface class to achieve serializable

transient modifier can guarantee that a member variable is not serialized

readObject and writing and reading to achieve writeOject examples.

2 In fact, some classes will have an array variable is set to an array of transient modification, so do not serialize the entire array, but to use specialized methods will have an array of serialized data range, to save space.

Dynamic Proxy

1 jdk own proxy class may be a dynamic proxy interface has been achieved.

2 cglib agent may proxy a normal class.

The basic principle to achieve dynamic proxy 3 are dynamically generated bytecode bytecode frame, and after the class is loaded with defineclass, obtain an instance of the proxy class.

Agent typically need to implement a processor for processing the pre-operation and post proxy class operations. In JDK dynamic proxy, this class is called invocationHandler.

4 JDK dynamic proxy proxy class methods are acquired first, and only acquires method declared in the interface, the generated proxy class bytecode, the first of this class definition into a class by defineclass, and then loaded into the JVM class, then we can, A.class.GetMethod () gets its way then invoke its method call, when you call this method, the original method invocation will actually go through the proxy class references.

5 For cglib dynamic agent, generally will be set to the proxy class the parent class of the proxy class, then acquires all non-final methods proxy class bytecode generated by the proxy class bytecode asm frame, the proxy class amazing, he will retain the original method and the proxy method, save in the form of an array of methods.

Dynamic proxies cglib the need to implement a enhancer and a interceptor, we need to configure the proxy content in the interceptor. If there is no interceptor configuration, the proxy class calls the proxy class is their own way, if you have configured interceptor, the proxy class modified method is used.

Multithreading

Here to speak juc bag multi-threaded class. juc content will explain the topic in the Java concurrency.

1 thread can be achieved through inheritance Thread class and implement Runable interfaces can also use the thread pool. callable can be achieved with future data acquisition thread.

2 Java threads in there are seven states, new runable running blocked waiting timewaiting terminate

thread is blocked waiting for the other thread releases the lock. After the thread is waiting wait wait indefinitely for the other threads using notify wake timewating limited time waiting to be awakened, it could be fixed sleep time.

3 Thread the join is an instance method, such a.join (b), it indicates a thread to wait until completion b thread running operation.

4 o.wait method will hold the thread releases the lock of the object o and enters the blocked state, notify the thread is holding a lock object o notify other threads waiting for the lock to acquire the lock. notify method does not release the lock. Note that both methods can only be used in synchronized synchronized method or synchronized block inside.

mutex lock 5 synchronized method using the underlying system calls, large overhead, jvm maintains a queue for each lock object, so that threads waiting for the lock object is waiting in this queue. When the thread gets the lock when you make less than a thread is blocked, while other tests after a thread will notify any notice, so unfair when the lock is locked.

6 Thread.sleep (), Thread.interrupt () method and other methods are based, showing the operation of the method of the current thread calls.

Two consecutive start a thread instance will throw an exception, this is because it will set the identity after the thread start, start again if it is determined that error.

IO flow

1 IO streams Java is the more important piece, mainly in Java byte stream, a character stream files. Wherein the file is opened by way of the flow, read and write.

2 IO stream many interfaces use the decorator pattern, i.e. by passing the original type constructor decorative manner, the original enhancement type, in order to obtain the image with the byte stream buffer, or encapsulated into a stream of bytes character stream, and so on, which needs to be noted that the coding problem, which prints out the results may be garbled, oh.

3 IO stream is closely related to network programming, after a socket access, we can get its input and output streams, to obtain the content of a TCP packet, and the content can be written into the data packet, because the stream is in accordance with the TCP protocol transmission manner, these data will actually sub TCP processing and error checking through the timeout retransmission, sliding window protocol, etc., to ensure the efficient and reliable transmission of TCP packets.

network programming

IO stream content to undertake

1 IO closely related to programming the network flow, after a socket access, we can get its input and output streams, to obtain the content of a TCP packet, and the content can be written into the data packet, because the stream is in accordance with the TCP protocol transmission manner, these data will actually sub TCP processing and error checking through the timeout retransmission, sliding window protocol, etc., to ensure the efficient and reliable transmission of TCP packets.

2 except that acquires TCP socket packet, the UDP may be used to encapsulate the DatagramPacket UDP packet, because the size of the UDP packets is determined, so instead of using a flow mode processing, but requires that the length is predefined, the source information and destination ports and so on.

3 In order to facilitate network programming, Java provides api types to support a range of network programming, such as URL class, InetAddress class and so on.

Subsequent articles will bring NIO relevant content, so stay tuned.

Java8

The default method interface, the interface can finally have a way to achieve, you can use annotations to identify the default method.

2 lambda expression to achieve a functional programming, you can declare a function interface via annotations, the interface can have only one method will be called upon to use this method is the lambda expression interface.

3 Option class implements a non-null test

4 api various updates, including CHM, the realization HashMap

5 Stream flow concept, to achieve a set of classes streaming access may be calculated based on this map and reduce the use of parallel.

Three: Data / learning site

JavaFamily: Internet Gouqietousheng by one man maintenance GitHub

CodeGym: An online Java programming course, 80% of the content is to practice, suitable for beginners to know nothing about.

Wibit Online Java Courses: a very interesting site to learn programming, a variety of vivid animated images can make people forget the boring learning. Online video learning, ideal for zero-based.

stanford CS106A: Programming Methodology: Stanford Classic series of course, absolutely no programming experience, want to learn the Java language, you can take a look at this course.

Bloombenc: an online interactive learning platform, teachers can modify their teaching methods based on your ability to learn and rhythm, but also coding on the platform.

Imooc: Mu class network, C language my university is here to see

CodeAcademy: more practical Java online course, focus is very useful when looking for work technical ability.

PLURALSIGHT: Java integration a lot of video lessons, some free, some paid, you can choose according to their needs.

Lynda Online Java Training Videos: Java Advanced courses, including how to use JDBC to integrate MySQL database, Reflection API, manage files and directories.

IX basis algorithm classes (Java): Chinese online interactive lessons, ready to start learning.

BeginnersBook: After the free Java tutorials for beginners, there is little basis for some programming, documentation can follow the code in practice.

docs.oracle.com/javase/tutorial: Official Guide to Java, to understand almost all the java technical characteristics are very helpful.

JournalDev: Java tutorials and Q & A

JavaWorld: The earliest a Java site, updated weekly Java technology articles.

developer.com/java: http://Gamelan.com maintained by the Java technology article website.

IBM Developerworks Technologies Web site: IBM's Develperworks technology site, which is one of Java Technology Home
Here Insert Picture Description
Above are some of my own thoughts, to share out the welcome to correct me, the way to find a wave of concern inside information you little concerned after I clicked partners [ Java ] you can receive free ~
Here Insert Picture Description

Published 22 original articles · won praise 7 · views 7597

Guess you like

Origin blog.csdn.net/ZYQZXF/article/details/104614216