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

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

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

#31 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7872
  • View blog
  • Posts: 13,354
  • Joined: 19-March 11

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

Posted 21 January 2013 - 07:42 PM

View Postfarrell2k, on 21 January 2013 - 09:21 PM, said:

I can't imagine game objects not communicating with another game manager object via getters and setters. Of course this just may be a failure of my imagination. :)/> Did any of them give you any examples?


I can. Depends on the game and the architecture, but it's generally pretty easy.

For example, if you're using an MVC architecture, the Controller is going to tell the Model what action the user has taken, not what the new state of the Model should be after the action is taken. Likewise, the Model is going to provide information about the current state to the View which will draw that state. The Model is not going to set values in the View, it will simply provide the View with the information it needs to do its job.

That's just one example. Here's another: if you're applying a force to an object, you don't want to calculate its new velocity and set it, you simply inform it that it's had some sort of impact, and here's the vector of acceleration that it should apply to itself, and let it calculate its new trajectory.

Or if you're in a zorkalike and your player drops and object, you don't reach into the room and insert that object in the room's inventory, you send the room a message telling it that this object has been dropped, and would it please do the right thing with it.

At least, that's how I'd do it.
Was This Post Helpful? 0
  • +
  • -

#32 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 - 07:45 PM

Oh right, my bad, I thought he meant the hacking of programs and websites and stuff.

Yeah, I do see a lot people saying to just CODE CODE CODE! It's just the difficult task of trying to make something with the knowledge you have but then you miss one key thing and then that key thing turns out to be one whole entire topic and it just gets confusing from there.

However, I will take your advice. I am ashamed to say that the best program I have made so far is a just a simple calculator in the console despite the fact I know a lot more now since I coded that program which was back in 2012 last summer. I think I might revisit it and recode it with the knowledge I have now.

Thanks a bunch.

If anyone wants to see the calculator console I made, feel free to ask and then laugh at it. It's pretty large so I'm only going to post it if someone wants it.
Was This Post Helpful? 0
  • +
  • -

#33 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10647
  • View blog
  • Posts: 39,539
  • Joined: 27-December 08

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

Posted 21 January 2013 - 07:46 PM

Quote

Yeah, I do see a lot people saying to just CODE CODE CODE! It's just the difficult task of trying to make something with the knowledge you have but then you miss one key thing and then that key thing turns out to be one whole entire topic and it just gets confusing from there.

You've been given a projects list. You can Google for Intro to Java classes and use their assignments. You can come up with an idea on your own. If you never write code, you'll never get better. Don't be intimidated. You have to start somewhere.
Was This Post Helpful? 0
  • +
  • -

#34 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7872
  • View blog
  • Posts: 13,354
  • Joined: 19-March 11

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

Posted 21 January 2013 - 07:50 PM

View PostDrPerry, on 21 January 2013 - 09:35 PM, said:

I will look though those Tutoracles. I have read a few of them but sometimes I feel they code everything really differently to everyone else. Just completely differently. That might just be me, but that is my opinion.


That's probably true. But they're not writing production code, they're writing stuff for you to understand. For you to ask beginner questions about production code tells me you need to read beginner code for a while.

Quote

Also, this isn't about hacking. This is about Java and game development.


Hacking in the real sense. Exploring the world around you and figuring stuff out. Being intellectually self-reliant, as well as willing and eager to learn from others. If you rely only on yourself, you're likely to end up an arrogant solipsistic prat and think yourself superior to all others and have no friends and we don't want that - but if you bring nothing to the conversation, you're a drag. Middle-ground it. Learn from what's already there so you can ask more interesting questions that I can really answer.

Quote

Also, I never said someone HAD to answer them, it doesn't hurt ANYONE to ask a question. If nobody answers, that sucks. If someone is nice enough to answer then awesome. At the end of the day, I have lots more views on the question I asked and a lot more information I would have had from just one source.


But you won't understand the answers unless you've got up to them, and you haven't, and we're not going to conduct a private guided tour through all of Java just for you. You've got to get yourself started, and work your way up to a question, and ask that one. There's a reason the tutorials start where they do and present the information in the order they do. They didn't just pull "primitive objects and operations on them" out of a hat.
Was This Post Helpful? 0
  • +
  • -

#35 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 849
  • View blog
  • Posts: 2,591
  • Joined: 29-July 11

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

Posted 21 January 2013 - 07:54 PM

View Postjon.kiparsky, on 22 January 2013 - 02:42 AM, said:

View Postfarrell2k, on 21 January 2013 - 09:21 PM, said:

I can't imagine game objects not communicating with another game manager object via getters and setters. Of course this just may be a failure of my imagination. :)/>/>/> Did any of them give you any examples?


I can. Depends on the game and the architecture, but it's generally pretty easy.

For example, if you're using an MVC architecture, the Controller is going to tell the Model what action the user has taken, not what the new state of the Model should be after the action is taken. Likewise, the Model is going to provide information about the current state to the View which will draw that state. The Model is not going to set values in the View, it will simply provide the View with the information it needs to do its job.


All of which is fine and dandy, but how do you do it without getters or setters? How does your controller communicate with your view or model without them? How does your controller update or read say a text field in your view without some method to get or set the value of that view?

Never mind. I guess we can just use the observer pattern and have the view update itself when necessary.

This post has been edited by farrell2k: 21 January 2013 - 08:01 PM

Was This Post Helpful? 0
  • +
  • -

#36 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 - 07:56 PM

@jon.kiparsky

Yes, you make many valid points. I was only worried about making the thread too long so I was kind of trying to shorten all of the questions. I could have typed coded examples for each question and I could have probably gone into a lot more detail than I have but I felt that the post was already long enough as it was.
Was This Post Helpful? 0
  • +
  • -

#37 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10647
  • View blog
  • Posts: 39,539
  • Joined: 27-December 08

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

Posted 21 January 2013 - 07:58 PM

You were still all over the place. Having done my fair share of work with Swing, I can tell you first hand that if you don't know your OOP (which you still have work to do), jumping into GUI and Graphics/Game programming is not a good idea.

In addition to basic code for the concepts, get going on more projects as well. Apply what you are learning and it will stick better.
Was This Post Helpful? 0
  • +
  • -

#38 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 - 08:01 PM

Ok, I will do. Like I said I think I will try to work on my calculator class. If anyone wants to look at it just ask. :-)
Was This Post Helpful? 0
  • +
  • -

#39 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10647
  • View blog
  • Posts: 39,539
  • Joined: 27-December 08

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

Posted 21 January 2013 - 08:02 PM

I would be more interested to see your new Calculator program. Try and do the following two things:
-Design a Calculator class
-Separate the user interface from the Calculator class
Was This Post Helpful? 0
  • +
  • -

#40 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7872
  • View blog
  • Posts: 13,354
  • Joined: 19-March 11

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

Posted 21 January 2013 - 08:03 PM

You might have something as simple as this:

view.update(state);


Where state comprises, essentially, the world. What does view do with this? That's up to view. That's the point: if I'm the model, I don't have to care.

EDIT: The difference between this and a setter is important. A setter tells a class what value one of its fields should have. This means that some other class is responsible for doing the work that properly belongs to that class. A more effective design centralizes all of the calculation for a given class in that class.
The important point to focus on is: you should never have direct access to another object's internal state. Tight coupling is to be avoided.

This post has been edited by jon.kiparsky: 21 January 2013 - 08:13 PM

Was This Post Helpful? 0
  • +
  • -

#41 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 - 08:08 PM

@macosnerd101

Yeah but I'm just thinking, in my old calculator console, it would the user input for the operator so it would ask for all the obvious operators in a list and then if you typed the correct string in and hit enter it would ask for two numbers to use the operator with.

The issue is with those two numbers I had to click enter between them. So for example I would need to do: (each new line is where I would need to click enter)

ADD
5
7

Then it would obviously display 12. I want to be able to type 12*4 in the console and hit enter but I haven't learned that much of the scanner. Any suggestions? I will try looking on Google before anyone complains. ;-)#

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

#42 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 849
  • View blog
  • Posts: 2,591
  • Joined: 29-July 11

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

Posted 21 January 2013 - 08:08 PM

View Postjon.kiparsky, on 22 January 2013 - 03:03 AM, said:

You might have something as simple as this:

view.update(state);


Where state comprises, essentially, the world. What does view do with this? That's up to view. That's the point: if I'm the model, I don't have to care.


And that update() is still a setter in my book. Maybe not. I'll have to think about it. :)

This post has been edited by farrell2k: 21 January 2013 - 08:09 PM

Was This Post Helpful? 0
  • +
  • -

#43 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10647
  • View blog
  • Posts: 39,539
  • Joined: 27-December 08

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

Posted 21 January 2013 - 08:10 PM

DrPerry- I'm not going to hold your hand through the design. This is for you to do. If you don't know how to use Scanner, look at tutorials and try it yourself. This is what we are talking about. Then focus on good class design practices and focus on designing a Calculator class to handle the basic functionality of a calculator.
Was This Post Helpful? 0
  • +
  • -

#44 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 - 08:15 PM

Ha ha, I don't think you quite understood, many apologies. I understand how to use the scanner but I don't quite know how to scan a single line of a string and select operators from that string. I've looked online and it appears I apparently need to use something called 'StringTokenizier' with arrays. Not sure how to use StringTokenizier but I will look it up.

I was only asking for a suggestion on how to store different things in one press of the enter button. But it doesn't matter, I think I found a few things.

:-)
Was This Post Helpful? 0
  • +
  • -

#45 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10647
  • View blog
  • Posts: 39,539
  • Joined: 27-December 08

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

Posted 21 January 2013 - 08:16 PM

StringTokenizer is legacy code and should be avoided in favor of the String split() method. Check out the String class for more information on String parsing.
Was This Post Helpful? 0
  • +
  • -

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