473,569 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Main class constructor !

I am new to Java.

Since the "main" class has the main() function it it, is this called
before the constructor, or is a constructor totally irrelevant for a
main class, since you never "new" it ?
I am used to C++ whare main exists outside any class.

I have a test "main" class and it appears the constructor is never
called ?

Confused !

TIA
Remove the SPAMBLOCK from my email address to reply.
Jul 17 '05 #1
2 7601
Alan.J.Thackray wrote:
I am new to Java.

Since the "main" class has the main() function it it, is this called
before the constructor, or is a constructor totally irrelevant for a
main class, since you never "new" it ?
I am used to C++ whare main exists outside any class.

I have a test "main" class and it appears the constructor is never
called ?


That is correct. Note that main() is declared static. In this context,
static means the same as it does in C++; a static method does not need
to be invoked on an instance of a class.

Many people who wish to stay in the OO paradigm will write main()
similar to the following:

public class MyClass
{
// ...other code...

public static void main(String args[])
{
final MyClass myInstance = new MyClass();
myInstance.go() ;
}
}

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #2

"Alan.J.Thackra y" <al************ *@SPAMBLOCK.blu eyonder.co.uk> wrote in
message news:jq******** *************** *********@4ax.c om...
I am new to Java.

Since the "main" class has the main() function it it, is this called
before the constructor, or is a constructor totally irrelevant for a
main class, since you never "new" it ?
I am used to C++ whare main exists outside any class.

I have a test "main" class and it appears the constructor is never
called ?

Confused !

TIA


Sounds like you actually named your class "main" ????
You should steer clear of class names like that to avoid confusion.
Name a class "Bill" or "George" - even "Sue" - use proper case to follow
convention, and keep away from reserved words.
--- main is a static method, which means you do not need to create an
instance of that class to run the method.
main is *not* a constructor, its a special method.
HTH

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.807 / Virus Database: 549 - Release Date: 12/7/2004
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1765
by: Henry Jordon | last post by:
hello I was wondering if someone could help me get a main going on this project I've completed the header file that the professor started us on but not really sure how to get the main going. If someone could please give me some pointers it would greatly be appreciated. Again thanks for the help. Henry headerfile:
4
2933
by: wongjoekmeu | last post by:
Hello All, >From a book where I have learned C++ it says that each application must have at least one function which is the main() function. Now I have the source code of a C++ program from someone else. But whatever I am doing to search for the main function, I can not find it. There is a very short description of the program in a Readme...
6
1627
by: Marc | last post by:
I am just starting out teaching myself C#, and I have come accross a confusing point in my book. It seems that any class can have a Main() function, but what does that mean? Is the Main() function for a class called whenever an instance of that class is created, or would it be there for another purpose? I already know that one of the Main()...
2
12009
by: Bill D | last post by:
In a simple Windows forms application, the main form is called Form1. Within this form's class, I refer to the the running instance of this main class as "this" as in this.Text = "NEW TEXT" I want to do something like change this Text on the Form1 window from within another class. Trying Form1.Text = "TEXT FROM CLASS" or...
1
3590
by: BillZondlo | last post by:
Can someone look at this and tell me why, when I call this from my main app, it displays fine (fades form in and out) but then before my main app displays, I see other dialog boxes flash monentarily on the screen and this delays the main app display? Here is the fade which I compile to a dll and call from my main app: using System; using...
2
3329
by: Legendary Pansy | last post by:
Hello, I'm trying to accomplish the impossible by trying to do something equivalent of this example found here http://www.c-sharpcorner.com/Code/2003/Dec/DialogTutorial.as Starting with "Listing 2 - Changing the constructor of the modeless dialog to accept the parent object:" line and go onwards is what I'm trying to do Basically, there is...
2
2594
by: Defected | last post by:
Hi, How i can implement a main function with this Binary Search Tree. thanks for help. is this code corrected ? #include<iostream>
3
3923
by: Jon | last post by:
My main form opens up another form, and from this other form, I'd like to access things in the main form. The problem is that although I know the name of the class of the main form (FormMain) I don't know the name of the instance of it since it was generated by the VS C# Express 2005 designer. In program.cs, I notice that there is the line:...
4
7886
by: lilyumestar | last post by:
I have project I have to do for class. We have to write 4 different .java files. Project2.java HouseGUI.java House.java HouseSorting.java I already finish House.java and I need to work on both the Project2.java and HouseGUI.java Here are the requirements for those two. The GUI Create a class called HouseGUI which extends JFrame. It...
0
7609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.