CLASS AND PACKAGES IN JAVA
- SHASHANK GUNDA
- Apr 23, 2023
- 2 min read
Remember, Java is an object-oriented programming language, which means everything is associated with a class and object, and the program flow is continued in the class. Are you not aware of the technical terms? No problem, everything, you will learn. Are you Waiting to write your first Java program? Then we will do that in this blog.
CREATING A CLASS
What is the class like? Class is the blueprint of an object and how they behave like.
Let's see the syntax ( Declaration of class ):
class MyFirstClass {
}Now, the name of your Java class is MyFirstClass, and the program file should be saved the same as the class name "MyFirstClass" with the extension .java. For instance, MyFirstClass.java. The program statements and methods are to be written between the brackets.
The are some Naming Conventions. Let's see what they are
Use CamelCase and start the class name with a capital letter.
If a class name contains multiple words, start each word with a capital letter.
Choose descriptive and meaningful class names that accurately describe the class's purpose.
Avoid using underscores or numbers in class names.
Use nouns for class names.
For instance, the class name should be "MyFirstClass", Every word starts with a capital letter without underscores or numbers.
PACKAGES IN JAVA
Packages in Java are the collection of related classes and interfaces that provide a namespace for the class.
Declaration of the package is straightforward, and the keyword package is used and followed by the package name.
package treeex;
class MyFirstClass {
}There are some naming conventions for packages. Let's see
Use all lowercase letters for package names.
Separate words in package names with a dot.
Avoid using special characters like underscores or hyphens in package names.
Make your package names hierarchical and descriptive of your code organisation.
Use meaningful and descriptive names for your packages.
Might the theory is overloaded but remember the points. Everything will be clear bit by bit in the learning process.


Comments