Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 24-07-2005, 11:52 AM   #1 (permalink)
Broken In
 
Join Date: Oct 2004
Posts: 162
Default problem in java


i have jdk1.5

written simple program in java

class Pg1
{
public static void main(String[] args)
{


System.out.println("HI");
}
}


it is compling no problem

but when i run java Pg1

it give a exception java.lang "main" cannot be found

please help
shivi4 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 24-07-2005, 01:35 PM   #2 (permalink)
Alpha Geek
 
Satissh S's Avatar
 
Join Date: Mar 2005
Location: Chennai , India
Posts: 693
Default Re: problem in java

Quote:
Originally Posted by shivi4
public static void main(String[] args)
It sud be like this brother,
public static void main(String args[] )
Though the compiler doesn't detect it, its a logic error.
In the above line u declare that args is a variable of type string. So it shud be in this format String x[]. Java accepts all variables as String type. So u should explicitly convert other variables to String type b4 execution.
__________________
Call it Emacs,
Love it or Leave it.
Satissh S is offline  
Old 24-07-2005, 02:03 PM   #3 (permalink)
Wise Old Owl
 
deathvirus_me's Avatar
 
Join Date: May 2005
Location: Kolkata, India
Posts: 1,838
Default

Quote:
It sud be like this brother,
public static void main(String args[] )
Though the compiler doesn't detect it, its a logic error.
You need to refer more books dude .....both the statements work absolutely fine in java .....

and personally i prefer public static void main(String []args) .....

The only reason u cannot run a file is that u must have not added \bin to the system path ... for example if u've installed java in c:\jdk5 .. then u need to add this to the system path : c:\jdk5\bin ... things should run fine after that ....

But i'd suggest u to download JCreatorLE from here :

http://www.jcreator.com/download.php...ec26fe8226cca7

U should be able to easily compile/run programs ....it has a very easy-to-use interface ....

Also if u write a code with a single class then declare the class as public and name the code as the class name .......for now atleast ...

Code:
public class prg{
   public static void main(String []args){
      System.out.println("Hello!");
   }
}
save this as prg.java as i've declared the class public
deathvirus_me is offline  
Old 24-07-2005, 02:14 PM   #4 (permalink)
Wise Old Owl
 
siriusb's Avatar
 
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
Default

Nope, java acepts both way of declaring the main method. The problem is that your compiler has placed the .class file somewhere else while the interpreter is looking somewhere else. If u are using cmd line, then try to include path too. Or u may need to set the classpath. Click here to know how.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
siriusb is offline  
Old 25-07-2005, 07:06 AM   #5 (permalink)
Alpha Geek
 
Satissh S's Avatar
 
Join Date: Mar 2005
Location: Chennai , India
Posts: 693
Default

Oops! Helping others is fine but leading them wrong is bad! I regret it!
But im using J2se5 along with JBuilder.
__________________
Call it Emacs,
Love it or Leave it.
Satissh S is offline  
Old 26-07-2005, 10:07 PM   #6 (permalink)
Wise Old Owl
 
deathvirus_me's Avatar
 
Join Date: May 2005
Location: Kolkata, India
Posts: 1,838
Default

Hey how come noone uses JCreatorLE ????
deathvirus_me is offline  
Old 26-07-2005, 11:40 PM   #7 (permalink)
Alpha Geek
 
Satissh S's Avatar
 
Join Date: Mar 2005
Location: Chennai , India
Posts: 693
Default

@ deathvirusme: Where is it available from? is it free for download?
__________________
Call it Emacs,
Love it or Leave it.
Satissh S is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by abhidev
- by topgear
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 06:56 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2