Package
Keywords: package
A package is the equivalent of a folder
The package must be written in the package above all classes
Format: Package demopackage (full lowercase); (semicolon)
If the Handwriting DOS command requires a command to create a package
Javac-d ..... (file path) + Compiled main class (note if the location is different to define the path of the package to classpath) Set classpath =,,,,
Scope of four keywords public > proteted > Default > Private
proteted protected
Default Permissions
Public proteted Default Private
Similar √√√√
Same package √√√x
Different buns (inheritance or implementation) √√XX
Different packages non-subclass √xxx
If a function is to be called by an external class, then the function and class are public
A class actually defaults to the package name for that directory, and the package name if you want to invoke a class of another package name. Class Name
If the package name is long and long, it's a hassle.
Keyword Import Import
Import this package, then you can directly write the class name, note can not import two packets, and the call of the class in both packages are common, will produce a compilation error
* Wildcard characters can be instance import pack1.pack2.*
Suppose Pack1 has pack2 inside.
There's Pack3 in Pack2, Pack4.
Then this can make Pack3, Pack4 are imported
This also has a disadvantage, that is, if the Pack2 has 100 folders, and we only have 2 folders, the memory consumption will be very large, not recommended to write
This can be simplified in the Advanced compiler
General to prevent conflicts from using URLs as names (domain names)
Thread
There are a lot of threads in every process.
Because Java has a garbage disposal mechanism, assuming that no other threads are considered, a process must have a garbage handling mechanism and a thread of the main function
The main function of the thread is main so when you run to write a main function
The appearance of threads can speed up the operation of the program to some extent
Keyword Thread threads
If you want to call just inherit this thread and overwrite the run function, the thing inside the run function is the code we want to run.
Start () function run thread
Class Test extends thread{public void Run () {for (int i = 0; i <; i++) System.out.println ("Hello T Hread "+i);} } Class Demo_ Thread {public static void Main (string[] args) { Test demo = new test (); Demo.start (); Demo.run (); for (int i = 0; i < i++) System.out.println ("Hello default" +i);} }
Enables multi-process
If you write only run, then you will only be running from top to bottom.
GetName
Getpackage
Function
Learn Java DAY9 from scratch