• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Eclipse doesn't show println() in console

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

I'm just start learning java and met the following problem:

in my program I have only one method main (String[] args) and when I make another part of program in {}, it doesn't show the result in console

Unfortunately, I can't paste it here, just attached screenshot of Eclipse Workspace.

Please, help me to solve this problem.
Thank you.
Untitled.png
[Thumbnail for Untitled.png]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrey Programmer wrote:
in my program I have only one method main (String[] args) and when I make another part of program in {}, it doesn't show the result in console



Please explain what what you mean by the part in bold. I can only guess from the screen shot that you made it as part of an instance initializer. Can you confirm this?

And if so, can you show use the code that does the instantiation of the Program class?

Henry
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please, refer to the attached file for the text of program.

Eclipse don't show result of out.println(r);

out.printf("a = %d\nb = %d\n", a, b);

out.printf ("d=%f", d);

out.printf("%1$tY-%1$tB - %1tD", now);

Unfortunately, I can't attach niether .jar niether .txt file.

If it is possible, I can forward it to e-mail or using skype.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrey Shestakov wrote:Unfortunately, I can't attach niether .jar niether .txt file.


You don't need to. You should post the relevant part of the program in your replies being sure to UseCodeTags (⇐ that's a link).

If it is possible, I can forward it to e-mail or using skype.


Again, you should post any relevant information in the replies. Offline communications is frowned upon.
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyway, you are right.

I'm just using one method main public static void main(String[] args) as instance initializer.
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the full code:

 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrey Shestakov wrote:
I'm just using one method main public static void main(String[] args) as instance initializer.



No. You have one main() method, and three instance initializers. And since you don't actually create any instances of Program, the instance initializers will not be executed.

Henry
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry, instance=object, am I right?

Can I reate initializer of instance in such way:

public static void A(), for example? Using method "A".

 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can create methods. But you need to actually call those methods to see any result.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Agreed. Now you have four static methods -- main(), A(), B(), and C(). The JVM will call main() -- your code (meaning the code in main()) must call the others.

Henry
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, should I see the result in the code above for these four methods?

Now no any mistakes but anyway I don't see results except discribed using method main ().
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrey Shestakov wrote:So, should I see the result in the code above for these four methods?

Now no any mistakes but anyway I don't see results except discribed using method main ().



Correct. You should only see the output for the main() method... as there isn't any code in your program that calls the other three methods.

Henry
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I called them with such code in main():

Program.A();

Program.B();

Program.C();

Is it correct? Is there another common way to do it?
Thank you.
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That should work but because all of this happens inside of your Program class the use of "Program." is unnecessary. You can just call "A();".
 
Andrey Shestakov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your kind help!
 
You got style baby! More than this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic