简体   繁体   English

在 Eclipse 中创建一个包,相当于创建一个新文件夹吗?

[英]Is creating a package in Eclipse, equivalent of creating a new folder?

I'm not using Eclipse, so for my project when stated "create a new Java project called "Project 1", and import the above 2 files into a default package. " Is that the equivalent of just throwing the two files into a folder and naming it "Project 1"?我没有使用 Eclipse,所以对于我的项目,当声明“创建一个名为“项目 1”的新 Java 项目,并将上述 2 个文件导入到默认包中时。这是否等同于将两个文件放入一个文件夹中并将其命名为“项目 1”?

Because I'm using VS Code, If not how would I be able to create a package on VS Code?因为我使用的是 VS Code,否则我如何能够在 VS Code 上创建包?

Yes, about package in VS Code, the first thing we need to do is creating a folder.是的,关于 VS Code 中的包,我们需要做的第一件事就是创建一个文件夹。

When we create a folder under src, which we assume its name is AAA .当我们在 src 下创建一个文件夹时,我们假设它的名字是AAA if a .java file is created under AAA, there will be a statement package AAA;如果在AAA下创建一个.java文件,就会有一个声明package AAA; on the top line, like the screenshot shows:在第一行,如屏幕截图所示:

在此处输入图片说明

If package AAA;如果package AAA; isn't generated automatically, we should add it manually in every file which is under this folder.不是自动生成的,我们应该在这个文件夹下的每个文件中手动添加它。

A package is a subdirectory below the src directory which is below the project directory.包是项目目录下 src 目录下的子目录。 You won't run into any issues using the default package, but it is generally good practice to put all your class and other files into a package so it is more organized.使用默认包不会遇到任何问题,但通常将所有类和其他文件放入一个包中是一种很好的做法,以便更有条理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM