Project Structure of Java

Source: Internet
Author: User

In Eclipse, a project is represented by a folder, which is placed in the Resource management panel on the left. After the project is expanded, there is a src folder for storing the source code of the project ; there is a JRE System Library, which is the runtime required for the current project, and its version is the version of the JRE that was selected when the project was created. Opening it can be seen with a lot of jar format packages, which is the runtime of the system provided to the program's operating environment and open APIs.

Expand the SRC (source code) folder to see the current project. If you are creating a project for practice, you can create a class in the default package and practice writing code in it. But in a formal development environment, this approach is very undesirable.

The canonical approach is to create a child package under the default package that needs to be created.

The name of the package has certain naming rules, such as the site is www.yeqc.com, then the naming rules here are reversed.

namely COM.YEQC

The first is the nature of the company, that is, commercial (representing a business-type company)

The second one is the company name.

Next is the project name, for example, the project here is called Hello, added to become Com.yeqc.hello

And then, after Hello, continue adding

The package name is then broken down by function, such as creating the first package that is used to run and open a program

You can name this package main

Click Finish

As you can see, the default package edge becomes a Com.yeqc.hello.main


In general, an application should follow the structure rules of MVC.

M stands for model (models)

V represents view (view or interface)

C for Control (control), where the Com.yeqc.hello.main store is the code for the controls


Next, you can right-click on SRC to continue creating the package

Based on the structure rules of MVC, you can create the next package Com.yeqc.hello.view

This creates a view package


Create another model package according to the MVC structure

Call it the Com.yeqc.hello.model.


Three basic packages have been created to complete. If the project is very complex, the package structure here can be very complex. Here is the simplest package structure.


After the program has created the package structure, the first thing to do is to create a program's main portal, the Main method

Create a main class to put in the Com.yeqc.hello.main package, and generate a Main method

Click Finish


If you want to create a class that stores the model in your project, then put it in the Com.yeqc.hello.model package

For example, to create a game project, the map of the game, the attributes of the characters, and so on are all part of the data model.

Should be put into this package

Right-click on the package to create a new class, call it model

Click Finish

The model can be stored in this package.


If the project needs to add a view and user interface

Then we need to put it in the Com.yeqc.hello.view bag.


when the package is created, there is a clear concept of how it will be stored on the hard disk

Come to File Manager

Find Hello World in the work space project

You can see the SRC folder and a bin folder

src corresponds to the src folder under the Eclipse project

Com.yeqc.hello.mian in the package

Each of these points represents each level of file structure in the package.

Open Src->com->yeqc->hello

You can then see the main, model, view three folders

Because in the project, these three packages have the same prefixes.

Until hello, they are stored in the same file structure

So in the last three structures, they are different, so separate the folder store

You can see that the corresponding classes created are stored in main, model, and view.


Return to the project's folder to see a bin path in HelloWorld

This bin path is not visible in the project

It is used to store the current eclipse real-time compiled class file

It has the same folder structure and SRC is exactly the same

Just follow the layers in turn and see the. class files that are compiled in real time

That is, the Java binary file, two is not the source code written


The structure of the package can also be created directly in the file browser

Like Src->com->yeqc->hello.

You can create a new folder here, call it network, "Enter"

This creates a new network package.

When you refresh in eclipse, you see the network package

That's when you can see com.yeqc.hello.network.

You can continue to create the class here


You can create a child package under a package

For example, under the Com.yeqc.hello.view package, create a package img to hold the image.

You can see com.yeqc.hello.img after you refresh the project


Other folders can be created under the current project

The most common occurrence is a lib folder

Here you can store some third-party libraries

in the Lib folder, you can copy a library from somewhere else and paste it into this folder .

Then it will appear in the current directory structure.

Back to the Java workspace and refresh, you can see the Lib folder under the current project

And as you can see in the file browser, the Lib folder and the Src folder belong to the same level

This file in the Lib folder now appears only in the current working environment and is not referenced by the project.

Right-click the file->build path->add to Build Path

There is a new structure called the referenced library (referenced Libraries).

When a package appears here, it is already referenced by the current project.

And you can expand the package here and watch its directory structure.

You can see that the naming of this package is consistent with the above specifications

So you can reference the contents of the package in the project.


Project Structure of Java

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.