A front end of the back-end java journey (a) Starting from Java Package

As a front-end engineer wants advanced java backend but fear of java, you just missing their own tutorial, we are programming people, completely unnecessary from int, String, Boolean, if, else, witch, for, while .... this kind of thing to learn the. Let me begin, first find the route back end java trip, then quickly back-end java attack it with everyone.

First, learn to create a Java project

Take a look at how to use it until we know Java package. Create a normal java project using the IDEA tool.

IDEA here to download and install tools, and download jdk not introduced (if it does not install jdk, click to view detailed installation steps ), but you must ensure that the tools and IDEA jdk to have installed to read on:

step1 Click Create New Project to create a project

step2 here we must ensure that the point is a blue box jdk must be selected, if not, click New on the right to add in your download jdk, the remaining boxes are not checked, click next

step3 The Select template interface, default is not checked, you can check for the convenience and select Java Hello Word template, click next

step4 first line of input the project name, the second line choose what items are stored path, click Finish to complete the project creation

step5 Main.java into the right click menu Run 'Main' will be their first experience of a java program

Java File Manager

As the front end of a player's career, you can often walk in vue / react the project, the project src directory has a profound insight, they themselves would design listings that fit their own style of storing the appropriate code, in java is the same, we You can create a different directory in src to manage different Java code.

To a simple example: When you are ready to create Directory (WebStorm in a Directory), you suddenly find, WDMY even without this option, but there you have not seen in years WebStorm thing, that is Package, yes, Java It is called by this Packagething to manage files directory.

Well, it would create a learning.basethe Package(包)bar, then you will find more than a src directory under learning.basethe package.

You can click on the red box to the top right corner of the gear button to Compact Middle Packagesremove the hook option, you can see learning.basehas become a learning/basecascade directory.

At this point you can clearly explain the java package in the end is what he is used to one kind of catalog management and organization java project files.

Packages and folders in the end what is the difference?

When learned that package, we know the nature of the package is a folder or directory, but you (in fact I) may be a little confused as to why the java directory called the package, why do we need this package concept, we write there are also front-end catalog ah, I have not seen people put into the directory abstract concept of what the package.

Well, since the package is called, it is certainly not a common directory, then it is with the common catalog in the end what difference does it make?

In looking for answers, I found the answer online say there is no difference, but I can not give up, ah, there will be no difference that the concept of what is called the package rather than a directory.

Such individuals are understood: java package java directory structure is an acceptable specification. It was not an ordinary directory is that it is subject to certain provisions, while the ordinary directory you are free to create.

This specification includes:

  1. Naming convention: package name can only be strings, numbers, underscores, $ and can not start with a number, usually lowercase English characters (uppercase without an error).

    • The rules are very similar to variable naming, in fact, this is also a reason. You can create a Hello in learning.base Java Class
    •   package learning.base;
      
        public class Hello {
        
        }
      复制代码
    • You can see package learning.basethe package name declared in the java code, if anything, Math symbol appears in the package name, is not unreasonable, so this specification is very important.
  2. Organizational structure of the package specification: general structure of the package to write down the domain name to organize, to dot between the package name .to connect. For example, I have a domain name is called geekrole.comI can organize this package name com.geekrole.user.

    • At first you may have questions about why the errors with writing, but if you put the bag down into the directory structure com/geekrole/user, you know, naming the directory structure of a score, so the package name is.

Use package

We already know, java package is a directory to manage and organize files java project, so we can be certain type of code is encapsulated into a single package, many of the standard java libraries offer also organized in the form of packets , but it is global, and begin with java, for example java.lang, java.utiland so on.

Breaking the psychological fear

At this point you (in fact I) may face a kind of anxiety and fear of the unknown, how do I know what it needs some packages, it's what's bag method, each call to import the package how to import ...

Well, to be honest, this fear should be redundant, Idea can help us to automatically import some use of the package, you can try the following code, when you wrote after the package is automatically imported Scanner Scanner Enter. If a custom package, idea will be a corresponding tips to help us to automatically import.

package learning.base;

import java.util.Scanner;

public class Hello {
    public static void main(String[] args) {
        // 输入两个数字比较大小,输出大数
        Scanner sc = new Scanner(System.in);
        int num1 = sc.nextInt();
        int num2 = sc.nextInt();
        int res = Math.max(num1, num2);
        System.out.println(res);
    }
}
复制代码

Solve the problem of the imported package, then how do you know what the package, this is a question of accumulation, and if the development process need to use the time-related, then check out the time-related package, look at the ways we can supply use, it is java9 official document, you can find a variety of packages that you want to use (java9 document)

tipsYou can take note of the way declaratively and import package. package keyword is used to declare package, import keyword is used to import the package

What is a jar package and the war package?

Now comes the package, it might jar package and the package is also a brief description war, to avoid the follow-up program to bring them to our fear of the unknown.

jar package is hell

You may not understand jar package, but must know and used zip compression utility, such as 2345 good pressure, through which you can put a lot of files even folders packaged together for easy transfer to others, but it also has a compression algorithm, you can put the file size smaller.

jar package is the essence of java in the zip package, essentially the same, but since he is a jar, it must zip bag with a difference, what difference jar and zip is: jar file is not only used to compress and release, but also for deployment library package and, components and plug-ins, and may be such as compilers and tools directly JVM ( sentence from Baidu ).

That jar package can further our packaging various types of files (could prevent up through package in the form of classes) to be a further package file, and the file is no need to decompress when in use, can be used directly. In addition also has the advantage of some of the zip package, such as compression.

This, jar package in the end what advantage they would be roughly inferred twelve, and if it is obsessive-compulsive disorder, Baidu search a search, then you will find yourself able to guess based on the difference between the zip and above the jar and zip.

war is hell and package

Said jar package, but also how a war package, bluntly, war is to package up a web application packaging package and similar package with the jar, it can also be run directly.

We can understand, jar package is a package of various tools, war is based on a module package of the entire site, or a site, it can be run directly.

summary

Although this article is not something substantive programming related, but it can help some friends do not have basic java from another angle quickly have a general understanding of java.

The following is a chat when it comes to how to write java related articles, think of as a student Jike professional, has only learned c / c ++, java never played seriously, then interest and opportunity so I contacted the front end, but java is always a block heart disease ah.

Java content may be really a bit much, a java SE grammar books normal point but also four or five hundred pages, looks really like a dictionary. Talk about my java recently read a book "written for busy people JavaSE9 core technology", 500 pages, like a dictionary, 大忙人do not look empty dictionary ah.

Find the Internet to find information quickly learn, but did not find what you want, or is introduced int, Integer, String, Boolean, if, else, switch or began to introduce a bunch of object-oriented features, what jdk, jre Yes. This tutorial content is very wide, not for me to learn quickly, as a learned c Person language (c, c ++, java, javascript are considered), a number of basic grammar, if, else, switch, while, do while, for exactly the same, ah, there is not much to learn and repeat as necessary.

So he started thinking about it lug for it, and then recorded, but also for some of the advanced front-end java friend seriously do something, we are all programmed, needless to say a lot of things would not say, quickly familiar with java, excessive spring boot as soon as possible to such frameworks as the real beginning of the backend programming that is important, rather than the pursuit content enough, more than what he used to finish school?

There is a reason, called the Mu class, July full stack java class teacher, but no java-based, so the foundation must own up here a little longer.

Guess you like

Origin juejin.im/post/5e0704b06fb9a016280146c0