Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: confused and seeking advice

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default confused and seeking advice

    ok, i have never programmed java ever.
    i have programed in basic on the old spectrum 48k, easy amos on the amiga and have started using justbasic.

    i was told i would be better to try java as its an easyier language to learn ....so far im thinking i was lied to.

    ok the first step i took was to google jave tutorial, and followed a tutorial that had me download java jdk (it wanted me to download 2 but 6 was the only version i saw)
    it then wanted me to put the following into a notepad (you know not a java interface or anything that will help highlight syntex like justbasic does)
    class myfirstjavaprog
    {  
       public static void main(String args[])
       {
          System.out.println("Hello World");
       }
    }

    put it didnt explain what all this did, now i understand
     System.out.println("Hello World")
    is a rather long winded version of basics
     print "Hello World"
    (you see why i say this seems less easy lol)

    the bulk of my program will be randomly generating a roleplaying character and the characters background
    an example of my code in justbasic
    gosub [colour]
    gosub [meterial]
    let exp$ = " it is ";colour$;" and apears to be made of ";meterial$
    print exp$
    [colour]
    let colour = int(rnd(1)*17) + 1
    if colour = 1 then let colour$ = "red"
    if colour = 2 then let colour$ = "green"
    if colour = 3 then let colour$ = "orange"
    if colour = 4 then let colour$ = "black"
    if colour = 5 then let colour$ = "white"
    if colour = 6 then let colour$ = "blue"
    if colour = 7 then let colour$ = "gold"
    if colour = 8 then let colour$ = "silver"
    if colour = 9 then let colour$ = "light blue"
    if colour = 10 then let colour$ = "blood red"
    if colour = 11 then let colour$ = "amber"
    if colour = 12 then let colour$ = "gray"
    if colour = 13 then let colour$ = "purple"
    if colour = 14 then let colour$ = "yellow"
    if colour = 15 then let colour$ = "brown"
    if colour = 16 then let colour$ = "cream"
    if colour = 17 then let colour$ = "transparent"
    return
     
    [meterial]
    let meterial = int(rnd(1)*17) + 1
    if meterial = 1 then let meterial$ = "wood"
    if meterial = 2 then let meterial$ = "steel"
    if meterial = 3 then let meterial$ = "iron"
    if meterial = 4 then let meterial$ = "gold"
    if meterial = 5 then let meterial$ = "silver"
    if meterial = 6 then let meterial$ = "platnum"
    if meterial = 7 then let meterial$ = "stone"
    if meterial = 8 then let meterial$ = "ethreal"
    if meterial = 9 then let meterial$ = "a wierd metal that is cold to the touch"
    if meterial = 10 then let meterial$ = "iron"
    if meterial = 11 then let meterial$ = "wood"
    if meterial = 12 then let meterial$ = "stone"
    if meterial = 13 then let meterial$ = "iron"
    if meterial = 14 then let meterial$ = "glass"
    if meterial = 15 then let meterial$ = "glass"
    if meterial = 16 then let meterial$ = "alumenium"
    if meterial = 17 then let meterial$ = "obsidian"
    if meterial = 18 then let meterial$ = "diamond"
    if meterial = 19 then let meterial$ = "diamond"
    return

    is such a thing possible in java ? is it easier or harder?


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: confused and seeking advice

    it wanted me to download 2 but 6 was the only version i saw
    old school. Anyways, JDK 1.2 through JDK 1.6 are all roughly compatible (at least anything that runs on 1.2 should run on 1.6)

    If you're looking for a Java development environment, I would recommend getting Eclipse. Simply download "Eclipse for Java developers" (not the one for JavaEE developers unless you want to go towards web development). Note that eclipse for some reason doesn't like installers, so if you're running on windows just extract it somewhere and run eclipse.exe (you'll want to have the JDK and JRE installed, version 6 is the latest).

    Another good IDE is Netbeans. I've never personally like it too much, but it's equally as popular and as powerful as Eclipse.

    class myfirstjavaprog
    {  
       public static void main(String args[])
       {
          System.out.println("Hello World");
       }
    }
    Ok, so what this does is declare a Java class. If you're unfamiliar with object oriented programming, that should probably be a good idea to learn about first as Java is 100% object oriented (well, you can treat it somewhat as procedural, but it's really best not to).

    Anyways, the first line declares that you're defining a class called myfirstjavaprog. Everything in Java must lie inside a class/interface. I'm not sure if you're familiar with C/C++ syntax, but the curly brackets denote block statements. Also, they can be nested arbitrarily deep.

    class myfirstjavaprog // declares the class
    { // these denote the block which defines myfirstjavaprog
    }

    The inner stuff declares the main method. All java programs must enter at the main method (well, there are some exceptions but we'll forget about those for now). The main method must be declared to have:
    1. public access
    2. be a static method (don't worry about that for now, if you want to know more google the term "static java method")
    3. have a void return (meaning it doesn't return anything, not even the null object)
    4. Take 1 parameter which is an array of strings.

    put it didnt explain what all this did, now i understand
     System.out.println("Hello World")
    is a rather long winded version of basics
     print "Hello World"
    In a sense, yes. There are reasons why it must be done this way, and they have to deal with the object oriented nature of Java:

    System is a class which defines the interface between Java and the native OS. Inside of System there is a field allowing access to an object called out, which allows Java to output data to the standard output stream (stdout). println is a method which takes 1 parameter and prints it to the stdout, then prints out a newline. Rather than defining a "global method" (which isn't possible in Java) called print which automatically prints out to stdout, Java defines a class (specifically, the PrintStream class) which can print out to any stream. System.out just happens to be an instance of that class and it prints out to the stdout stream. This reduces code that needs to be written/maintained.

    Here are some good Java tutorials you could take a look at. They're made by Oracle (well, originally Sun) who develop and maintain Java.
    The Java™ Tutorials

    is such a thing possible in java ? is it easier or harder?
    Yes, it's possible (and in fact with a little bit of re-factoring to use enumerations, much easier in Java). Now the question is did you want a weighted chance of getting different materials/colors? If so, it's a little harder to implement, but it's still pretty easy.

    public enum Materials
    {
        wood, iron, gold, silver, platinum, stone, ethreal, a_weird_metal_that_is_cold_to_the_touch, glass, glass, aluminum, obsidian, diamond
        public String toString()
        {
            return super.toString().replace('_', ' ');
        }
    }

    public class Game
    {
    	public static void main(String[] args)
    	{
    		// implemented to get an equal chance for every material
    		// code for getting color is very similar
    		Materials material = Materials.values()[(int) (Math.random() * Materials.values().length)];
    		System.out.println("the item is made of " + material);
    	}
    }

    i was told i would be better to try java as its an easyier language to learn ....so far im thinking i was lied to.
    It's a very powerful language. Compared to C/C++ it is much easier to learn (no need to manage memory manually, some syntax is much less obfuscated). I'm not quite sure how it compares to basic for simplicity, but I'm positive that for larger projects Java will be much easier to use.
    Last edited by helloworld922; December 29th, 2010 at 06:31 PM.

  3. The Following 2 Users Say Thank You to helloworld922 For This Useful Post:

    JavaPF (December 30th, 2010), mrgreaper (December 29th, 2010)

  4. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: confused and seeking advice

    First thank you for the reply the detail was very much appreciated and i understand a lot more now then i did when i read the tutorial lol
    i think basic will serve my needs better for now, the program im doing is not for commercial gain just to help our group out.

    the choices would be weighted, certain things hould be more common hence the duplicates of it in the list, with java can i not get away with a similier principle just add duplicates to the list? (may seem academic to ask that since i have decided to go to back to basic but curiosity abounds )

    i have no knowledge of c++ which could be why im finding it so alien lol

  5. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: confused and seeking advice

    Yeah, but not using an enumeration.

    public class Game
    {
        public static void main(String[] args)
        {
            // code for getting color is very similar
            String[] materials = new String[] {"wood", "wood", "iron", "iron", "gold", "silver", "a strange metal"}; // ... shortened for simplicity
            String material = materials[(int)(Math.random() * materials.length)];
            System.out.println("the item is made of " + material);
        }
    }

    If you're just programming simple stuff for fun then there's not much benefit of switching. However, if you like programming larger projects and/or plan on doing it more seriously, then I would recommend moving to a more powerful and more commonly used language (Java, C, C++, C#, Python, Ruby).

    Actually, from personal experience I've found python very simple to use while still being extremely powerful. It looks somewhat similar to basic, and is syntactically somewhere between basic and Java. Ruby supposedly is similar to Python, however I've never used it.

    # this is similar to the above code but in python
    import random
    materials = ["wood", "wood", "iron", "iron", "gold", "silver", "a strange metal"]
    material = materials[int(random.random() * len(materials))]
    print("the material is " + material)

  6. #5
    Member
    Join Date
    Dec 2010
    Posts
    46
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Default Re: confused and seeking advice

    Quote Originally Posted by helloworld922 View Post

    import random
    materials = ["wood", "wood", "iron", "iron", "gold", "silver", "a strange metal"]
    material = materials[int(random.random() * len(materials))]
    print("the material is " + material)[/highlight]
    you are not fully making use of the random library
    material=random.choice(materials)

  7. #6
    Member
    Join Date
    Dec 2010
    Posts
    46
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Default Re: confused and seeking advice

    Quote Originally Posted by mrgreaper View Post
    i was told i would be better to try java as its an easyier language to learn ....so far im thinking i was lied to.
    Try Python, you will never look back at Java ever.

  8. #7
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: confused and seeking advice

    Quote Originally Posted by JavaHater View Post
    you are not fully making use of the random library
    material=random.choice(materials)
    I didn't peruse the Python API very thouroughly.

    Try Python, you will never look back at Java ever.
    I did, and I'm much more comfortable using Java. However, I'm one of those people who fall into the category of those who prefer strong-typed over weak-typed languages. There are plenty of people who are the other way around. My favorite weak-typed language is actually matlab, but that's because I do a lot of scientific and engineering computing (python is a nice second, especially when used with SciPy).

  9. #8
    Junior Member
    Join Date
    Dec 2010
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: confused and seeking advice

    I know a loads of people learn programming languages from "Internet Resources"(I too am learning JAVA this way). However, for someone who is new the concept of OOP(Object Oriented Programming), I would suggest you to buy a book regarding the subject matter, not that it is necessary. I learned the basic concept of OOP from C++, however C++ was not strict on the concepts of Objects as Java is. I remember learning QBasic when I was a kid (but unfortunately have barbecued everything in my brain relating the language). But I can assure you Java is a fun language. It's been my 2nd week so far and I'm already loving it. Besides, there are more Java programmers in the world right now than any other languages, so this means there are more programs written in Java, which in-turn means, these programs have to be maintained and upgraded, which, finally means more job listings to grab relating Java.

    P.S. Two of my friends always argue about Python, that whether it is a programming language or a scripting language(I don't see the difference). I have never tried Python, but have been hearing people calling it "The next JAVA". I have also heard remarks saying Java is a "Hybrid Language". If someone could shed light on this matter, I think it would help OP to decide much better.
    Last edited by mick.bhattarai; December 31st, 2010 at 03:40 PM.

  10. #9
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: confused and seeking advice

    Python will never be the next "java" for two key reasons (there are others, but these are the main two):

    1. Python is "weak-typed". That means you don't have to declare the type of variables, and the same variable can be used to hold objects of different types. Java on the other hand is strong typed. You must declare the type of every variable and that variable can only hold objects of that type (or objects of sub-types via polymorphism)
    2. Python isn't 100% object oriented. It does have object oriented concepts in it, but it's possible to program in Python without ever using objects (granted, this could get quite difficult and ridiculously extreme without using objects). Java on the other hand is designed to be 100% object oriented. You could use Java as a semi-procedurally, but it's still object oriented.

    I'm not sure what you mean by "hybrid language", I've never heard this term before. However, I suspect you mean that they are interpreted languages.
    Java and Python are both considered interpreted languages because they don't compile down to machine code. Instead, they're compiled into something known as "intermediate code" (in Javas case, this is also known as Java Bytecode). Then another program (for Java it's the JVM, in Python it's the Python runtime) reads in the intermediate code and executes it. Machine code can be executed directly by your computer. Intermediate code can't be executed by your computer directly. Note that both Java and Python support something call "Just in time" compilation where the intermediate code gets compiled to machine code at runtime, however they are still considered interpreted languages.

    I don't see the difference between the terms "programming language" or "scripting language", either. The lines are so blurred nowadays that it's pretty much impossible to tell the difference between the two.

  11. #10
    Member
    Join Date
    Dec 2010
    Posts
    46
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Default Re: confused and seeking advice

    Quote Originally Posted by helloworld922 View Post
    Python will never be the next "java" for two key reasons (there are others, but these are the main two):
    it depends on what one means by "next Java". If you mean ease of use, not long winded, general purpose programming, rapid development, batteries included, better data structures etc, then Python can be "the next Java and beyond". In that case, the reasons that Python is "weak typed" or isn't 100% object oriented is totally wrong.

    1. Python is "weak-typed". That means you don't have to declare the type of variables, and the same variable can be used to hold objects of different types. Java on the other hand is strong typed. You must declare the type of every variable and that variable can only hold objects of that type (or objects of sub-types via polymorphism)
    This, can be good or bad. For me, its good, because I want to develop my code fast and get the job done fast. Its bad because I am not a static type fan (.

    2. Python isn't 100% object oriented. It does have object oriented concepts in it, but it's possible to program in Python without ever using objects (granted, this could get quite difficult and ridiculously extreme without using objects).
    You are quite wrong about that. doing things procedurally and using objects are 2 different things. In Python, strings are objects. ie you can do things like this
    >>> "my string".upper()
    'MY STRING'
    >>> (7).__add__(5)
    12
    Note, that using the dot operator constitutes object oriented concepts (remember things like "this" or "self ? )
    and this is an example of procedural code using OO
    import sys
    print "My string in lower case is " + "MY STRING".lower()
    print "7 added to 5 is " ,  (7).__add__(5)
    sys.exit()


    Java on the other hand is designed to be 100% object oriented.
    quite wrong again. If its designed to be 100% OO, then why you can use int, byte etc?

    You could use Java as a semi-procedurally, but it's still object oriented.
    That doesn't mean Python isn't as i illustrated.

    you might want to see this and this for similar discussion

    I'm not sure what you mean by "hybrid language", I've never heard this term before. However, I suspect you mean that they are interpreted languages.
    in his context, i think he meant can be used procedurally or OO

  12. #11
    Member
    Join Date
    Dec 2010
    Posts
    46
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Default Re: confused and seeking advice

    Quote Originally Posted by mick.bhattarai View Post
    P.S. Two of my friends always argue about Python, that whether it is a programming language or a scripting language(I don't see the difference)
    it doesn't matter, as long as you use it to get the job done and you are satisfied with it. You can call them anything you want.

    I have never tried Python, but have been hearing people calling it "The next JAVA".
    Python is not Java, and Java is not Python. However, depending on the person and the situation, Python can be a more productive tool to use for a job as compared to Java.
    1) Less verbose
    2) Abundance of libraries provided, eg FTP, Telnet, SMTP, MIME, etc
    3) Ease of use of data structures such as dictionaries. eg dictionary = { "1" : 1 , 1: "one" }. Note, the keys can have different data types
    4) File I/O is easy. (if you look at those code that use BufferedReader etc etc, you will know what i mean)
    5) String manipulation is easy. ( eg "abc"[:2] returns "ab". )
    6) Python shell enables you to debug/test your code on the fly.
    7) many others.
    Last edited by JavaHater; January 1st, 2011 at 06:39 AM.

  13. #12
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: confused and seeking advice

    Touche It's always nice to learn new things, though (and dig up old things I did know at one point or should have known when I posted that).

    Perhaps I could re-phrase what I posted above:

    One thing mentioned on one of those sites you posted to points of the OO paradigm. True you need objects to operate on (which both python and java have), however it's how you use, or don't use, these objects which is important. A key component is missing from the python implementation: true encapsulation or "data hiding". It's really one of the more obscure points and arguable you could say Python has it via the underscore naming convention (for better or for worse).

    Does it really matter that Python doesn't have true encapsulation? I'd argue no as long as the programmer has some decent knowledge about the language and CS in general.

    In any case, I don't think either language could be argued "absolutely better" than the other. Programming languages are just tools, and you should choose the tool to match the job. Sometimes multiple tools can fulfill the requirements of the job equally well and sometimes one tool is easier and/or better at performing a particular job than another.

    I've always been a fan of the "strong-typed" languages (C/C++, C#, Java, etc.). It's really a personally preference thing and I know that there's not really much rational behind it. Both can be used effectively, and equally both can be used ineffectively.

Similar Threads

  1. A little advice please:
    By SDKC in forum Java Theory & Questions
    Replies: 1
    Last Post: December 8th, 2010, 08:15 PM
  2. Need some help/advice for my GUI code.
    By J-Ark in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 4th, 2010, 12:23 PM
  3. Need some general and specific advice.
    By Morevan in forum Loops & Control Statements
    Replies: 2
    Last Post: January 3rd, 2010, 11:31 PM
  4. Programming advice
    By silverspoon34 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 6th, 2009, 04:19 PM
  5. i need some advice ....
    By mdstrauss in forum Java Theory & Questions
    Replies: 8
    Last Post: July 24th, 2009, 02:29 PM