🎯 In this video, we explore one of the most essential Java concepts: how to reuse classes from different packages using the import statement!
Learn how to structure your Java projects professionally using packages, and access classes across them without confusion. We'll walk through a real example using ClassOne, ClassTwo, and MainClass, all placed in separate packages — just like in real-world projects.
🧠 What You'll Learn:
✅ How to create packages in Java
✅ How to reuse classes from other packages using import
✅ Why packages help keep your code clean and organized
✅ Hands-on example with a realistic file structure
📁 Java File Structure:
src/
├── com/example/one/ClassOne.java
├── com/example/two/ClassTwo.java
└── com/example/main/MainClass.java
💻 Java Code Example:
🔹 ClassOne.java (in com.example.one)
package com.example.one;
public class ClassOne {
public void greet() {
System.out.println("Hello from ClassOne in package ONE");
}
}
🔹 ClassTwo.java (in com.example.two)
package com.example.two;
public class ClassTwo {
public void greet() {
System.out.println("Hello from ClassTwo in package TWO");
}
}
🔹 MainClass.java (in com.example.main)
package com.example.main;
// Import classes from other packages
import com.example.one.ClassOne;
import com.example.two.ClassTwo;
public class MainClass {
public static void main(String[] args) {
ClassOne one = new ClassOne();
ClassTwo two = new ClassTwo();
one.greet();
two.greet();
}
}
⚡ Code Explanation (High-Energy Style!):
🔸 1. Packages = Organized Java
Packages help group related classes together.
Think of them like folders in your project!
🔸 2. ClassOne and ClassTwo Live in Different Packages
ClassOne is in com.example.one
ClassTwo is in com.example.two
Each has a method greet() that prints a message.
🔸 3. MainClass Imports Them Like a Pro!
In MainClass, we use:
import com.example.one.ClassOne;
import com.example.two.ClassTwo;
Then we create objects and call their methods — easy and clean!
✅ BONUS TIP:
This is how large-scale Java apps are built: reusable code, clean structure, no mess!
🧠 Summary:
Use ClassName.methodName() for static methods.
Use import statements to access classes from other packages.
Keep your package structure neat and meaningful.
📢 Smash that 👍 Like button, 🔔 Subscribe for more Java tips, and 💬 Drop a comment if you want a follow-up tutorial on package-private access or import static!
#️⃣ Hashtags :
#JavaPackages, #JavaImport, #JavaClasses, #JavaOOP, #JavaProjectStructure, #JavaTutorial, #LearnJava, #JavaBeginner, #CodeWithJava, #JavaForBeginners, #CodingInJava, #JavaConcepts, #SoftwareDevelopment, #ImportInJava, #JavaOrganizedCode, #CodingBasics, #JavaIDE, #JavaExamples, #JavaCode, #JavaLearning, #ObjectOrientedProgramming, #JavaPractice, #JavaExplained, #ReusingJavaClasses, #CodeSmarter, #JavaPackageSystem, #JavaDevelopment, #JavaProjects, #ImportStatement, #JavaTips
Watch video 📦 Java Packages Explained: How to Reuse Classes from Different Packages Using import online without registration, duration hours minute second in high quality. This video was added by user QA_AI_WIZARDS 30 April 2025, don't forget to share it with your friends and acquaintances, it has been viewed on our site once and liked it 0 people.