aspose file tools*
The moose likes Beginning Java and the fly likes Should this code work in NetBeans? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Should this code work in NetBeans?" Watch "Should this code work in NetBeans?" New topic
Author

Should this code work in NetBeans?

andrew dale
Ranch Hand

Joined: Aug 15, 2011
Posts: 45
Heres the code:



It was part of Head First Java book, code magnet test chapter 2.

I also have a question or two about it:

boolean Tophat = true;
boolean snare = true;

I thought boolean was just to get a True/False answer... What does that mean when you making it = to true?

Thank you. This forum and everyone apart of it has been a godsend to me.

edit-------

This is what I get when I run the project


run:
java.lang.NoSuchMethodError: main
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)

You'll never achieve your goals if you don't take that chance, so go pry open that trunk and get those amps.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38334
    
  23
Yes, you can set a boolean to true or false like that.

I would prefer to see if (b) ..., not if (b == true) ... ==true and ==false should never, in my opinion, be used.

You would need a class with a main method, and the main method calls the other code.
andrew dale
Ranch Hand

Joined: Aug 15, 2011
Posts: 45
Campbell Ritchie wrote:Yes, you can set a boolean to true or false like that.

I would prefer to see if (b) ..., not if (b == true) ... ==true and ==false should never, in my opinion, be used.

You would need a class with a main method, and the main method calls the other code.


Ok, so you cant get the true/false result without boolean is that what your saying?

I also don't understand what you mean by I need a class with a main method? Do i have to create a separate file? If you can elaborate it would be greatly appreciated.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

andrew dale wrote:This is what I get when I run the project


run:
java.lang.NoSuchMethodError: main
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)

That's probably because you are trying to run class DrumKit, whereas you should run class DrumKit.DrumKitTestDrive - that's the class with the main method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Campbell Ritchie wrote:
I would prefer to see if (b) ..., not if (b == true) ...

Correct! because sometime by mistake you may type if(b = true) and also if(b) is looks better than if(b == true) . is not it?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38334
    
  23
andrew dale wrote: . . . Ok, so you cant get the true/false result without boolean is that what your saying? . . .
Not at all. The reserved words true and false are boolean literals, which means they count as booleans themselves.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14102
    
  16

Did you really mean to put the class DrumKitTestDrive inside class DrumKit, or is that a mistake?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Should this code work in NetBeans?