• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Help me in getting the ans

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I wanna to write a method name inside the same method without using System.out.println();
example:---
void hello(){
//i wanna to write "hello" here
//without using System.out.println("help");
}

plzzzzz let me know the Ans
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you want to print you can use
System.out.print(yourString);
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know of any other way to output to the console apart from using the PrintStream (out) in the System class. Or have I misunderstood the question? It seems like a bizzare thing to do. Why can't you use System.out.println()?
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you trying to use other ways to log instead of the System.out classes? If so, there is also the java.util.logging.Logger class or import the commons logging jar and use the Log class in there.
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are trying to dynamically determine the method name that you're in, you could call a Thread.dumpStack, get the stack trace, and parse through that to determine what method you're in. This is an expensive operation, though....
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use a logger to write.
I think if you want to write your method name inside the method then you have to use the reflection.

example
(you need a logger to write it like java.util.logger)
//if hello is the only method then this code would do
somelog(this.getClass().getMethods()[0].getName()

but if more than one method then is it little bit complicated. I will not confuse you more but If you do need to know more let me know.

Hope this helps
Kareem
 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic