package is grouping of your classes, interfaces, annotation and enums. To name a package, in the very top of your file, use the keyword package followed by the name.
package myclasses;
Sometimes, companies used the reverse name of their domain in their package. But take note of the hypen or other special characters used in the domain name because they are not valid in creating a package name.
package com.example.tralala;
When accessing a class in your package, you can do the following:
1. You can use the fully qualified name if you don't want to import it.
public void main(String[] args){
com.example.tralala.MyClass obj = new com.example.tralala.MyClass();
}
2. But if you use import, you can put it after your package name of the class you are creating.
package com.example.anothertralala;
import com.example.tralala.MyClass;
3. You can use a * as a wildcard character to signify all classes under it.
import com.example.tralala.*;
4. Note that packages are not hierarchical just like your classes. There can be another package in that tralala. So, just import them all.
import com.example.tralala.*;
import com.example.tralala.anothertralala*;
5. However if there are some classes with the same name as your class, just use the fully qualified name which is the package and the name of your class.
6. For importing static classes like java.lang.Math, just add a static keyword after the import.
import static java.lang.Math
7. For the source file of your class, it ends in .java extension and when compiled, it ends in .class extension.
com.example.tralala.MyClass.java
com.example.tralala.MyClass.class

YOU ARE READING
Java Programming
Aléatoirehttps://docs.oracle.com/javase/tutorial/ This is the link where I learned my java lessons online. I choose java as first programming language. I am a career shifter. I just want to start something new. I choose to write it here in Wattpad so that I...