For class
, we will proceed on the assumption that we have some image.
It is often explained that the class is a blueprint and the instance is actually generated based on the blueprint, but if you do not know the class, please google.
I think it's common to other object-oriented programming languages.
The basics of a java program start with creating a class. If you want to create a simple program, you only need to use a few classes, If you want to create a big program, you will use many classes. A package is a collection of classes and interfaces, and is classified according to usage. In java, various classes are prepared, including the object class, but these are all managed by the package. Different packages will be treated as different classes even if they have the same name.
Source: http://www1.bbiq.jp/takeharu/java51.html
Each Java ™ class belongs to a package. Which class is included in which package is stated in the first statement in the Java source file. If the source file does not have a package statement, the class is considered to be included in the unnamed default package.
Source: https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/rzaha/clpckdir.htm
・ All classes belong to package
-If package is not specified, it belongs to the default package
-Collecting related classes into a package has the advantages of clarifying the development unit and making it easier to manage, and restricting access only from the same package.
-The package name hierarchy corresponds to the directory hierarchy.
(java.util.ArrayList
corresponds to java / util / ArrayList.class
)
python
package java.lang;
Declares to belong to java.lang
.
-In order to uniquely identify a class, it must be described with a fully qualified name
.
fully qualified name
=> package name
-The package can be omitted by writing the import command so that you do not have to write this every time.
-It seems that the import command is generally written immediately after the package declaration.python
import java.util.*;
With this specification, all directory hierarchies directly under java.util can be specified.
= Same for instance fields and instance variables.
If you think about it roughly, you can classify the types of variables into two types: basic data type
(= primitive type
, value type
) and reference type
(= class type
).
The following 8 types.
Mold | Memory area | Overview |
---|---|---|
boolean | 1bit | true or false |
char | 16bit | Unicode single character |
byte | 8bit | Signed integer-128~127 |
short | 16bit | Signed integer-32768~32767 |
int | 32bit | Signed integer-2147483648~2147483647 |
long | 64bit | Signed integer about-922 Kyo-about 922 Kyo |
float | 32bit | Floating point number |
double | 64bit | Floating point number |
A variable of the basic data type means that its size (number of bits) is exactly determined by the type. This means that when a variable is declared, the used area of the variable in memory can be secured in just proportion. Any value can be kept within that fixed area (as long as it is within the range of that type).
Reference source: https://nobuo-create.net/sanshougata/
-Specific data values (numerical values and characters) written directly to the memory can be assigned, and the variables themselves have values. -Unlike the reference type, it does not have a method. ・ Starts with all lowercase letters.
-All are reference types except the basic data type. -Arrays and Strings are also reference types. -The reference type creates an object and stores the value (= reference value) for referencing the object in a variable.
Reference URL: https://www.mlab.im.dendai.ac.jp/~yamada/java/reference/
A variable whose value cannot be changed.
python
final int COUNT = 4;
Add final
at the beginning and write in capital letters.
Recommended Posts