Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2007, 12:15 PM
Authorized User
 
Join Date: Jun 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default java program with package

hello....
how to compile a java program using package?????
e.g:
package mypack;
class balance
{
  System.out.println("u r in balance class");
}

class accountbalance
{
 public static void main(String args[])
 {
   system.out.println("u r ii accountbalance");
 }
}
...................................

plse anyone provide a soln to this?????


 
Old July 10th, 2007, 07:48 AM
Authorized User
 
Join Date: Oct 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,,
First of all you should place your java file in the folder with your_pachage_name under your root directory.

For compile use command: .....root_directory_name> javac your_package_name\your_class_name.java

For execution use command:.....root_directory_name> java your_package_name.you_class_name

Best,
Anna
 
Old July 13th, 2007, 04:05 PM
Authorized User
 
Join Date: Apr 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Additionally you can use -d switch of javac when compiling.

1. Go to directory where the .java file is present.
2. Execute javac <java_file> -d <destnation-directory>

This would compile the java file and place it in the destnation directory with package structure declared.

-eNJay
 
Old July 26th, 2007, 05:13 AM
Authorized User
 
Join Date: May 2007
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

save the file in the folder name with "mypack"

compile

run


http://studyjava.org/forums/
 
Old August 16th, 2008, 01:39 PM
Registered User
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ch.venki Send a message via MSN to ch.venki Send a message via Yahoo to ch.venki
Default

hi,

In packages we have to separate rule to compile the java programe.
Generally we use javac java-file-name.
but in packages we follow javac -d . file-name;
here -d is the destination where the class files to be stored.
and . refers current package.

In u'r programe u save as accountbalance.java because in that u declared the main function
 
Old September 19th, 2008, 09:15 PM
yulin11
Guest
 
Posts: n/a
Default

may be you can put you program in a single file. Then it can compile it for you automatically.

everyone can go far!www.codeuu.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
java program help chris1012 Java Basics 3 November 8th, 2007 09:35 AM
how to complie java program fafa Apache Tomcat 1 June 15th, 2006 05:10 AM
java program todeepak_g JSP Basics 0 January 25th, 2006 06:04 AM
java program todeepak_g JSP Basics 0 January 25th, 2006 06:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.