Package | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Package

Explain what is the use of packages and java lang .packages In simple way

19th Aug 2020, 4:13 AM
Azad Shami
Azad Shami - avatar
5 Answers
+ 1
Azad Shami you're welcome.
19th Aug 2020, 5:25 AM
Avinesh
Avinesh - avatar
0
Package is a collection of related classes and interfaces. They are generally used to avoid name conflicts and moreover you have a much better maintainable code. You can have more than 1 class with the same name but declared in a different package. java.lang package is implicitly imported by every Java program that you write because it has most relevant collection of classes for Java language support.
19th Aug 2020, 5:05 AM
Avinesh
Avinesh - avatar
0
package factor; import java .util.Scanner ; public class factor { public static void main(String[] args) { int n,i; Scanner sc =new Scanner (System .in); System .out.println ("enter a no"); n=sc.nextInt(); System .out.println(" factor of no is"); for (i=1;i<=n;i++)//let assume no10 //factor of 10 is 1,2,5,10 { if(n%i==0)//we have to check(10%2==0) System .out .println (i);//2 and so on } } } When I run the program it show the error that Java.lang.Noclassdefound Error Can you explain and solve??
19th Aug 2020, 5:17 AM
Azad Shami
Azad Shami - avatar
0
Sololearn does not support packages so removing the very 1st line shall do the job.
19th Aug 2020, 5:23 AM
Avinesh
Avinesh - avatar
0
Thank you brother ❣❣❣
19th Aug 2020, 5:24 AM
Azad Shami
Azad Shami - avatar