Monday, February 3, 2020

Exercise – 12 (Packages)


Exercise – 12 (Packages) 


a). Write a JAVA program illustrate class path 


import java.net.URL;

import java.net.URLClassLoader;
public class App
{
public static void main(String[] args)
{
ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();
for(int i=0; i< urls.length; i++)
{
System.out.println(urls[i].getFile());
}
}
}

b). Write a case study on including in class path in your os environment of your package.  

COPEING THE PATH OF JAVA:-

First of all go to MYCOMPUTER and go to the drive where the java is installed.In that go to

PROGRAM FILES and then double click on java folder.
In that we have observed there is a folder with name java jdk,double click on the java jdk folder
and then go into the bin folder.
At this time we have to copy the path of the bin folder.

SETTING THE JAVA PATH:-

Inorder to set the path of the java in our system,first of all we need to open CONTROL PANEL
in our system and go to SYSTEM SETTINGS .

In system settings we need to go into the ADVANCED SYSTEM SETTINGS settings.In

advanced system settings we just click on ENVIRONMENT VARIABLES option.
In USER VARIABLES click on NEW button and type the " path" at VARIABLE NAME.
We need to paste the previously copied path of the bin folder at the place of VARIABLE VALUE.
Finally click on OK and then OK,then close the MYCOMPUTR window.Now the java path is set.We are ready to use java facilities in our computer.


c). Write a JAVA program that import and use the defined your package in the previous  Problem


1).

package pack;

public class Addition
{
private double d1,d2;
public Addition(double a, double b)
{
d1=a;
d2=b;
}
public void sum()
{
System.out.println("Sum inside of  class Addition is:"+(d1+d2));
}
}

Compilation of the program :- javac -d . Addition.java
2).
import pack.Addition;
class Use
{
public static void main(String args[])
{
Addition obj=new Addition(10,15.5);
obj.sum();
}
}

No comments:

Post a Comment

JAVA PROGRAMMING ASSIGNMENT 2 QUESTIONS

SIR C R REDDY COLLEGE OF ENGINEERING, ELURU DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING JAVA PROGRAMMING ASSIGNMENT 2 QUESTIONS ...