• Post Reply Bookmark Topic Watch Topic
  • New Topic

Keyboard input using "import java.io.*;" OR "import java.util.scanner;"  RSS feed

 
Tim Kinnaird
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not even a Noob. I'm Pre-Noob. I have some limited previous knowledge of C++ that I've practically forgotten. A hack of the worst kind, I can't get far reading instructional books before I rip my hair out. The best way for me is to get the basic syntax down and just dive in doing some coding. When I hit a snag, I go to the net and fish for awhile, hit a book or two, find my answer and then push on again until my next snag.

Incredibly foolish Noob question #1

netbeans can't seem to find any of the packages (I think they are called) that I need for simple keyboard input. I get a squiggly red line under the "i" in the first line of a code that I copy/pasted from the net: "import java.io.*;" Same squiggly under the "i" for: "import java.util.Scanner;". Both won't compile or run.

A couple days ago I DL'd the latest JDK/Netbeans bundle from sun/oracle. I'm thinking that there is maybe a supplemental library of these so-called "packages" that I need? But I've poked around the sun/oracle DL site and it ain't jumpin' out at me.

I'm tryin' to find the easiest way to simply read in information from keyboard input.

Does anyone dare face the limitless ignorance of a noob?
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be easiest if you can paste a screenshot... you shouldn't get red squiggles on import statements unless you've got it set up wrong.

Have you created a Netbeans project and then a .java file ("Java Class") that you're editing?

Also, if you have any characters apart from a package statement before the import, it could cause problems.
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW the easiest way to get input (that works within Netbeans - you can type in the Output window by clicking on it) is with Scanner: do something like this:
s.nextLine() is a String, so obviously you could assign it to a String variable or whatever.

(I'm assuming you mean reading text from the keyboard, rather than detecting keypresses, which is a lot more involved.)
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I recommend if you are a real newbie/noobie, you don't use NetBeans. Use a decent text editor (eg Notepad2, Notepad++, jEdit on Windows®, or gedit or kate on *nix). M$ Notepad is not particularly good, and can introduce confusing errors by adding an extension.
Use the command line. There is something about that in the Java™ Tutorials; go through that section missing out the OS you don't use and the NetBeans version.

You might have a control character which you can't see preceding the "i" in "import" and the compiler will see that as an error. Both those packages you are looking for are standard sun/Oracle pacakges, which should be inside the file called rt.jar, which you will find inside your Java™ installation folder. So you ought not to have to download anything else at this stage.

More detailed instructions for running LP's little class
  • Open a command prompt or a terminal (start→all programs→accessories→command is one way to open it on Windows®)
  • mkdir java (or similar name. You can now use that folder for ever.)
  • cd java
  • Edit a file called HelloYou.java and save it in that folder. Note name of file and name of class should match.
  • javac HelloYou.java
  • java HelloYou
  • Beware: there is very little scope for spelling errors. Note where you have to miss out the .java extension.
     
    Tim Kinnaird
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you Luigi and Campbell Ritchie. It did have something to do with my setup in netbeans. I was able to input from keyboard. Maybe it's because i'm older but Java feels like its hurting way more than when I dabbled in C++. I've got some books coming from the library that I hope will help. I guess I'm alot older too. Maybe my gray matter is bogging down a bit.
     
    Eduardo Hernandez
    Greenhorn
    Posts: 13
    Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Get a copy of Kathy Sierra & Bert Bates Head First Java 2nd Edition and you'll see that Java isn't that complicated.
     
    Tim Kinnaird
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    yep, i've got that one and a dummies book on the way.
     
    Campbell Ritchie
    Marshal
    Posts: 56595
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    HFJ is a lot better than the other book you mentioned.
     
    Campbell Ritchie
    Marshal
    Posts: 56595
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    ... and don't use NetBeans of you are a complete beginner. The learning curve for the IDE is so steep it may prevent you learning Java™.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!