LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-20-2009, 05:46 AM   #1
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Rep: Reputation: 50
helper methods + System.out.println() not working. (caution- JAVA question)


A quick disclaimer before I begin my question- the last couple of times I've asked a Java question here I've been flamed. I realise that Java is the scum of the earth and there are much better languages to pick. I know. I'm constrained by my university. Just answer the question please, or stay quiet- please don't waste my time.

To the question: I have methods called by other methods and I want to check if they are actually doing their thing- quickly and easily, using System.out.println(). I want to know if there are issues with helper methods printing to the commandline/terminal or if there is something seriously wrong with my code. Since this is for homework I won't post my actual code, but the code to do with where the issue is.

Code:
public class MyClass 

   public MyClass() { //generic constructor. 
   }

   public buildThis() { 
//take an input and build it into the data stucture. 

     int foo = usefulMethodWhichReturnsInt();
     System.out.println("This prints fine.");  //1

   }
   public usefulMethodWhichReturnsInt() {
      System.out.println("Will this print?"); //2
      return 0; 
   } 

   public static void main(String args[]) {
      MyClass bar = new MyClass;
      bar.buildThis();
      System.out.println("This will also print."); //3
}
So yeah, will the usefulMethod be able to print something on the command line?

Thanks everyone in advance.

titanium_geek
 
Old 05-20-2009, 05:48 AM   #2
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Original Poster
Rep: Reputation: 50
Ok, I added another trial method and it worked. (Grrr.) This means there are probably other bugs present in my code, sigh.

Fixed it. I think it's because my logic was really bad. Remembered to use if NOTs instead of ifs.

TG

Last edited by titanium_geek; 05-20-2009 at 06:22 AM.
 
  


Reply

Tags
java, print


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System.out.println("Hello, world."); rkirk LinuxQuestions.org Member Intro 1 04-16-2009 09:56 AM
difference between Java compare and compareTo methods kpachopoulos Programming 2 09-19-2004 04:08 AM
println question AMMullan Programming 2 04-18-2004 07:38 AM
java -- methods -- please help Laptop2250 Programming 2 12-13-2003 12:46 AM
system.out.println() not working in servlet, Tomcat Ethan Programming 7 07-24-2002 11:40 AM


All times are GMT -5. The time now is 07:25 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration