学java,一分钟了解java











分享兴趣,传播快乐,增长见闻,留下美好!



亲爱的您,这里是LearningYard学苑。今天小编为大家带来“学习知多少:java篇”,欢迎您的访问。



Share interests, spread happiness, increase knowledge, and leave a good legacy!



Dear you, this is The LearningYard Academy. Today Xiaobian brings you “Learn how much to know :Java chapter”, welcome your visit.



一、思维导图



一、 Mind mapping





















二、源文件声明规则



我们将学习源文件的声明规则。当在一个源文件中定义多个类,并且还有import语句和package语句时,要特别注意这些规则。



二、 Source File Declaration Rules



We will learn the declaration rules for source files. When defining multiple classes in a source file, and there are also import and package statements, special attention should be paid to these rules.










一个源文件中只能有一个 public 类



一个源文件可以有多个非 public 类



There can only be one public class in a source file



A source file can have multiple non public classes










源文件的名称应该和 public 类的类名保持一致。例如:源文件中 public 类的类名是 Employee,那么源文件应该命名为Employee.java。



The name of the source file should be consistent with the class name of the public class. For example, if the class name of the public class in the source file is Employee, then the source file should be named Employee.java.










如果一个类定义在某个包中,那么 package 语句应该在源文件的首行。



If a class is defined in a package, the package statement should be on the first line of the source file.










如果源文件包含 import 语句,那么应该放在 package 语句和类定义之间。如果没有 package 语句,那么 import 语句应该在源文件中最前面。



import 语句和 package 语句对源文件中定义的所有类都有效。在同一源文件中,不能给不同的类不同的包声明。



If the source file contains an import statement, it should be placed between the package statement and the class definition. If there is no package statement, then the import statement should be at the top of the source file.










类有若干种访问级别,并且类也分不同的类型:抽象类和 final 类等。这些将在访问控制章节介绍。



The import statement and package statement are valid for all classes defined in the source file. You cannot declare different packages for different classes in the same source file.










除了上面提到的几种类型,Java 还有一些特殊的类,如:内部类、匿名类。



Classes have several access level, and classes are also divided into different types: abstract classes and final classes. These will be introduced in the access control section.










Java 包



包主要用来对类和接口进行分类。当开发 Java 程序时,可能编写成百上千的类,因此很有必要对类和接口进行分类。



Java package



Packages are mainly used to classify classes and interfaces. When developing Java programs, it is possible to write hundreds or thousands of classes, so it is necessary to classify classes and interfaces.










import 语句



在 Java 中,如果给出一个完整的限定名,包括包名、类名,那么 Java 编译器就可以很容易地定位到源代码或者类。import 语句就是用来提供一个合理的路径,使得编译器可以找到某个类。



Import statement



In Java, if a fully qualified name is given, including the package name and class name, the Java compiler can easily locate the source code or class. The import statement is used to provide a reasonable path for the compiler to find a certain class.










例如,下面的命令行将会命令编译器载入 java_installation/java/io 路径下的所有类



For example, the following command line will command the compiler to load Java_ All classes in the installation/java/io path










import java.io.*;



一个类可以包含以下类型变量:



局部变量:在方法、构造方法或者语句块中定义的变量被称为局部变量。变量声明和初始化都是在方法中,方法结束后,变量就会自动销毁。



成员变量:成员变量是定义在类中,方法体之外的变量。这种变量在创建对象的时候实例化。成员变量可以被类中方法、构造方法和特定类的语句块访问。



类变量:类变量也声明在类中,方法体之外,但必须声明为 static 类型。



一个类可以拥有多个方法,在上面的例子中:eat()、run()、sleep() 和 name() 都是 Dog 类的方法。



A class can contain the following type variables:



Local variables: Variables defined in methods, construction methods, or statement blocks are referred to as local variables. Variable declaration and initialization are both in the method, and after the method ends, the variable will be automatically destroyed.



































































今天的分享就到这里了。


如果您对今天的文章有独特的想法,


欢迎给我们留言,


让我们相约明天。


祝您今天过得开心快乐!









That’s all for today’s sharing.


If you have a unique idea for today’s article,


please leave us a message,


and let us meet tomorrow.


I wish you a happy day !










本文由learningyard新学苑原创,如有侵权,请联系我们!



翻译来源于谷歌翻译



部分来源于



百度文库



清华大学出版《java程序设计基础》



编辑&排版|百味



审核|闫庆红

本文来自投稿,不代表商川网立场,如若转载,请注明出处:http://www.sclgvs.com/peixun/34660.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。