Results 1 to 7 of 7
  1. #1
    lolgrapig112 is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Question Best way to use bridge diffrent classes

    Dear,

    First of all I'm new to the forums so hello all :) And I think I will be here for a long, long time.

    But here is the qeustion, I am programming java for some time now mostly just for practice. But I whas wondering if my method of creating a refrence from one class to another is good or if there is a better one.

    So this is the idea. we have 2 classes:

    main and methods

    main is just the startup code that will refere to all the code's that is needed.
    methods contains all the code to run for the input and output.

    now what I do like when I need to cast some code in main from methods is:

    Java Code:
    methods mh = new methods();
    //to refere it
    //after that i just run the code like:
    
    mh.print("123test123");
    I think there is nothing wrong with that. But I whas wondering if you could make a way to code it like a library that you don't need
    the methods mh = new methods() part and just import it and run it.

    Like:

    Java Code:
    import com.test.methods;
    and then just typ the methods you like to run.
    Thanks in advance.

    Greetz,
    me

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Best way to use bridge diffrent classes

    If your methods are stateless, and only then, you could make them static.
    Have a look at the coding conventions, class names start with a capital letter.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    lolgrapig112 is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Default Re: Best way to use bridge diffrent classes

    Quote Originally Posted by PhHein View Post
    If your methods are stateless, and only then, you could make them static.
    Have a look at the coding conventions, class names start with a capital letter.
    Thanks for the stateless explenation. Still had to google what it meand.

    But I think you made a mistake with saying class names are written with a capital letter. If you name the class without it
    you should refere to it without it. main != Main. But I believe you tried to say they normally are so. I take this at advice. And wil use a capital letter next time.

    Thanks,
    Me

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,930
    Rep Power
    5

    Default Re: Best way to use bridge diffrent classes

    Quote Originally Posted by lolgrapig112 View Post
    But I think you made a mistake with saying class names are written with a capital letter. If you name the class without it
    you should refere to it without it. main != Main. But I believe you tried to say they normally are so. I take this at advice. And wil use a capital letter next time.
    He is correct. Class names by convention (and interfaces) begin with a capital letter. Variables usually start with a lower case letter (unless they are constants in which they are usually all upper case).

    So

    Java Code:
    methods mh = new methods();
    // should be written as 
    Methods mh = new Methods();
    // where the class is 
    class Methods {
      // stuff here
    }
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    lolgrapig112 is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Default Re: Best way to use bridge diffrent classes

    Ah but

    Java Code:
    //if class =
    class methods {
           //stuff here
    }
    methods mh = new methods();
    //works to...
    But probally it's not the right way to do it as I am reading the conventions. Never know their whas a guide line for java developers in how to write code.
    Thanks for the advice and for the help!

    Also I prefere this:

    Java Code:
    class Something 
    {
    
    }
    over this:

    Java Code:
    class Something{
    
    }
    Is that wrong to ? To put the {} like that ?

    Greetz,
    Me

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,930
    Rep Power
    5

    Default Re: Best way to use bridge diffrent classes

    Your style is yours and that is fine. I prefer the former. And some companies probably dictate what they want. Fortunately, modern IDE's allow one to reformat code.

    And if you are interested, there is a link to the Java naming conventions in my signature.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    lolgrapig112 is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Default Re: Best way to use bridge diffrent classes

    Quote Originally Posted by jim829 View Post
    Your style is yours and that is fine. I prefer the former. And some companies probably dictate what they want. Fortunately, modern IDE's allow one to reformat code.

    And if you are interested, there is a link to the Java naming conventions in my signature.

    Regards,
    Jim
    Thanks alot I prefere to call this case closed. Reading the java naming conventions.

    Greetz,
    Me

Similar Threads

  1. Diffrent screen resolution
    By tnrh1 in forum CLDC and MIDP
    Replies: 0
    Last Post: 11-14-2012, 08:28 PM
  2. Access textarea from diffrent class
    By nihar_deb in forum New To Java
    Replies: 1
    Last Post: 05-24-2011, 04:39 PM
  3. How to keep a string through out diffrent methods
    By bmist in forum Java Applets
    Replies: 33
    Last Post: 05-27-2010, 07:24 PM
  4. Add diffrent components in jtable
    By anilkumar_vist in forum Advanced Java
    Replies: 1
    Last Post: 11-23-2009, 06:03 AM
  5. diffrent page redirection in struts.
    By rakesh_n_mehta in forum Web Frameworks
    Replies: 0
    Last Post: 12-11-2008, 07:34 AM

Tags for this Thread

Posting Permissions

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