Skip to main content

Posts

Showing posts with the label packages

Packages in Java

Introduction Package is a java directory used to group related classes and interfaces and used to separate new classes from existed classes. Means if we use packages we can create multiple classes with same name. How to Create package? Nothing fancies, you just need to follow below syntax: package "package-name"; e.g. package com.app; Rule: It should be First statement in Java Program According to industry standard, every class file or interface file first line should be package statement. And it starts from reverse domain of the company e.g. com.mycompany.functionality. Program showing creation of class with package : //Example.java package com.app; class Example { public static void main(String args[]){ System.out.println("Creating package!!!"); } } Execution: Go to directory where you have created class file >Javac -d . Pro...