20 questions on a variety of topics to aid me learn Java.

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

53 Replies - 2090 Views - Last Post: 22 January 2013 - 07:54 AM Rate Topic: -----

#1 DrPerry  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 19
  • Joined: 21-January 13

20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 05:28 PM

================================================== ================================================== ===
Before reading this MASSIVE post, please read the bottom at the stupid amount of P.P.S.'s as they probably have a lot of information that I forgot to put in the middle or something.
================================================== ================================================== ===

Hi, I'm some guy on the internet and I am 15 years old. For the sake of this post and the answers I hope to have, please ignore my age and understand my maturity and I hope that you can understand why I would like to learn this language so much. I seem to have major issues with learning this language and online tutorials and stacks of books do not seem to do the trick. Please do not reply saying "this is not for you, try something else" because although I do not know much in Java in terms of making good applications, I have learned quite a few things and I am able to make simple things with the console such as making a calculator where the user has to type in what operator they want to use and then they are asked to enter two numbers in which they are timed/added/divided etc. together and it gives the answer. Considering this I really want to continue learning this language because I find it fun to learn and fun to program in, yet I am having serious stress issues because I can't understand simple things and I just forget some of them and I then find it difficult to make simple applications. For example, I am trying to make a simple snake game where you have to find all the apples and eat them and then your body grows larger etc. but I just can't think of how I would do it. I know a few simple application type things and maybe how to put them to use, but I just don't know how to use them in this situation and how to start off making games like these.

Just to tell you a little bit about my background of programming, I have known about programming since I was about 11, I made a virus in Visual Basic believe it or not. It would disguise itself as Mozilla Firefox and would slowly delete random files that were opened or edited in the last month starting from the last used files in said month. It would delete a set amount of files every time you booted up and it was pretty nasty. It was obviously quite easy to get rid of it and it probably had many bugs, but it was a nasty virus nonetheless. Anyway, that lasted around 2 months and I never really picked up on programming until around 13 at which point I learned a bit of Java up until the System.out.println part, so not very far at all and I barely understood anything. Then I kinda picked it up at 14 last summer (2012) and learned almost as much I know now over the summer holidays and then kind of left it until after Christmas because I couldn't really get past a certain 'barrier' so I got bored and gave up. Until now. After Christmas I got back into it and starting learning a few more things, understood functions a little more and downloaded a bunch of source code from lots of different websites. I've now been extremely stressed out for the past 2 weeks going crazy because I can't fit anything else into my head because I just forget it or just don't understand it. So I am now in a complete frenzy not doing homework, being a douche to my friends and just not being very social or doing stupid things.

Unfortunately this is going to be a rather long post as you can probably already tell and there will be a 20 Q's kind of 'game' below where I ask things that I desperately need to know and maybe things that I want to know but don't necessarily need to know.

If you can, I would greatly appreciate it if you could answer all of the first 14 questions in one post instead of 1 or 2. Also, please do not post anything unnecessary or nasty as I am a new poster here and I just want to get started in Java and I have my own reasons for starting at such a young age and my intentions are rather personal. So please treat this matter with maturity and I hope someone can really help me.

I am sorry for any misspellings or grammatical errors, I am fully English, I am just rubbish at spelling.

THE QUESTIONS!!!

1) What is SUPER used for, when should I use it and why should I use it?

2) When making a new class and you type PUBLIC [insert class name here](){} what does this do and why does it need to be the same name as the class it is in?

3) Why do you need to make new classes inside already made classes sometimes?

4) What is the use of NEW and why do you need to use it when you are creating something like a JFrame, where for example you would use it in your main function and have NEW [insert name of function with JFrame inside]();, why can't you just do [insert name of function with JFrame inside]();?

5) What is actionPerformed, where is it used and why should I use it?

6) When using a function, what is achieved when you call another class and make another variable inside said function? Eg, public [insert class name here]([insert other class name here][insert new variable name here]){}

7) What 'type' is an ENUM? Is it an int? String? Double? So if I were to make ENUM [insert name of enum here] {A, B, C, D, E, F, G}; So what would happen if I were to say PUBLIC [insert name of enum here] B = 5; what would that mean? Would that assign it as an integer?

8) When should I use enums, what is the point in them?

9) What does [inset object here].ORDINAL mean? What is it used for and when should I use it?

10) Although I understand that the RETURN statement is used to end a function and return it with a value if there is one specified, but when it returns it with that value that you may have specified, what happens to that value, how do I retrieve it and how do I use it? When will I know when to use RETURN?

11) Briefly explain how to use KeyEvent, getKeyCode and just anything else to do with accepting user input and how I would use it.

12) When using the KeyAdapter, why do you need to make a new class inside an already made class? What does this achieve? Why can you not extend it on the current class you are using instead of making a new class? This links back to the 3rd question.

13) What is the difference between ++object and object++? Does it really matter which way I use them? Why should I use them differently and how will it affect my code if I use them differently?

14) What's the difference between an IF statement and a BOOLEAN statement? They are both booleans and if used correctly can be used to do the exact same thing with just one or two lines of codes difference. Which one should I pick over the other and why? Which one is better to use for what kind of things?

================================================== ================================================== ===
POINTLESS QUESTIONS THAT I JUST FEEL LIKE ASKING THAT DON'T NEED TO BE ANSWERED AND DON'T HAVE MUCH TO DO WITH THE CODE ITSELF
================================================== ================================================== ===

15) What is the best way to get into the mindset of 'a programmer'? What is the best way to understand the ways in which you would build an application and learning the step by step processes so you know what you have to do next and how to do it.

16) I seem to always be worried that it takes programmers 5 minutes to program a very simple game, like Tetris because I've seen videos and just other places where it makes it look like it takes them a very small amount of time to make something that might take me months to learn. Is this how it works? Or can it take hours to program 5 classes for a very simple game? If so, why does it, if said programmer hypothetically understands the language well enough to make said program? Surely they would know what to do and how to make it so it would not take long at all?

17) How often are IF and ELSE statements used in common programs? I feel when I am making a program I am always using them too much and I just stop programming from there because I feel that I am using too much of something so maybe it isn't the right way to do it or maybe there is a better way to do it.

18) What would be the best way to learn programming for someone who finds it difficult to teach himself said topic yet has no efficient way to have someone teach him? I feel I am somewhat intelligent enough to learn a programming language, I have gotten this far, so I feel I should just keep going. Besides, despite the difficulties I have and the ridiculous amount of stress I get from not being able to learn on my own, I find it very entertaining to program things, read over other peoples code and slowly learn the world of programming. I feel that I see myself as a programmer in the future and I just really hope that I can learn this language quickly before I am too old to have time to learn this as a hobbie as I do now.

19) I am someone who hopes to become a games developer as I thoroughly enjoy playing games as much as I do finding out how they work. What would be the right way about learning how to make games? Should I stick with Java or should I go to C++? I've only stuck with Java because I have more experience with it and I feel that I should learn an easy language and get used to OOP and other things before I go off making complex programs with a difficult language. I know how to print something to the console in C++ and that's about it.

20) I have no way of having an education on programming in my school at the moment and all courses that have programming in them aren't very good - you make a simple application for coursework and you do a computer physics exam at the end of the year, not too helpful for me. Also, I don't have many friends that are diversed in any language of programming and the ones I do have, coincidentally, absolutely none of them are any good at making games or painting anything in graphics or anything to do with frames and windows. They're all about the console and making mods for games instead of making full on programs with a window and what not so it's difficult to get any of them to teach me anything. I've looked at college courses and none of them are for my age and what I am wanting, or they are just too damn expensive. I have also looked at online courses, one-to-one tutoring etc. but they are either way too expensive or they aren't very good in terms of being in a country half way across the world or maybe they have bad ratings. Anyway, what I'm trying to ask, despite all the negative put backs and all the issues that seem to follow me whenever I try to learn this damn language, what would be the best way to teach myself this language or any other language, or where are the best places to have someone teach me for free/cheap prices? I just essentially want to make something basic like a video game like Tetris or something so I at least have some knowledge of making a video game so I can maybe learn other things much easier.

P.S. I am in top sets for all my classes at school, so any intelligence issues aren't a part of this. I guess you could maybe call it laziness, but I just prefer to say that I am too used to people teaching me things and doing things for me rather than teaching and doing things myself. So if I were stuck on an island alone I really would not know what to do at all because I would mainly rely on other people.

P.P.S. Just for anyone's curiosity, I use Eclipse as my IDE on a Windows 7 Ultimate OS.

P.P.P.S. I am British.

P.P.P.P.S. I have read through about 4 books about Java, but on most of them I just get really bored and stop reading them half way through because they either don't explain what I want to know or they really suck at explaining what I want to know.

P.P.P.P.S If you are going to post a good tutorial, please post one that I have most likely NOT been on. PLEASE. I have gone through MANY tutorials which all of them don't do me any favours. Please post one that you think that I might not have seen and actually tells me what EACH line of code does and WHY it does it and WHY I might use it and WHERE I might use it. Etc.

P.P.P.P.P.S If this is a TL;DR kind of post, then I am awfully sorry to have bored you, please go onto another post, but thank you very much for taking the time to actually LOOK and CLICK on my post. However if you do not have any intention of helping my dilemma, please leave as although I am asking for A LOT for FREE, I really don't need pointless posts that really do not solve my problem. Thanks.

P.P.P.P.P.P.S (Last P.P.S I swear! I just keep forgetting things.) If you have any questions to ask or I might not have asked something properly, feel free to ask as I will probably be refreshing this page non-stop for the next 2 weeks. Thanks ^^

For all the people out there who are THAT awesome to post here answers to these questions, I really salute to you and I would VERY gladly give you money for your time and effort, if I had the funds to give you what it's worth. ;-)

Is This A Good Question/Topic? 1
  • +

Replies To: 20 questions on a variety of topics to aid me learn Java.

#2 ianian112  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 119
  • View blog
  • Posts: 378
  • Joined: 28-November 09

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 05:41 PM

TLDR: I'm a super genius that made a virus at age 11
Was This Post Helpful? 2
  • +
  • -

#3 DrPerry  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 19
  • Joined: 21-January 13

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 05:45 PM

View Postianian112, on 21 January 2013 - 05:41 PM, said:

TLDR: I'm a super genius that made a virus at age 11


I'm sorry, but this wasn't too helpful, you could have at least read the first paragraph or so? Besides, I wasn't even trying to make myself look like a genius on the slightest, I even said that it was probably bug ridden and very easy to get out of. It's very easy to make things like that in VB. If you are going to help, please post something helpful instead of making a negative remark.

Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 ianian112  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 119
  • View blog
  • Posts: 378
  • Joined: 28-November 09

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 05:47 PM

View PostDrPerry, on 21 January 2013 - 05:45 PM, said:

View Postianian112, on 21 January 2013 - 05:41 PM, said:

TLDR: I'm a super genius that made a virus at age 11


I'm sorry, but this wasn't too helpful, you could have at least read the first paragraph or so? Besides, I wasn't even trying to make myself look like a genius on the slightest, I even said that it was probably bug ridden and very easy to get out of. It's very easy to make things like that in VB. If you are going to help, please post something helpful instead of making a negative remark.

Thanks.

Most of your questions can be answered by google. for example I took your first question prepended 'java' and bam: http://docs.oracle.c...andI/super.html

Also your post makes you come across as an egotistical brat.

This post has been edited by ianian112: 21 January 2013 - 05:49 PM

Was This Post Helpful? 0
  • +
  • -

#5 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,686
  • Joined: 13-March 10

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 05:48 PM

You read 4 Java books but you did not finish them because they dont teach you stuff you want to know. Guess what, the stuff you are asking is covered in every introductory Java book. Why should i type in the contents of a book here?

And about the tutorial that you have not seen. WTF?

Programming is not for you. Give up.
Was This Post Helpful? 1
  • +
  • -

#6 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7621
  • View blog
  • Posts: 12,849
  • Joined: 19-March 11

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 05:50 PM

Quote

P.P.P.P.S If you are going to post a good tutorial, please post one that I have most likely NOT been on


Here you go. Pretty sure this will help.


(too snide, didn't read: some of your questions are good ones, and have interesting answers, but there's no way that this post will produce anything interesting: too many topics all piled up, and you give too many opportunities to play the "go away, kid" game. If you read what esr has to say in that esay I linked to and really try to apply it, you're likely to get good answers to some of your questions.)

This post has been edited by jon.kiparsky: 21 January 2013 - 05:54 PM

Was This Post Helpful? 4
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10438
  • View blog
  • Posts: 38,651
  • Joined: 27-December 08

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 05:55 PM

*
POPULAR

Quote

1) What is SUPER used for, when should I use it and why should I use it?

2) When making a new class and you type PUBLIC [insert class name here](){} what does this do and why does it need to be the same name as the class it is in?

