top of page
This website was created by Contagious

CLASS AND PACKAGES IN JAVA

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

  1. Use CamelCase and start the class name with a capital letter.

  2. If a class name contains multiple words, start each word with a capital letter.

  3. Choose descriptive and meaningful class names that accurately describe the class's purpose.

  4. Avoid using underscores or numbers in class names.

  5. 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

  1. Use all lowercase letters for package names.

  2. Separate words in package names with a dot.

  3. Avoid using special characters like underscores or hyphens in package names.

  4. Make your package names hierarchical and descriptive of your code organisation.

  5. 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.

 
 
 

Related Posts

See All
OBJECTS, INHERITANCE, AND INTERFACE

We already studied what is Class and Packages. Now we will get to know about Object inheritance and interface the major concept of OOP(...

 
 
 
INTRODUCTION TO JAVA

Java is a high-level and object-oriented programming language developed by Sun Microsystems in the mid-1990s, Later it was acquired by Oracl

 
 
 

Comments


bottom of page