r/learnandroid • u/[deleted] • Jun 03 '11
Lesson Two: Getting Familiar with Eclipse and Java
http://learnaboutandroid.blogspot.com/2011/06/lesson-two-getting-familiar-with.html1
u/rfederici Jun 03 '11
I really like this subreddit from what I've seen so far, but I do have a question: As Really_Likes_Nutella (who doesn't?!) referenced, the Android Developer's site has great guides/tutorials for beginners (including setting up Eclipse for Android development) and a superb and extremely in-depth reference for more experienced developers. Is this same thing, or is it going into more depth and reason? Is it more geared towards complete beginners, or will you slowly get more advanced with it?
Thank you and I look forward to future lessons!
1
Jun 03 '11
There's a couple reasons I'm doing this.
First, I love the Android Developer's site and their tutorials. However, I have a (fairly) extensive background in Java, and have practiced in Android before. If you read through the tutorials, I find them to be very thorough and in-depth; however, they assume you have a lot of knowledge already. It would be like reading a "Nuclear Fusion for Dummies" book; sure, it's a "beginners" guide, but you can't just go pick it up and understand everything about it. I'm trying to write these tutorials to be not only in-depth, but to explain things as well. Sure, a tutorial can explain how to write a method or a constructor, but what does that all mean? When I learned Java, we were simply taught "this is how you do it, I'm not going to give you an explanation as to why this is how it's done) and to be honest, it fucked me over my first semester of college. I barely passed that class, because I NEED to understand how those things go on. I hope to pass that on to others, so they can understand too.
Second, is that tutorials are just...there. Sure, you can start whenever, but I find that if I do that, I lose a lot of desire quickly, because I don't know what pace to take. The idea I'm trying to make is that everyone takes the same pace; so if anyone comes up with questions or problems, there are other people at the same place that may be able to answer, or might have the question as well. As long as we take the same pace together, we can then help each other out. It also is far more structured for people.
Right now, I'm keeping it VERY basic. As I've said before, a good amount (75%) of people want to have reminder tutorial on Java, and a smaller portion (40%) of people don't know Java at all. I will get more advanced, I promise; Also, I hope to have the whole project laid out into a website which anyone can follow by July 1st, but we'll see how ambitious I am.
If you have any other questions, feel free to ask, I'm always happy to answer!1
u/BlueScreenJunky Jun 03 '11
however, they assume you have a lot of knowledge already.
Exactly. The tutorials and conferences from Google seem to be geared towards professional developpers who have never programmed for Android but already know a lot about programming and OOP in general. So I'm grateful you're doing this for people like me who have very little experience and would like java/android to be their first experience.
2
u/zck Jun 03 '11 edited Jun 03 '11
However, I have no clue why "String[] args" is what is used; I just know it WORKS. If someone would like to elaborate further, please feel free to leave a comment.
Ouch.
In function declarations in Java, whatever's between the parentheses is the argument list. Each argument is separated by commas from the others. There are no commas, so there's only one argument.
A argument has two parts: a type and a name. The type is String[]; the name is args.
The [] in the type means "array of". It's a String array.
So main() takes in a String array. This can be useful if you want to pass arguments to the Java program when it starts up.
...numbers usually are 0 or -1, and Strings are NULL if you plan on changing them later; otherwise, just set them to what you want them to be.
That's incredibly confusing. Numbers are not usually 0 or -1; they're just (apparently) set to those for Android preferences. You can change strings later. It's a bad idea to tell newbies things that are wrong for Java, but right for Android.
1
u/hedyedy Jun 12 '11
Isn't this a carry over from C? I assume main() is the entry point. In fact, I tried to rename it and got: public class myClass { public static void soWhat(String[] args) {
. . .
}} I ran it and got the following error:
java.lang.NoSuchMethodError: main Exception in thread "main"
Regarding the arguments:
the arguments are the command line arguments (or console arguments). To enter arguments, do the following: go to: run run configuration click on "(x)= arguments" tab and enter the arguments in the "Program Arguments" box I entered: "Item1 Item2 Item" and changed the code to: public class myClass { public static void main(String[] args) { System.out.println(args[0]); System.out.println(args[1]); System.out.println(args[2]); }
}
and ran it, with the following result:
item1 item2 item3
1
u/zck Jun 13 '11
Yeah, but the question wasn't about the name main; it was about the argument String[] args. It's a String array which is populated with the arguments to the program.
2
u/[deleted] Jun 03 '11
Thanks for doing this.
After setting up Eclipse I jumped ahead a bit and did this but it is a bit complicated and goes into XML which I don't really understand.
Is this lesson not Android, just Java since it prints into the console and doesn't use the Android SDK?