answersLogoWhite

0

As we know, default package of java.lang.*; is implicitly called if it is not explicitly called Ok, So. Package is Collection Classes ( abstract or interfaces).

Package Creation :-

1 ) First line of the program, in which you want create a package must be a your desired package name starting with package keyword and followed by semicolon.

2 ) While creating package, it is not necessary to write public before each class name.

3 ) But, each and ever method must be public.

Creating or Compiling Package :-

Syntax :-

D:\Practice\Javac -d < Path of program > < .java file name >

Complete Example :-

package TYBCS;

class Mathematics

{

public int addNumbers(int num1,int num2)

{

return(num1+num2);

}

public static double addFloatNum(double num1,double num2,double num3)

{

return(num1+num2+num3);

}

}

class Maximum

{

public int getMaxOutofThree(int n1,int n2,int n3)

{

int num=0;

if(n1>n2 && n1>n3) { num=n1; }

if(n2>n1 && n2>n3) { num=n2; }

if(n3>n1 && n3>n2) { num=n3; }

return num;

}

}

class Practice

{

public static void main(String args[])

{

Mathematics m=new Mathematics();

Maximum mx=new Maximum();

System.out.println("Addition 5+5 : "+m.addNumbers(5,5));

System.out.println("Addition f 2.5+2.5 : "+m.addFloatNum(2.5,2.5,2.5));

System.out.println("Max Number 7, 8 , 1 : "+mx.getMaxOutofThree(7,8,1));

}

}

/*

Output:-

D:\Data>javac -d D:\Data\ Practice.java

D:\Data>java TYBCS.Practice

Addition 5+5 : 10

Addition 2.5+2.5 : 7.5

Max Number 7, 8 , 1 : 8

D:\Data>

*/

User Avatar

Wiki User

13y ago

Still curious? Ask our experts.

Chat with our AI personalities

BeauBeau
You're doing better than you think!
Chat with Beau
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
JudyJudy
Simplicity is my specialty.
Chat with Judy
More answers

Predefinedpackages and classes are those that come installed as part of the standard Java library; it is expected that each conforming Java implementation will have these libraries available to them without having to package those classes as part of the project. User defined packages, in contrast, are those classes not defined by the Java interface and must be packaged as part of an application (e.g. placed in the JAR file) in order to provide the implementation class files needed to have the program run.

User Avatar

Wiki User

12y ago
User Avatar

Predefined packages

Java provides various predefined classes and interfaces (API’s) organized under packages. These are known as predefined packages, following is the list of predefined packages in java −

java.lang − This package provides the language basics.

java.util − This packages provides classes and interfaces (API’s) related to collection frame work, events, data structure and other utility classes such as date.

java.io − This packages provides classes and interfaces for file operations, and other input and output operations.

USER Defined pakages

To create a package, we choose a package name and to include the classes, interfaces, enumerations, etc, inside the package, we write the package with its name at the top of every source file.

There can be only one package statement in each type of file. If we do not write class, interfaces, inside any package, then they will be placed in the current default package.

User Avatar

vivek sondhiya

Lvl 2
3y ago
User Avatar

Predefined packages are a part of the Java API and are accessible to all. One can create their own packages and distribute them.

User Avatar

Wiki User

12y ago
User Avatar

Rashmi

User Avatar

Rashmi Ranjan

Lvl 2
4y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What are differences between user defined packages and predefined packages in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are the different types of package in java?

1.user defined packages 2.predefined packages


What is the difference between predifined data structure and user define data structure?

A predefined structure or, more generally, a predefined type, is a type that is defined internally by the compiler implementation. For instance Microsoft's implementation includes predefined runtime information and GUID structures, amongst other predefined types such as size_t. These types are built in to the compiler itself, so you won't find them in a header file. By contrast, user-defined structures (types) are those you define yourself, or are provided for you by a third party.


What are predefined codes?

Predefined codes or the predefined functions are the codes small or large codes which are predefined by the maker of the language. In C++ the predefined codes can be included in the program by the header files. These codes are placed in files and functions could be used to access them. Like a simple console Code to output "Hello World" uses a predefined code cout


Can a class extend exception?

Yes You can. The features of such a class would be similar to what an Exception would have but not exactly as a predefined Java Exception. When you create a user defined exception you extend the java.lang.Exception class which in turn extends the java.lang.Throwable so indirectly you are extending the Throwable class while creating a user defined exception...


Name the following-A key word to use the classes defined in a package?

To access the classes which are present in other packages, we have to import the package to our program using the keyword 'import'. Eg: import packagename.subpackage.Class; OR import packagename.subpackage.*; /*Adds all the class which are present in package*/ 'extends' is the keyword used to inherit the classes defined in other packages.