Setting array in contructor Programming Software Development by Anonymusius … because I replaced it with an automatic version in the contructor. What would be the correct syntax to set the class… default contructor? Programming Software Development by brokenbentou im a astudent @ LTHS, in my forst year of Java, how do i make a default, and non-default contructor, and how to they work? Contructor and threads Programming Software Development by neutralfox Hello everyone, Can someone please explain to me the meaning of the code below: [code] public class Client extends javax.swing.JFrame implements Runnable { // constructutor public Client( String host, int port ) { . . . new Thread( this ).start(); } public void run() { something.... } } [/code] … Re: Contructor and threads Programming Software Development by JamesCherrill this represents the object whose method is currently executing. A Thread is a separate stream of execution (eg if you have a dual processor, you can execute two threads simultaneously). Your class implements the Runnable interface, which consists simply of a public void run() method. So new Thread(this) creates a new thread in which code … Re: Contructor and threads Programming Software Development by neutralfox Thanks for the answer James. But what happen if i run the program on a single core processor? Another question: Can you please explain the code that represent "this" in the above example. does new Thread(this).start () equivalent of new Thread(Client).start() ? You said this represents "code from your current object ", isn… Re: Contructor and threads Programming Software Development by JamesCherrill If you have a single processor the two (or more) threads will share it according to some process that you don't get involved with. In particular, if one thread has to wait (eg for user input) the other will be able to continue running. "this" represents the current instance of the class. In your example new Thread(Client) would try … Re: Contructor and threads Programming Software Development by neutralfox I understood now !! I got one last question on synchronisation, I think its better to start it in a new thread. Re: Contructor and threads Programming Software Development by neutralfox Hello, I got one last. I don't know if you remember me, but I was developing a chat system. And at the beginning my application was freezing because of the while loop () when the server listen. You told me to use thread and everything works pretty fine. The code above in another way to solve the freezing situation, isn't it? That's we could put … Re: Contructor and threads Programming Software Development by JamesCherrill Ah, now I see your question! Yes, the new thread means that the while loop can wait for connections in its thread while the user interface continues to do its stuff in its own thread. You don't necessarily need to use synchronised - in the case above you probably don't. You add a synchronised statement when you determine that there is a danger of… Re: Contructor and threads Programming Software Development by neutralfox Ok, Network programming in Java is so interesting. Thanks for the info. Thanks a lot for your help James. Re: Contructor and threads Programming Software Development by BestJewSinceJC NeutralFox - I'm glad you solved your problem - James is correct in saying "If you have a single processor the two (or more) threads will share it according to some process that you don't get involved with". As an example of that, consider the fact that you can use your email, play music, and IM all at the same time. Re: Contructor and threads Programming Software Development by neutralfox Okie .. Hello BJSJC !! I got a quad core extreme at home !! If I used thread in my program it should works faster on my PC but its just a small chat application, i don't think that I will see the difference on a quad or on a single core computer. Anyway, thanks for the answer. Re: Contructor and threads Programming Software Development by BestJewSinceJC Yes, you are correct - you would not notice a difference. However, if you started playing games, chatting, listening to music, and downloading files off the web, you might notice a difference between a single core and quad core machine. Also, FYI, each time you start a Java application, the main method is run in a new thread. Re: Contructor and threads Programming Software Development by neutralfox Thanks for the info dude. I got some more questions ... lol, a bit tired today, tomorrow I will post a new thread. A+ Re: Contructor and threads Programming Software Development by JamesCherrill Yes, the reason for multiple threads in Java is very rarely for performance , it's usually to allow the UI the run while something else is happening in the background, or to support multiple remote access sessions simultaneously. As BJSJC says you always get a new thread for your main(...) method at startup, but also Swing starts its own new … Contructor and destructor function Programming Software Development by Sohelp How i can use contractor and destruction function in program? I do not understood about this two function. Please help me ...... Your Regard Sohel Rana Bangladesh Contructor and Destructor function Programming Software Development by Sohelp How i can use contractor and destruction function in program? I do not understood about this two function. Please help me ...... Your Regard Sohel Rana Bangladesh Re: Contructor and Destructor function Programming Software Development by gerard4143 Posting every query that pops into your head is a misuse of this forum. Re: Contructor and destructor function Programming Software Development by Stefano Mtangoo Since your posts show you are starting C++, just get your head on [URL="http://www.cplusplus.com/doc/tutorial/"]this tutorial[/URL] and many of your questions will get answered Re: Setting array in contructor Programming Software Development by Grunt You need to use for loops or strcpy function inside constructors. Re: Setting array in contructor Programming Software Development by Anonymusius [quote=Grunt;246025]You need to use for loops or strcpy function inside constructors.[/quote] I'm sorry, I don't get what you mean. I know what loops and strcpy is but I don't see yet what you mean with it. Re: Setting array in contructor Programming Software Development by ~s.o.s~ Maybe something like [code] #include <iostream> using namespace std; class hello { private: char array[4][5]; public: hello(); void get_hello() { cout << "From the function: array[2][2] = " << "'" << array[2][2] << "'" << endl; } } hi; hello::hello() { … Re: Setting array in contructor Programming Software Development by Anonymusius No, I want to store ascii sprites for an (very) simple game in an object for the sake of data hiding. I have for example this sprite(not made by me): [code] " ##### ", " # # ", " # # ", " # # # ", " # # ## ", " # # &… Re: Setting array in contructor Programming Software Development by ~s.o.s~ Maybe you can do a workaround like this [code] #include <iostream> using namespace std; class Mine { char pattern [6][30] ; public: Mine () { char buffer [6] [30] = {" ##### ", " # # ", &… Re: Setting array in contructor Programming Software Development by Anonymusius I solved it with the following code: [code] strcpy(array[0]," ###"); strcpy(array[1],"####"); strcpy(array[2],"####"); strcpy(array[3],"####"); [/code] Thanks for taking the time to respond and help me further with this. Re: Setting array in contructor Programming Software Development by killdude69 The code doesn't work because you set the array to be multi-dimensional (e.g. array[5][5]). You did not set all of the arrays. The array code should be: [CODE] int array[2][2] = {1, 1, 1} {1, 1, 1} {1, 1, 1}; cout << "array[0][2] == 1"; [/CODE] Re: default contructor? Programming Software Development by thines01 A default constructor is one that takes no parameters and sets the initial values for the class. [CODE] public class CSomething { public int iFred; public CSomething() { // default constructor iFred = 0; } public CSomething(int iSetFred) { //non-default iFred = iSetFred; } } [/CODE] Re: default contructor? Programming Software Development by JamesCherrill [QUOTE=thines01;1038027]A default constructor is one that takes no parameters and sets the initial values for the class. [/QUOTE] Not exactly. Constructors can have arguments, or no arguments. If you do not create any constructors, the compiler gives you a "default" constructor which is a no-args constructor that simply calls the … Re: default contructor? Programming Software Development by brokenbentou [QUOTE=thines01;1038027]A default constructor is one that takes no parameters and sets the initial values for the class. [CODE] public class CSomething { public int iFred; public CSomething() { // default constructor iFred = 0; } public CSomething(int iSetFred) { //non-default iFred = iSetFred; } … Re: default contructor? Programming Software Development by JamesCherrill No. A default constructor just calls the superclasses' no-args constructor. If you want to do any special initialisation you need to write a constructor (which may or may not take arguments)