• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help me in getting the ans  RSS feed

 
Shaikh Riyaz
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want to print you can use
System.out.print(yourString);
 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • 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()?
 
brad balmer
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • 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....
 
Kareem Qureshi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!