Results 1 to 4 of 4

Thread: Could you guys entertain a few questions?

  1. #1
    Join Date
    Sep 2008
    Location
    Midland, Texas
    Posts
    52
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Question Could you guys entertain a few questions?

    Could you guys entertain a few questions?

    I have written a few posts to this forum and as I said before, I am a newbie to programming, as far as programming languages is concern. Recently I purchased the “Java, The Complete Reference” and I must admit it is addictive, at least for me. I just finished chapter eight, inheritance, and I have a few random questions for you guys.

    1. I understand the difference between default, public, private and protected, but how much use does “private” and or “protected” gets in real world? Could you guys give me a few examples of when it is convenient to use one over the other?
    2. Also, maybe I am a bit confused, but I keep reading about people writing malicious code which could affect a program I might write, but doesn’t the fact that programs are compiled into Java bytecode help to avoid the problem of people opening up and reading the program code?
    3. Would it be wise for me to begin, whenever I am ready, writing all my programs as public and as the need arises and I feel more comfortable begin using “private”?
    4. Also, I read some of the other posts and I noticed that some of you keep referring to the “How to program in Java” by DIETEL. Is this a must have book? I want to learn the language and eventually (as soon as possible) get certified because I really like it, and while I don’t mind spending money on a worthy cause or item, I don’t want to go broke purchasing every other book on the same subject.

    I really appreciate the fact that you guys take the time to help people like me. Thanks in advance for your help and patience. Hopefully one day in the not too distant future I’ll be able to submit postings that are up to par with your. Thanks again.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    1. I understand the difference between default, public, private and protected, but how much use does “private” and or “protected” gets in real world? Could you guys give me a few examples of when it is convenient to use one over the other?
    A lot. When you are considering the design of your class, there are two different structures you must take into consideration: the API, and the implementation. The API is the interface to the class that everybody's going to use. If you have a lot of users of your class, changing the API will break all their code. As such, the API should change as little as possible (so make sure you've thought it out well when you initially designed it). Properties and methods belonging to the API will be designated public, since other people will have to access them. Meanwhile, in the bowels of the class, there will be all sorts of properties and methods used to help implement that API. These should not be public, since if they were public they would be part of the API, and you would have to avoid changing them for fear of breaking existing code. If they're kept private, you can modify them as much as you want. Depending on how your class is intended to be used, these will be either private or protected — if you want your class to be extended, then the methods that the subclass will have to override must be protected, not private, but this does in a manner add them to the API, since people can and will make their code rely upon them by the act of extending the class.
    2. Also, maybe I am a bit confused, but I keep reading about people writing malicious code which could affect a program I might write, but doesn’t the fact that programs are compiled into Java bytecode help to avoid the problem of people opening up and reading the program code?
    No. Compilation is an efficiency measure, never one of security, especially in Java's case: Java bytecode can be decompiled with a fairly high rate of accuracy. There are less potential security issues in Java code than in a lower-level language like C, because the runtime takes care of a lot of things for you automatically, such as memory management and string termination, but if you're careless somebody could still get through.
    3. Would it be wise for me to begin, whenever I am ready, writing all my programs as public and as the need arises and I feel more comfortable begin using “private”?
    No — quite the opposite. Be conservative until you have enough experience to know when a method is good and should be added to the API. Of course, if only you will ever be using your classes, it doesn't matter so much anyway
    4. Also, I read some of the other posts and I noticed that some of you keep referring to the “How to program in Java” by DIETEL. Is this a must have book? I want to learn the language and eventually (as soon as possible) get certified because I really like it, and while I don’t mind spending money on a worthy cause or item, I don’t want to go broke purchasing every other book on the same subject.
    I did some research amongst the Java-ites, and it seems that the most highly recommended book is Thinking in Java, by Bruce Eckel. However, they and I all agreed that Java is not a very good first language — it will give you bad habits. Rather, I would suggest you'd be better off with a different language, like Python, Javascript, Scheme, or Haskell. Personally I think that Scheme is particularly good as a first language — you can probably learn Scheme as a side-effect of going through the excellent book, Structure and Interpretation of Computer Programs, which will give you a brilliant introduction to and perspective on programming languages in general. If you really want to jump into practical programming immediately, you'd be better with one of the other three I suggested, but I really do recommend going through SICP first.
    Last edited by Twey; 10-05-2008 at 10:39 AM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. The Following User Says Thank You to Twey For This Useful Post:

    xtiano77 (10-05-2008)

  4. #3
    Join Date
    Sep 2008
    Location
    Midland, Texas
    Posts
    52
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    Could you explain what you mean by “bad habits”? I don’t understand why is Java not a very good program? Basically, what I want to do is learn the program for personal use and later, with a lot of practice and experience, for professional use. I have a “Beginners Javascript book” and also an advance one, but the book itself suggest that I learn something like Java before I try to read that book. But, isn’t Javascript scripting not programming?

    Can one compile Python so it can be run in other computers that don’t have it installed in them? Would Python make my efforts of learning Java easier? I chose Java because at work (government) that is all we pretty much use, and after talking with some of our IT guys, they suggested that I should jump from Javascript straight into Java. Also, I like the portability and flexibility of it. Originally, I was considering going the PHP route just to get started, but as I said, they suggested that since PHP is an open source, it wouldn’t really be worth my time if I want to write professionally in the future. Was I wrong on that? I guess what I am trying to say is that I want to learn programming and be good at it, and if I have to follow a specific order when it comes to learning the different languages, then I’ll do just that, I just want to know the order that needs to be followed. Can you shed some light in that respect as well? Thanks for your help so far.

  5. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Could you explain what you mean by “bad habits”? I don’t understand why is Java not a very good program?
    Because it's not very powerful, and as a result your reaction to problems will be to do things like copy-pasting code, rather than trying to find a better solution: your problem-solving skills, which can be put to use in more powerful languages, will remain undeveloped.
    I have a “Beginners Javascript book” and also an advance one, but the book itself suggest that I learn something like Java before I try to read that book.
    That is most peculiar of it. Perhaps the author was labouring under the misconception that Java and Javascript are somehow related. They aren't: Javascript is a much more powerful language.
    But, isn’t Javascript scripting not programming?
    'Not programming' is a bit of an iffy definition. Javascript can be considered a fully-fledged programming language; it's just not really suitable for many powerful applications, due to performance issues with a lot of its implementations, and oddities in the specs themselves. You can, however, do things in it that are much more advanced than is possible in Java.
    Can one compile Python so it can be run in other computers that don’t have it installed in them?
    Yes and no — it does require a runtime in order to run (like Java), but that runtime is small and easily distributed with the application (unlike Java).
    Would Python make my efforts of learning Java easier?
    Learning programming and learning a programming language are two different tasks that are often tackled together. Learning any language will make learning another easier, merely by having learnt to program with the last language. If both languages are of the same paradigm, the effect is increased. Therefore, yes, learning Python will make learning Java considerably easier, since both are imperative, object-oriented languages.
    I chose Java because at work (government) that is all we pretty much use
    Then, practically speaking, it certainly does sound like it's worth-while for you to learn Java — but I still don't recommend it as a first language. Develop your programming ability with a better language, then move to Java and apply what you've learnt.
    Originally, I was considering going the PHP route just to get started
    PHP is marginally better than Java, but still considerably less powerful than any of the languages I've mentioned above. I wouldn't recommend it as a first language, either.
    but as I said, they suggested that since PHP is an open source, it wouldn’t really be worth my time if I want to write professionally in the future.
    That is sheerest rubbish: PHP is used in many professional capacities, probably even more than Java (although Java does tend to be used in larger products, due to its static typing, which makes maintaining cohesion between modules of large products easier [a trait shared (and done better) by Haskell and, optionally, Common Lisp]). The open-source community is where most breakthroughs in development occur. Java is also open-source: there have been open-source implementations of Java for a long time, and recently Sun opened up the official implementation, too.
    I guess what I am trying to say is that I want to learn programming and be good at it, and if I have to follow a specific order when it comes to learning the different languages, then I’ll do just that, I just want to know the order that needs to be followed. Can you shed some light in that respect as well?
    If there are no time constraints, then the order I would recommend, for a high-level software developer, is as follows:

    Scheme -> Javascript -> C -> Python -> Erlang -> Haskell

    So, at each step of the way, you would learn:

    Scheme: the basics of programming, as well as the low-level implementation details of programming languages. Scheme has a very simple syntax that allows very powerful abstractions to be built upon it; as such, it should be ideal to teach you about programming, since the language itself won't get in your way much, either by trying to be excessively helpful or by limiting what you can do. SICP will help greatly with this, and also uses Scheme for those reasons. Functional programming. Imperative programming, and why it's often not as good an idea as some people would like to think.

    Javascript: the way the syntactic sugar that other languages tend to apply works. The imperative mindset and where it can be useful. The common C syntax and control structures that many languages (including Java) implement. A form of object-orientation, specialising on the first argument (like Java) but prototypical (unlike Java). More about imperative programming, and imperative counterparts to many functional constructs. A form of reflection (different from Scheme's, since Javascript does this differently to Scheme [whose reflection is more powerful]). Encapsulation.

    C: data structures in an almost purely imperative language. A close understanding of things like pointer size and arithmetic, and how the structures you use in higher-level languages are represented underneath. Knowledge of when it's better to use a higher-level language, and when you need to get close to the hardware.

    Python: class-based object-orientation. Reflection in class-based object-orientation (and comparison to both Scheme and Javascript's versions of reflection, since neither have native classes). When OO makes sense, and when it doesn't. Modularity and namespaces. The benefits of simplicity. When to use encapsulation.

    Erlang: a purer functional language than Scheme. Building powerful, fault-resistant applications. Benefits of standardisation. Effective concurrency and the benefits therein. How to design applications to take full advantage of concurrency.

    Haskell: pure functional programming. Types, typeclasses, and some type theory. Benefits of abstraction. Perhaps an understanding of programming language power and expressiveness, and how something that can take a whole page of code in one language can take only a few lines in another. A different type of simplicity: mathematical elegance.

    These languages are arranged so that each builds upon the one before, adding some new concept or paradigm to the mix, but keeping to enough of what you've already learnt that each step should be quite easily manageable for you. After that, you should be able to learn pretty much any programming language out there today with ease. Java will certainly be a snap, since you'll have covered all the concepts of Java — although you might find yourself somewhat frustrated by the constraints that Java's lack of expressiveness places upon you. There are practical uses for all of them: each lends itself to a different type of application, although you might not recognise how best to use some of them until you encounter their problem domains.
    Last edited by Twey; 10-05-2008 at 07:20 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. The Following User Says Thank You to Twey For This Useful Post:

    xtiano77 (10-05-2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •