Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 1st, 2008, 03:16 PM
rdunne rdunne is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 114 rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level)rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level)rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level)rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level)rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level)rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 15 h 18 m 50 sec
Reputation Power: 24
Homework - Public Static Void Main()

I'm new to Java, and I was under the impression, led to believe that all Java programs begin with this:
Public Static Void Main()
However, I have seen many java programs that do not have this, which is confusing. Can someone tell me the circumstances that require this in a Java file? How do Java program run without this?

Reply With Quote
  #2  
Old January 1st, 2008, 03:55 PM
tagmanadvance's Avatar
tagmanadvance tagmanadvance is offline
Kage Bunshin
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2005
Location: The Seven Seas Of Rhye
Posts: 835 tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 21 h 2 m 18 sec
Reputation Power: 248
Send a message via AIM to tagmanadvance Send a message via Yahoo to tagmanadvance Send a message via XFire to tagmanadvance
Applets don't require a "public static void main (args[])". Classes also do not require it. It is only necessary if you plan on running your application as a program (hence, if its not an applet, it IS required).
Comments on this post
Yawmark agrees: But there's more to it than just applets.
__________________
"Java makes impossible things possible, but makes easy things difficult." - Somebody

Reply With Quote
  #3  
Old January 1st, 2008, 05:13 PM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 8,628 Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 8 h 30 m
Reputation Power: 2097
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
Quote:
hence, if its not an applet...


Or a web service. Or an EJB. Or a web application. Or any other type of application designed to be run inside a container or as a plugin (much more than just applets).

~
__________________
Yawmark
class Sig{public static void main(String...args){\u0066or(int
\u0020$:"vÌÈÊ\"¤¾Àʲ¬Æ\"v¤Î¤\"²¤¨¸¬Æ".to\u0043h\u0061rArray()
)System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
+(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}

Reply With Quote
  #4  
Old January 2nd, 2008, 01:17 PM
violetfrog violetfrog is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 1 violetfrog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 33 sec
Reputation Power: 0
The only Java programs that contain Public Static Void Main() the ones that actually run.

Since you can have many classes in a Java program, the one that actually runs the program is the one that will have the Public Static Void Main() in it. The others won't, but they are accessed by the Main program.

When you first start out learning Java, they give you short little programs to introduce you to the various parts and they all have the Public Static Void Main() in them. Then later, you get introduced to the whole point of the object oriented programming and you have various other classes that don't have it in them. Can be confusing at first.

Make sense? hope that helps

Reply With Quote
  #5  
Old January 2nd, 2008, 01:39 PM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 8,628 Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 8 h 30 m
Reputation Power: 2097
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
Quote:
The only Java programs that contain Public Static Void Main() the ones that actually run.

Not quite. The "public static void main(String[] args)" method can be declared in any class or classes. Just because a class has that method does not mean that class must be run; only that it can be run. It's the method called by the JVM on the class designated at startup time. Aside from that, it's a method just like any other.

~

Reply With Quote
  #6  
Old January 2nd, 2008, 01:56 PM
rdunne rdunne is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 114 rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level)rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level)rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level)rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level)rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level)rdunne User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 15 h 18 m 50 sec
Reputation Power: 24
Quote:
Originally Posted by tagmanadvance
Applets don't require a "public static void main (args[])". Classes also do not require it. It is only necessary if you plan on running your application as a program (hence, if its not an applet, it IS required).


OK. Reason why I am asking this is I am trying to build a J2ME application for Bluetooth using MIDlets, basically sending/receiving data between my laptop/mobile phone. In order to evaluate data sent from my mobile, I need to run stats on data received on my laptop server.
When I receive data back from my mobile, it is stored in a data buffer in my USB Bluetooth Adaptor. Can I assume that a Java app (one that resdes on my laptop server) will be able to access this data buffer via an API. Is my thinking correct?

Reply With Quote
  #7  
Old January 2nd, 2008, 08:34 PM
tagmanadvance's Avatar
tagmanadvance tagmanadvance is offline
Kage Bunshin
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2005
Location: The Seven Seas Of Rhye
Posts: 835 tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level)tagmanadvance User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 21 h 2 m 18 sec
Reputation Power: 248
Send a message via AIM to tagmanadvance Send a message via Yahoo to tagmanadvance Send a message via XFire to tagmanadvance
Quote:
Originally Posted by Yawmark
Or a web service. Or an EJB. Or a web application. Or any other type of application designed to be run inside a container or as a plugin (much more than just applets).

I forgot/didn't know about half of those. I guess I have never had a reason to look into them. Maybe I should for the sake of knowledge? Anyway...
Quote:
Originally Posted by rdunne
Can I assume that a Java app (one that resdes on my laptop server) will be able to access this data buffer via an API. Is my thinking correct?
One would assume so, but there is no way to tell without first examining the API.

