Results 1 to 12 of 12
  1. #1
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default Creating custom objects

    i've experienced a little with objects.
    i know how to define objects, with the new keyword.
    and how to use them after that.

    for example i made this:
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package javaapplication2;
    
    import java.awt.*;
    import java.util.*;
    public class URL {
    
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
    
    String sb = new String("He110 W0r1d!");
    System.out.println(sb.toLowerCase());
    System.out.println(sb.toUpperCase());
    
        }
    
    }
    now my question is, how can i make custom objects. that are not in the API database.
    Is it possible to create your own objects, like this:
    Java Code:
    CustomObject object = new Customobject;
    if it's possible i need to make a function in another class that describers what CustomObject does.
    I tried this but don't know how to.

    Can anyone explain me how to make custom objects?

  2. #2
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    maybe this will help
    Classes etc.
    a more presice question would be great.
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

  3. #3
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    can anyone explain me how to make custom objects?

    isn't that kinda precise

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by coltragon View Post
    can anyone explain me how to make custom objects?

    isn't that kinda precise
    You really should start reading the Sun tutorials because they explain in great detail what classes are all about. A class defines a type and its operations; the operations are the methods defined in the class. A pure type only tells what the type can do, not how it does it and those pure types are Java's interfaces. A class can implement an interface by telling how those things should be done. The things or objects that do all the work in Java are instantiations of classes; think of those classes as the blueprints of objects. Study those tutorials and play with the examples, your computer won't explode.

    kind regards,

    Jos

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    I agree with above posters, read the tutorials. However, maybe this will get you started:
    Java Code:
    public class MyCustomClass {
        String name = "Bobbert";
        String father = "Billiam";
        int age;
        
        public MyCustomClass(int age){
            this.age = age;
        }
        
        public int getAge(){
            return age;
        }
    }
    Then we can use it like this:
    Java Code:
    public class Driver {
        public static void main(String[] args) {
            new Driver();
        }
    
        MyCustomClass theClass;
    
        public Driver(){
            theClass = new MyCustomClass(16);
            System.out.print("Name is: ");
            System.out.println(theClass.name);
            System.out.print("Father is: ");
            System.out.println(theClass.father);
            System.out.print("Age is: ");
            System.out.println(theClass.getAge());
        }
    }
    Also note that in your example, the class you made called 'URL' is a 'custom class' as you put it.

    Good luck!

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by coltragon View Post
    can anyone explain me how to make custom objects?
    isn't that kinda precise
    Nope, that's a very general question, one that's best answered by studying the tutorials.

  7. #7
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    evrything can be learned with tutorials.

    why is forum here then?

  8. #8
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    why is forum here then?
    I'd argue that learning the language syntax, structure, and even a touch of implementation is gleanable from tutorials, this forum exists for advice on specific implementation questions, bugs, logic questions, etc...

    I think most on this forum expect you spend some time reading the manual before asking specific questions. Asking something like 'How do I make games' would be an example of a vague question where as 'what is the best method to evaluate execution time of an algorithm?' is sufficiently specific yet still has room for discussion.

    I think what all the others are trying to say, is that everything about how to use basic language functions (like object declaration and subsequent use of said object) is contained in some of the first java tutorials you read. 95% of the time you spend programming (and learning it) will be self study (and has to be - there is simply too much information to convey all at once). Most of us have spent many years learning how to program, and learning the ins and outs. If you want users to spend time helping, they want to see that you've spent time trying to learn. Thats all, I don't think anyone has any hard feelings :)

  9. #9
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    but who said i didn't read the sun tutorials?

    i did understand how to make custom objects.
    and there is still a New java section in here, you cane expect noobie questions

  10. #10
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Ok, well, you defined a custom object in your original example, which I mentioned, and I gave you code for defining one as well, and if you indeed followed the sun tutorials as well, then I don't know what else to tell you. Did you even read the code I gave you?

  11. #11
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    i did read it, i already understand how to do it now.
    but i was just discussing the fact, that here on the forum for every question i post.
    the awnser always is: read the tutorials.

    if you don't understand me, and you ask me: do you understand this?
    and than i say just google it or read a book.
    would yoou like that?
    Last edited by coltragon; 12-29-2009 at 06:43 PM.

  12. #12
    adz
    adz is offline Member
    Join Date
    Jul 2009
    Posts
    35
    Rep Power
    0

    Default

    Well tutorials are generally a very good source of information and as they are written by Sun, they are also going to be accurate and exact.

    Also just to note, never do this:
    Java Code:
    String a = new String("whatever");
    Do the following instead:
    Java Code:
    String a = "whatever";
    The first creates two objects :/

Similar Threads

  1. Creating an Array of Objects
    By int80 in forum New To Java
    Replies: 4
    Last Post: 08-09-2011, 12:40 PM
  2. Creating Array of Objects
    By chathurajeewaka in forum New To Java
    Replies: 4
    Last Post: 12-03-2009, 03:23 PM
  3. Creating an array of objects
    By geowizard in forum New To Java
    Replies: 5
    Last Post: 11-16-2009, 01:25 AM
  4. Creating Custom annotations
    By ajeeb in forum New To Java
    Replies: 2
    Last Post: 04-02-2009, 08:14 PM
  5. Creating objects question
    By sergm in forum New To Java
    Replies: 2
    Last Post: 12-27-2007, 04:10 PM

Posting Permissions

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