473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Java: public static main error

Dököll
2,364 Expert 2GB
Does public static main encapsulate a class?

Meaning:

Expand|Select|Wrap|Line Numbers
  1.  
  2. public static void main(String[] args) {
  3. // public class Myclass
  4. // code here to do other stuff
  5.  
  6. // Am I encapsulating the class here?  
  7.  
  8. System.out.println(className);
  9.  
  10. }
  11.  
  12. It probably does no make sense the way I am asking this.
  13.  
  14.  
  15.  
  16.  
I am getting a logical error when attempting to run code. Nothing happens.

Tell what you see. Thanks!

Dököll
Nov 14 '07 #1
9 1763
Does public static main encapsulate a class?

Meaning:

Expand|Select|Wrap|Line Numbers
  1.  
  2. public static void main(String[] args) {
  3. // public class Myclass
  4. // code here to do other stuff
  5.  
  6. // Am I encapsulating the class here?  
  7.  
  8. System.out.println(className);
  9.  
  10. }
  11.  
  12. It probably does no make sense the way I am asking this.
  13.  
  14.  
  15.  
  16.  
I am getting a logical error when attempting to run code. Nothing happens.

Tell what you see. Thanks!

Dököll


Have u encapsulated your main function in a class?
Nov 14 '07 #2
Dököll
2,364 Expert 2GB
Have u encapsulated your main function in a class?
all attempted but nothing works. For now I have this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Game 
  3. {
  4.     private Parser parser;
  5.     private Room currentRoom;
  6.     private View currentView;
  7.  
  8.  
  9.  
  10. public static void main(String[] args)
  11. {
  12.  
  13.    Game game= new Game();
  14.  
  15.    game.start();
  16.  
  17. }
  18.  
  19.  
Encapsulating, or having the last braket further down did not work. Above says it cannot find symbol start()

Should the code still run using a compiler, perhaps that't it?

I believe main is there to give it the ability to be view in a browser.
Nov 14 '07 #3
r035198x
13,262 8TB
all attempted but nothing works. For now I have this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Game 
  3. {
  4.     private Parser parser;
  5.     private Room currentRoom;
  6.     private View currentView;
  7.  
  8.  
  9.  
  10. public static void main(String[] args)
  11. {
  12.  
  13.    Game game= new Game();
  14.  
  15.    game.start();
  16.  
  17. }
  18.  
  19.  
Encapsulating, or having the last braket further down did not work. Above says it cannot find symbol start()

Should the code still run using a compiler, perhaps that't it?

I believe main is there to give it the ability to be view in a browser.
The main method is the entry point of the program. Your game class does not have a method called start like the compiler said so you can't call it. You are also missing a closing bracket.
Nov 14 '07 #4
JosAH
11,448 Expert 8TB
all attempted but nothing works. For now I have this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Game 
  3. {
  4.     private Parser parser;
  5.     private Room currentRoom;
  6.     private View currentView;
  7.  
  8.  
  9.  
  10. public static void main(String[] args)
  11. {
  12.  
  13.    Game game= new Game();
  14.  
  15.    game.start();
  16.  
  17. }
  18.  
  19.  
Encapsulating, or having the last braket further down did not work. Above says it cannot find symbol start()

Should the code still run using a compiler, perhaps that't it?

I believe main is there to give it the ability to be view in a browser.
What you're doing is this: a Game object encapsulates a parser, a currentRoom
and a currentView; they're members of a Game class object. main() is just an
entry point to get your program going. It doesn't have anything to do with browsers.
When you start your Game class on the command line, the jvm checks whether
or not your Game class has a main() method with the correct signature; if so,
that's where your program starts. Your Game class doesn't have a 'start()' method
so javac starts whining at you for that.

I don't understand your last question: compilers have nothing to do with this.

kind regards,

Jos

ps. there's a syntax error in your class: add a last '}'
Nov 14 '07 #5
Dököll
2,364 Expert 2GB
What you're doing is this: a Game object encapsulates a parser, a currentRoom
and a currentView; they're members of a Game class object. main() is just an
entry point to get your program going. It doesn't have anything to do with browsers.
When you start your Game class on the command line, the jvm checks whether
or not your Game class has a main() method with the correct signature; if so,
that's where your program starts. Your Game class doesn't have a 'start()' method
so javac starts whining at you for that.

I don't understand your last question: compilers have nothing to do with this.

kind regards,

Jos

ps. there's a syntax error in your class: add a last '}'
Thanks to you both, I think I read the book wrong, I thought start was a reservred word/verb which when called, whatever if within the main { } would execute in a browser. That main was the engine that makes available the results of the code, when compiled, in a browser.

So I thought having main in the code, I was having a problem when the code ran through BlueJ, the compiler I am using.

But, just as I would for an HTML file, where I'd click and I get data through a browser, shouldn't public static void main do it. It sounds like that what the book is saying. I'll look again. I think I need to really understand what main does... But tell what you think. Thanks again for replying, guys, really nice.

In a bit!

Dököll
Nov 16 '07 #6
JosAH
11,448 Expert 8TB
But, just as I would for an HTML file, where I'd click and I get data through a browser, shouldn't public static void main do it. It sounds like that what the book is saying. I'll look again. I think I need to really understand what main does... But tell what you think. Thanks again for replying, guys, really nice.

In a bit!

Dököll
You really think too much of main; it is just a static method. When you start up
the JVM giving it a class; the JVM tries to load that class and searches for a
static void main(String[] args) { ... } method. If it finds it it calls it given the rest
of the command line arguments. From there the entire circus starts.

When you want to do things in a browser you either create an Applet or JApplet
(check the API documentation). They run on the client side in a Java enabled
browser or you have to create 'server pages' JSPs and/or Servlets that run on a
server and pass html pages to the browser on the client side.

kind regards,

Jos
Nov 16 '07 #7
Dököll
2,364 Expert 2GB
You really think too much of main; it is just a static method. When you start up
the JVM giving it a class; the JVM tries to load that class and searches for a
static void main(String[] args) { ... } method. If it finds it it calls it given the rest
of the command line arguments. From there the entire circus starts.

When you want to do things in a browser you either create an Applet or JApplet
(check the API documentation). They run on the client side in a Java enabled
browser or you have to create 'server pages' JSPs and/or Servlets that run on a
server and pass html pages to the browser on the client side.

kind regards,

Jos
Yes I think I am...

I will be doing more reading on that. I am going to check the API documentation as you said, although I suspect it may be above my head. Will keep you posted.

You have a wonderful week-end!

Thanks!

Dököll
Nov 17 '07 #8
JosAH
11,448 Expert 8TB
Yes I think I am...

I will be doing more reading on that. I am going to check the API documentation as you said, although I suspect it may be above my head.
It isn't; the API documentation simply documents all the classes in the Java SE
core set. It also documents every method and member variable. You should
have the API docs open next to your IDE or whatever. There's no need to guess
or hack or whatever; when in doubt: read the API docs first.

In the Java Articles index you'll find a link from where you can download the
entire API documentation. Download it, it's worth every single byte it takes on
your hard disk drive.

kind regards,

Jos
Nov 18 '07 #9
Dököll
2,364 Expert 2GB
It isn't; the API documentation simply documents all the classes in the Java SE
core set. It also documents every method and member variable. You should
have the API docs open next to your IDE or whatever. There's no need to guess
or hack or whatever; when in doubt: read the API docs first.

In the Java Articles index you'll find a link from where you can download the
entire API documentation. Download it, it's worth every single byte it takes on
your hard disk drive.

kind regards,

Jos
Every single byte, eh:-)

Will take a closer look...

In a bit!

Dököll
Nov 19 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: netgeni59 | last post by:
Hello fellow C# friends, I am trying to write a C# TCP client that was formerly written in Java. The server must still remain in Java. I cannot get text data from the C# client to be received...
2
by: Michael | last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP, I am unable to find out why the "Build for Debug" option within Stored Procedure Builder is not enabled on Java stored...
3
by: PieMan2004 | last post by:
Hi, ive been looking for a solid java community to help me when im tearing out my hair :) Basically ive constructed a GUI that has to represent the same look and functions of the typical windows...
6
by: Rhino | last post by:
I'm trying to debug a simple Java UDF written in the DB2General style within Eclipse. I'm getting a java.lang.UnsatisfiedLinkError when I execute the set() method in the UDF. I know that the...
0
by: r035198x | last post by:
Overriding therefore allows you to use the same method name to refer to differently implemented methods. Here is an example using the famous shapes example. class Shape { public Shape()...
3
by: shiniskumar | last post by:
Question 1 class JMM102 { public static void main(String args) { for (int i = 0; i<5 ;i++) { switch(i) { case 0: System.out.print("v ");break; case 1: System.out.print("w "); case 2:...
1
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
5
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is...
2
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.