At PHONEKY, you will find many other apps and games of different genres, from Education and Entertainment to the Security and Navigation Java apps. To see the Top 10 best Java software for mobile phones, just sort apps by popularity.
![]()
Greenhorn
posted 6 years agoThis is my first crack at manipulating code. I'm trying to use TextIO.java instead of Java.Util.Scanner and use an integer type variable instead of a string. Why can't I simply declare my variable as an integer and output it in the same format? Here is my code:
import java.util.Scanner;
public class Main { public static void main(String[] args) { TextIO.putln('Hello World!'); TextIO.putln('What is your age?'); int age = TextIO.getInt(); TextIO.getInt(); TextIO.put('Your age is '); TextIO.putInt(age); } }
Ranch Hand
posted 6 years ago
Hi Allen
A very warm welcome to the ranch. Mistakenly you put the code inside the quotes instead of code tags. Anyways, this is the right one: What is TextIO class by the way? Never heard of it. Which package is it in?
lowercase baba
posted 6 years ago
As Mansukhdeep implied, there is no TextIO in the java API. That means you must have gotten it from somewhere else, and we don't know what that would be. Did you get it from a teacher? From a website?
also, saying 'why can't i do XYZ' is kind of pointless. What happened when you tried it? Either the compiler or the JVM will tell you EXACTLY why you can't do it. you will have gotten some kind of error message. Post the full and complete text, and perhaps we can help interpret it for you.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Greenhorn
posted 6 years ago
Thanks for your responses. Sorry for the ambiguity in my question and ignorance to the forum's features.
I downloaded the TextIO class from here. So far as I understand, the TextIO class is primarily for input/output and is an alternative to System.in and System.out. The beginner java book I am reading (don't have the title on me) suggested that it has some advantages over Scanner. The code I posted above is intended to get the user input (years old) and print out user's age. So long as I keep the variable a string my code runs fine, but when I try to make my 'age' variable an integer it fails to return my age to me after a carriage return during run-time. I hope this reply is more sufficient for explaining my issue. Any help is much appreciated.
Ranch Hand
posted 6 years ago
There is no putInt(..) method in the file you provided. Just check. I presume that must be the line you are having problems with.(line no. 14). If not, please share the exception / error details. That way we can guide you better.
Greenhorn
posted 6 years ago
That was precisely the line I was having a problem with. I am using Eclipse and missed the what should have been obvious reminder about the syntax error. Subsequently, I tried using TextIO.put() which states that an integer is a valid parameter but continued to get a '?' print out instead of the age when I ran it.
I google'd the TextIO.java class and looked at examples. In the examples I found, the author just used System.out.print for output and stuck to TextIO.java for getting user data. This was really my first attempt at problem solving in java and I hope it wasn't to painful for those of you that helped! So thanks and bear with my posts in the future!
Ranch Hand
posted 6 years ago
This was really my first attempt at problem solving in java and I hope it wasn't to painful for those of you that helped! So thanks and bear with my posts in the future!
No No! Not at all buddy. Don't ever hesitate to ask anything. We are all here to learn and help. So don't be formal.
I am using Eclipse and missed the what should have been obvious reminder about the syntax error.
If these are the first few of your tryouts at writing Java code, as you said, then my suggestion would be get rid of the IDE for now. Use a simple text editor to write the code yourself. Starting from package statements to imports, defining classes, methods instance variables etc. The reason is IDEs like Eclipse assist you with many things. So, you will never fully understand what is really happening under the hood. Write the code yourself in the editor, compile it and run from the command prompt. Make mistakes and get your hands dirty. Then you can home in on the exceptions and errors. It will not only teach you Java coding as such, but many other things that are a must know for a novice like classpaths, jar file issues etc.. Which book are you referring to by the way?
Ranch Hand
posted 6 years ago
Mansukhdeep Thind wrote:
I am using Eclipse and missed the what should have been obvious reminder about the syntax error.
If these are the first few of your tryouts at writing Java code, as you said, then my suggestion would be get rid of the IDE for now. Use a simple text editor to write the code yourself. Starting from package statements to imports, defining classes, methods instance variables etc. The reason is IDEs like Eclipse assist you with many things. So, you will never fully understand what is really happening under the hood. Write the code yourself in the editor, compile it and run from the command prompt. Make mistakes and get your hands dirty. Then you can home in on the exceptions and errors. It will not only teach you Java coding as such, but many other things that are a must know for a novice like classpaths, jar file issues etc.. Which book are you referring to by the way? That's really a good suggestion, but it's applicable only for people with huge level of motivation (or rich experience with other programming languages), rest won't be able to get out of this 'dirt' and abandon java at all. I personally started with Netbeans, and despite that IDE did 95% of work for me, there was a huge mass things that I need to learn first, besides classpaths, jar problems and starting jvm myself.
Greenhorn
posted 6 years ago
Interesting feedback. I appreciate the suggestions from both of you. Quick history since I think it may be relevant. I'm 30 now and began tooling with HTML when I was 15 or so, so I have a bit of grasp on simple text editing. Also, I worked in a machine shop and got introduced to the fundamentals of G-code for CNC machines which seemed to share some similarities with Java (and probably many other scripting languages?). Aside from that, I'm pretty much a newbie to Java and this is my first real crack at any programming language besides HTML (if that falls under the category).
About IDEs, I definitely see the advantage of them but as I'm working from a netbook for the time being it may make sense to take my first steps using Notepad or something less memory dependent than Eclipse. The book I'm reading has been adapted to Android App form but seems to match what I'm seeing here. I like the writing. Seems straight forward without talking down to me. Get what I mean? Any thoughts or recommendations on reading material? I'm mostly interested in gearing up to write an Android app eventually.
Ranch Hand
posted 6 years ago
I like the writing. Seems straight forward without talking down to me. Get what I mean?
You mean to say some authors talk down to people? Interesting viewpoint. I hope we don't fall in that category.
Greenhorn
posted 6 years ago
Probably not the best expression. I just mean to say the writer doesn't dumb it down too much and belabor the point
I'd like to find an IDE that is more lightweight than Eclipse to run on my slow netbook. Any suggestions?
Ranch Hand
posted 6 years ago
I'd like to find an IDE that is more lightweight than Eclipse to run on my slow netbook. Any suggestions?
Try either this or this one here. Let me know how each one fares.
Marshal
posted 6 years ago
Ranch Hand
posted 6 years ago
Campbell Ritchie wrote:Probably better to go back to the command line.
Hardcore. But if OP has such a rich experience as working at machine workshop, so he knows nuts and bolts of computers, I suspect he can prefer that way. Please put me right if I'm wrong. @OP: try Sublime text editor, I like it.
Marshal
posted 6 years ago
The problem with IDEs is that you have to put so much effort into learning the IDE, which would be better used for learning Java. Also you don’t learn the command‑line options well if you use an IDE.
Ranch Hand
posted 6 years ago
Campbell Ritchie wrote:you have to put so much effort into learning the IDE, which would be better used for learning Java
You will have to learn to use IDE anyway. But I agree that if you plan to go deep into java it's better to start from fundamentals.
Marshal
![]()
By the time you are writing large enough applications to need an IDE, you will know the Java. Then you will have brain‑space enough to learn the IDE as well.
Greenhorn
posted 6 years ago
I checked out both DrJava and JEdit and I'm going to give DrJava a try for a little while. I like the sound of the command-line purist approach, and I grew up on MS-DOS so I'm familiar with command-line environment, but I tend to be a bit disorganized and so I like that an IDE can help with that.
Ranch Hand
posted 6 years ago
Jayeemsuh Allen wrote:I checked out both DrJava and JEdit and I'm going to give DrJava a try for a little while.
That's all 'noname' IDEs to me. I've never used any of these before and didn't even hear any suggestions to start using it. If you plan to start with IDE, it would be wiser to invest your time in learning popular and proven IDE.
Greenhorn
posted 6 years ago
That's all 'noname' IDEs to me. I've never used any of these before and didn't even hear any suggestions to start using it. If you plan to start with IDE, it would be wiser to invest your time in learning popular and proven IDE. Noted! As I mentioned though, the hardware on my netbook is pretty meager so I need something pretty lightweight. I'm using DrJava for now and it seems to be doing the trick for compiling and running simple input/calculate/output type programs. That's mostly all I'll be doing for the time being. Maybe I'll upgrade my PC and IDE once I get some more experience. On a somewhat unrelated note, I'm looking to read up on conventions for style and specifically how to form good habits with indentation. I'd like to start these habits early and have them stick. Any suggestions on where I can learn this sort of thing? Here is some code that I'm looking to practice on:
Ranch Hand
posted 6 years ago
I've got a lot of questions about your code.
Do you really need these uninitialized vars? Is it really needs to be double instead of float, int instead of short (byte)? Can you opt out of TextIO custom class, to make folks from the ranch understand the code? Personally I like to stick to standard APIs to show the code (otherwise dependent I need to share dependent classes).
Marshal
posted 6 years ago
surlac surlacovich wrote: . . . Is it really needs to be double instead of float, int instead of short (byte)? . . .
That is not at all a good suggestion; floating‑point arithmetic is done with doubles as a default and integer arithmetic with ints. In the days when memory was expensive, it might have been worth being economical with it, but that has not been the case for, probably, twenty years.
Marshal
posted 6 years ago
surlac surlacovich wrote: . . . Can you opt out of TextIO custom class, to make folks from the ranch understand the code? TextIO appears simply to be a utility class which writes things to the command line and reads from it. Its methods have simple names, so we can easily work out what they mean.Personally I like to stick to standard APIs to show the code (otherwise dependent I need to share dependent classes). Agree it would be better to write your own utility class for text input and simply use System.out and System.err for output, but OP specifically said he wanted to use TextIO.
Greenhorn
posted 6 years ago
Agree it would be better to write your own utility class for text input and simply use System.out and System.err for output
Sadly, I don't even know what a utility class is but I'll look into it. I did take a quick look at Scanner and how it is used for simple input/output. I used it successfully, but I am drawn to the simplicity of TextIO for the simple needs I have now.
That is not at all a good suggestion; floating‑point arithmetic is done with doubles as a default and integer arithmetic with ints. In the days when memory was expensive, it might have been worth being economical with it, but that has not been the case for, probably, twenty years.
Interesting! I simply used type double and int because they were used for variables with similar purposes in examples that I saw.
Marshal
posted 6 years ago
They are used in examples so often because they are the default types in Java.
![]() Comments are closed.
|
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |