How to execute class with a main() method in a package, JAVA Programming

Assignment Help:

 

Example:  You have a class named "Set" in a project folder "e:\myProject" and package named com.zxy.client, will you be able to compile and execute it as it is

 

 

package com.xyz.client;

 

public class Pet {

public static void main(String[] args) {

System.out.println("I am found in the classpath");

}

}

 

To run-> e:\myProject> java com.zxy.client.Set

 

The answer is no and you would get the following exception: "Exception in thread "main" java.lang.- NoClassDefFoundError: com/zxy/client/Set". You have to set the classpath. How shall you do that? One of the following ways:

 

1. Set the operating system CLASSPATH environment variable to have the project folder "e:\myProject".

2. Set the operating system CLASSPATH environment variable to have a jar file "e:/myProject/client.jar", which has the Set.class file in it.

3. Run it with -classpath or -cp option as given below:

c:\>java -cp c:/myProject com.xyz.client.Pet

OR

c:\>java -classpath c:/myProject/client.jar com.xyz.client.Pet

 


Related Discussions:- How to execute class with a main() method in a package

Questions pseudocodes, 1. Write the pseudocode to get the input of 10 integ...

1. Write the pseudocode to get the input of 10 integers from the user and add them up and output the total. (4 points) 2. Compute the output of following pseudocode. Assume that

Area under the curve, write a program to find the area under the curvey y=f...

write a program to find the area under the curvey y=f(x) between x=a and x=b.integrate y=f(x) between the limits of a and b. the area under a curve between two points can be found

Write a program to perform multiplication and division, Write a program to ...

Write a program to perform multiplication and division in java? Of course Java could also do multiplication and division. Because most keyboards don't have the times and divisi

What is a variable in java program, What is a variable in Java program? ...

What is a variable in Java program? It's a memory location. Memory location is given some name. Memory location is being assigned some value. Value may change o

Posting on a wall, Viewing a User's Wall Where your project allows you t...

Viewing a User's Wall Where your project allows you to view a user's profile, your ZHTML must provide the following capabilities: 1. Provide a Wall for that user profile, dis

Develop a customer relationship management system, You are a newly recruite...

You are a newly recruited programmer, working for an IT company. This company won a contract to develop a Customer Relationship Management System (CRM) for a major retailer. The CR

Benefits of spring framework, Benefits of Spring framework : Spring can...

Benefits of Spring framework : Spring can effectively organize your middle tier objects as given in the diagram above, whether or not you select to use EJB. Applications create

Performance of a java application, How can I improve the performance of a ...

How can I improve the performance of a java application , describe the java optimization techniques?

What is the difference between internet and intranet, What is the differenc...

What is the difference between Internet and Intranet ? Intranet and internet are 2 domains which are extremely a like but frequent segregated in order to manage security. Inter

What is struts validator framework, Struts Framework gives the functionalit...

Struts Framework gives the functionality to validate the form data. It can be use to authenticate the data on the users browser as well as on the server side. Struts Framework emit

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd