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

huangapple go评论75阅读模式
英文:

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

问题

我没有使用Eclipse,所以对于我的项目,当指示"创建一个名为“Project 1”的新Java项目,并将上述两个文件导入默认包。"这样做是否相当于只是把这两个文件放入一个文件夹并将其命名为"Project 1"?

因为我在使用VS Code,如果不是这样的话,我该如何在VS Code中创建一个包?

英文:

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"?

Because I'm using VS Code, If not how would I be able to create a package on VS Code?

答案1

得分: 1

是的,在VS Code中关于包(package)的部分,我们首先需要做的是创建一个文件夹。

当我们在src下创建一个文件夹,假设它的名字是AAA。如果在AAA文件夹下创建了一个.java文件,在顶部一行会有一个**package AAA;**的语句,就像截图所示:

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

如果**package AAA;**没有自动生成,我们需要在每个位于这个文件夹下的文件中手动添加它。

英文:

Yes, about package in VS Code, the first thing we need to do is creating a folder.

When we create a folder under src, which we assume its name is AAA. if a .java file is created under AAA, there will be a statement package AAA; on the top line, like the screenshot shows:

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

If package AAA; isn't generated automatically, we should add it manually in every file which is under this folder.

答案2

得分: 0

一个包是位于项目目录下方的 src 目录下的子目录。使用默认包不会遇到任何问题,但通常最好的做法是将所有的类和其他文件放入一个包中,以便更有组织。

英文:

A package is a subdirectory below the src directory which is below the project directory. 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.

huangapple
  • 本文由 发表于 2020年10月15日 01:56:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/64358973.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定