These two go together, so I'll start here. The super keyword is used to reference the super class. You can use it in a method you are overriding to call the prior implementation in the super class, or to call a super constructor explicitly. For question #2, you are referring to a constructor. It is used to instantiate and initialize the object. If you do not provide one, Java will provide one by default. Note that child classes must have a matching constructor or make an explicit call to the parent constructor. When an object is instantiated, the parent constructor must be called all the way back to Object.

Consider the following code sample. Here, A has a constructor that accepts an int and B does not. Therefore, B has to make a super() call invoking A's constructor, which does not match the header for B's constructor.
class A{
   private int x;

   public A(int x){
      this.x = x;
   }
}

class B extends A{
 
    B(){
        super(0);
    }
}



Quote

3) Why do you need to make new classes inside already made classes sometimes?

Good design, really. If I have a Map or a Tree class, I may encapsulate an Entry or Node class that is meant to be used by the data structure only, but not outside of it.

Quote

4) What is the use of NEW and why do you need to use it when you are creating something like a JFrame, where for example you would use it in your main function and have NEW [insert name of function with JFrame inside]();, why can't you just do [insert name of function with JFrame inside]();?

The new keyword is used to instantiate an Object. If you don't use it, you cannot instantiate an object (with the sole exception of Enums and Strings).

Quote

5) What is actionPerformed, where is it used and why should I use it?

See the ActionListener interface.

Quote

6) When using a function, what is achieved when you call another class and make another variable inside said function? Eg, public [insert class name here]([insert other class name here][insert new variable name here]){}

This question isn't clear. You are going to have to be more specific and provide a code sample.

Quote

7) What 'type' is an ENUM? Is it an int? String? Double? So if I were to make ENUM [insert name of enum here] {A, B, C, D, E, F, G}; So what would happen if I were to say PUBLIC [insert name of enum here] B = 5; what would that mean? Would that assign it as an integer?

Enums compile down the same way as classes. The specific enum values are Objects.

Quote

8) When should I use enums, what is the point in them?

Really, the act as constants with properties. Direction is a good use for enums:
enum Direction{

    NORTH,
    SOUTH,
    EAST,
    WEST
}



Quote

]
9) What does [inset object here].ORDINAL mean? What is it used for and when should I use it?

You're referencing a constant, it looks like.

Looking at the rest of your questions, you are all over the place. Don't jump right into GUI and Game Programming, especially since you need to work on your grasp of OOP. Focus on the basics for now. We have a bunch of tutorials on DIC you can weed through. Focus on writing code as well. Take on projects that challenge you, but don't overwhelm you. Writing Tetris is not something I would encourage you to do at the moment. Writing a console Blackjack game or an inventory management system is probably more appropriate.
Was This Post Helpful? 5
  • +
  • -

#8 DrPerry  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 19
  • Joined: 21-January 13

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 05:59 PM

jon.kiparsky, you took my question literally and I chuckled. Thanks I will put this to use if you think that I have not structured this post well. Thanks. :-)

To the other two posters, I did mention I have an issue with learning, but I have the intelligence and potential to be something great. If you are going to post something I specifically said not to post, I am kindly asking you to leave. I am OK with no replies if it means I don't have people putting me down and supplying me with useless information. I hope I am not sounding too negative.

To darek9576, yes most of this could be Googled, but I can't exactly speak with the person writing the tutorial and ask questions and have a chat with said person, can I? Also, There were other questions that I was tempted to add but I Google them and I understood them. The things I have asked are things I have Googled and read over multiple times yet not understood very well. I only posted those questions hoping someone would be able to explain in a way I might understand.

Thanks. :-)

View Postmacosxnerd101, on 21 January 2013 - 05:55 PM, said:

all the stuff you said here


You sir are an amazing chap! I will read this very carefully and I thank you very much! We need more people like you in this world who are willing to help people for free while ignoring their reasons. I take my hat off to you! Thanks!

This post has been edited by macosxnerd101: 21 January 2013 - 06:01 PM
Reason for edit:: Fixed quote tags

Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10438
  • View blog
  • Posts: 38,651
  • Joined: 27-December 08

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 06:01 PM

Glad I could help, but the other points made are valid as well. As a programmer, you are expected to be able to read the documentation and tutorials. The reason it isn't sticking for you is because you aren't trying it out and playing around.
Was This Post Helpful? 1
  • +
  • -