Last edited by tagmanadvance : January 2nd, 2008 at 08:37 PM.

Reply With Quote
  #8  
Old January 2nd, 2008, 09:47 PM
Anyday1 Anyday1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 6 Anyday1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 51 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by rdunne
OK. Reason why I am asking this is I am trying to build a J2ME application for Bluetooth using MIDlets, basically sending/receiving data between my laptop/mobile phone. In order to evaluate data sent from my mobile, I need to run stats on data received on my laptop server.
When I receive data back from my mobile, it is stored in a data buffer in my USB Bluetooth Adaptor. Can I assume that a Java app (one that resdes on my laptop server) will be able to access this data buffer via an API. Is my thinking correct?


If you want to play a game of 'Theory', yeah, definitely possible... Honestly speaking though, I don't think you'd have anywhere near the experience to try attempting that yet.

I have no experience with bluetooth, but chances are you'd have to find out where the data gets sent and retrieve it or in worse case scenario, reverse-engineer the drivers packaged with the device... and not even mentioning the fact that it's not going to be written in java, but doing all that is not going to be easy.

So the first couple of things on your to do list is:

A) Figure out how your computer communicates with the device.
B) Recode/Convert all of the algorithms you need in java, which may not necessarily be possible.
C) Code your own interface, so your program can understand the input.


EDIT:::

If it stores itself in a databuffer, and you know where this is in memory, you can try to retrieve it... However, I've no idea how to do this.

I'm talking completely out of my ***, but my guess is it's going to be awhile before you're going to be interfacing yourself with those things.

Reply With Quote
  #9  
Old January 3rd, 2008, 07:46 AM
calpol2004's Avatar
calpol2004 calpol2004 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 255 calpol2004 User rank is Sergeant Major (2000 - 5000 Reputation Level)calpol2004 User rank is Sergeant Major (2000 - 5000 Reputation Level)calpol2004 User rank is Sergeant Major (2000 - 5000 Reputation Level)calpol2004 User rank is Sergeant Major (2000 - 5000 Reputation Level)calpol2004 User rank is Sergeant Major (2000 - 5000 Reputation Level)calpol2004 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 5 Days 13 h 2 m 16 sec
Reputation Power: 49
Send a message via MSN to calpol2004
Quote:
Originally Posted by rdunne
I'm new to Java, and I was under the impression, led to believe that all Java programs begin with this:
Public Static Void Main()
However, I have seen many java programs that do not have this, which is confusing. Can someone tell me the circumstances that require this in a Java file? How do Java program run without this?


let me help you understand what those properties mean:

public - this means other objects can access this classes data or access the method from outside the class. The alternative of this is "private" which means only other methods in the same class can call the method (kind of irrellevant for main, it's never really called again).

static - This means that theres only one copy of the thing your declaring static in memory and you don't need to create an instance of the class. It's generally done because when the main method is executed you haven't actually created an instance of the main class. When the variables in a class are static if you create multiple instances of the class then they will share the same variables (alter one objects variable and you alter them all). A very useful but confusing feature of OOP .

Void - this is the methods return type. If the method is called from inside the class or outside or whatever, the caller may expect a value returned. Like when you call a mathematical function from a class, lets say some made up method like MathsClass.add1and2() returns an integer type (a number, 3). Void simply means it returns nothing. A main method is never called (or at least it shouldn't ) so void is usually used. This is confusing since languages like C (java is kind of a derivative of C) used to return 1 or 0 depending on whether an error occured.

Last edited by calpol2004 : January 3rd, 2008 at 08:02 AM.

Reply With Quote
  #10  
Old January 3rd, 2008, 11:20 AM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 8,628 Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level)Yawmark User rank is General 17th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 8 h 30 m
Reputation Power: 2097
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
Quote:
public - this means other objects can access this classes data or access the method from outside the class.

Outside the package or subclasses. Protected and package-private (i.e., default access) members can also be accessed outside the class. Only the private modifier restricts access to within the class.

Quote:
It's generally done because when the main method is executed you haven't actually created an instance of the main class.

For the JVM to call the main() method of a class at startup, the method must be declared static. This is done out of convention and so the JVM doesn't need to instantiate the class.

Quote:
A main method is never called

Sure it is.

Quote:
or at least it shouldn't...

There is no general reason why it shouldn't be called. Once again, a "public static void main(String[] args)" method is just like any other public, static method that takes a string array as its only parameter and returns void. There may be a perfectly good reason to call main(); e.g., an application wrapper calling an underlying program, etc.

Quote:
...so void is usually used.

For the main() method to be called by the JVM at startup, it must return void. Also note that frequency with which a method will be called is orthogonal to whether or not that method returns (or should return) void.

~

Last edited by Yawmark : January 3rd, 2008 at 11:27 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Homework - Public Static Void Main()


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT