Skip to main content

Packages In Java

 


Package in java is a group of similar type of classes, interface and sub-package. Packages in java can be defined in two ways which are
1 Built-in Packages
2 User-defined Packages
Built-in Packages are 
     * Lang
     * Util
     * io
     * awt
     * net
     * applet, etc.

User-defined packages can be anything which are created by the user.

Packages are nothing but container of the classes which store the no of classes, interface and their methods.

Advantages of Packages
1 It provide access Protection
2 It removes the naming collision
3 it is used to categorize the classes and interface so that they can be easily maintained.

Steps for creating a package

Step-1 Create a folder in any drive of your choice 
Step-2 example in d: package1 (it is the name of the package)
Step-3 Open the java application and type the following code

package package1;
public class demo
{
 public void display()
{
System.out.println("Welcome to Programmingssidepoint");
}
}

Step-4 Save the above code in the drive where you have saved the package as demo.java
Step-5 Now open a new file and type the following code

import package1.demo;
class example
{
  public static void main(String[] args)
{
demo obj=new demo();
obj.display();
}
}

Step-6 Save the above code in the same drive in which you have created the folder that is package1
Step-7 example d:example.java
Step-8 Now compile and execute the following code.



Comments

Post a Comment

Popular posts from this blog

Best Programming Language to learn in 2021

The main aptitude to learn in this day and age is to realize how to compose a PC program. Today, PCs have entered in pretty much every industry. Be it the autopilot in an airplane or advanced speedometer in your bicycle, PCs in different structures encompass us. PCs are incredibly valuable for an association to scale up well. Gone are the times of pen and paper. Today, to store and access your data, you totally need PCs. The programming and engineer networks are arising at a rate quicker than at any other time. Different new programming dialects are coming up that are appropriate for various classifications of designers (tenderfoots, middle, and specialists) just as for various use cases (web application, versatile applications, game turn of events, disseminated framework, and so forth) Each amateur is astounded with the inquiry, "What programming language would it be advisable for me to learn?" Types of Programming  1. Procedural Programming Languages This programming worldv

Java - Static variable, static method and static block with example.

Java Static keyword, Static method and Static block........ Questions.......?? 1) What is static keyword , static method() , static block 2) Define static keyword , static method() , static block 3) What do you mean by static keyword , static method() , static block 4)static keyword , static method() , static block in Java ?     1)Static Keyword:- Static keyword in Java Programming language is used for memory management purpose, it indicates that a particular member belong to a type itself, rather than to an instance of that type. As we mentioned above that is used for memory management purpose it means that static keyword gets memory once in the class which help in reduction of the memory, which makes the execution speed of the program fast which is a great advantage of the static keyword. let's take example how static keyword works..... firstly we will see how memory get wasted when we didn't use the static keyword. class company {  int emp_id; 

What is Procedural Programming Language(PPL)

  Procedural Programming Language. Procedural Programming might be the primary programming worldview that another engineer will learn. Essentially, the procedural code is the one that straightforwardly trains a gadget on the best way to complete an errand in consistent advances. This worldview utilizes a direct top-down methodology and treats information and techniques as two distinct elements. In view of the idea of a methodology call, Procedural Programming isolates the program into strategies, which are otherwise called schedules or capacities, just containing a progression of steps to be done.  Basically, Procedural Programming includes recording a rundown of directions to mention to the PC what it ought to do bit by bit to complete the job needing to be done.  Key Highlights of Procedural Programming  The vital highlights of procedural writing computer programs are given underneath:  1)Predefined capacities: A predefined work is normally a guidance distinguished by a name. For the