#10 DrPerry  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 19
  • Joined: 21-January 13

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 06:09 PM

To help explain questions 6

6) When using a function, what is achieved when you call another class and make another variable inside said function? Eg, public [insert class name here]([insert other class name here][insert new variable name here]){}

Here's a snippet I have from a Tetris game possibly stolen from Zetcode

   
 public Board(Tetris parent) {

       setFocusable(true);
       curPiece = new Shape();
       timer = new Timer(400, this);
       timer.start(); 

       statusbar =  parent.getStatusBar();
       board = new Tetrominoes[BoardWidth * BoardHeight];
       addKeyListener(new TAdapter());
       clearBoard();  
    }


All that is doing is referencing to the Tetris class files and the file this is in is called Board which further explains why I asked why you had to have the constructor as the same name as the class.

I read through your post a little more thoroughly and I must say you have helped a lot! I hope you go onto helping more people. ;-)
Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10438
  • View blog
  • Posts: 38,651
  • Joined: 27-December 08

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 06:14 PM

I'm not particularly sure why this particular constructor accepts a Tetris object but doesn't use it.

Quote

I asked why you had to have the constructor as the same name as the class.

Because this is how Java syntax requires the constructors to be defined.

Quote

When using a function, what is achieved when you call another class and make another variable inside said function? Eg, public [insert class name here]([insert other class name here][insert new variable name here]){}

The term in Java is method, not function. Really, it depends on what the local variable is used for. Note that variables declared inside methods are only accessible inside of the methods they are declared in.

Really, once you focus on learning your OOP properly, I think a lot of this will make more sense.
Was This Post Helpful? 0
  • +
  • -

#12 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7621
  • View blog
  • Posts: 12,849
  • Joined: 19-March 11

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 06:16 PM

The reason the class file has to be in a file with the same name is actually for the convenience of the compiler, or rather so the compiler can provide you with a convenience. When you ask the compiler to load a class named Foo, how does it know where to find the definition of that class?

If it's included in one of the standard libraries, then it's easy enough to sneak it in, I suppose - "it just knows". But if Foo is something you just wrote, it's not defined anywhere in the language. So how does the compiler know where to look for it?

Well, there are a few ways this could happen, and in Java it's done by looking in certain directories (I won't go into the classpath here, that's a new question, and you've got 20 stacked up already) and looking for files with the right names. Aligning public class names with file names means that it's very quick and easy to search for Foo.java when trying to compile a class that requires Foo, and to find Foo.class when it's time to load that class definition.
That's the short answer, but it'll have to do for now.
Was This Post Helpful? 1
  • +
  • -

#13 DrPerry  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 19
  • Joined: 21-January 13

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 06:31 PM

Thanks for the replies guys.

macosxnerd, sorry if my vocab of Java is a little off or something I say doesn't make sense, I just type stuff and hope people understand for some reason. I'm usually not that bothered on the names of stuff so I just try and guess what they're called from vague memory. So in future replies, please assume I have no idea what any of anything is called and just hope to God that what I am saying actually makes some sense.

Yeah, I'm gonna try and pick up the books I left and see if I can understand a little more. It's just a lot of the time when I flick a few pages forward and have a scan over the past few pages the author doesn't really describe WHY to use it, WHERE to use it etc. They only tell you HOW to use it and they just say 'stick it there and it should work'. Other might disagree with me or others may say that their way of teaching is good enough, but I guess I'm just very bad at learning on my own and I can't ask the questions I can in class.
Was This Post Helpful? 0
  • +
  • -

#14 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10438
  • View blog
  • Posts: 38,651
  • Joined: 27-December 08

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 06:33 PM

You're still looking at programming very academically, I feel like. Programming is a very practical topic. That is, if you don't write code, you'll never learn how to code. Once you get your feet wet, it will make more sense. The more programs you write, the more the topics will be cemented.

We have a good learning series and set of project ideas for you to look at.
Was This Post Helpful? 0
  • +
  • -

#15 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7621
  • View blog
  • Posts: 12,849
  • Joined: 19-March 11

Re: 20 questions on a variety of topics to aid me learn Java.

Posted 21 January 2013 - 06:41 PM

Or, to be a little more blunt: the best way to learn is not to dive in at the deep end and then yell for help. Try wading in at the shallow end and paddling around a bit.
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »