Using main class's methods from a different class in the same file

Hi guys. Migrating from C++, hit a few snags. Hope someone can furnish a quick word of advice here.
1. The filename is test.java, so test is the main class. This code and the topic title speak for themselves:
class SomeClass
     public void SomeMethod()
          System.out.println(test.SomeOperation());
public class test
     public static void main(String args[])
          SomeClass someObject = new SomeClass();
          someObject.SomeMethod();
     public static String SomeOperation()
          return "SomeThing";
}The code works fine. What I want to know is, is there some way to use test.SomeOperation() from SomeClass without the test.?
2. No sense opening a second topic for this, so second question: Similarly, is there a good way to refer to System.out.println without the System.out.? Like the using keyword in C++.
Thanks.

pfiinit wrote:
The code works fine. What I want to know is, is there some way to use test.SomeOperation() from SomeClass without the test.?Yes you can by using a static import, but I don't recommend it. SomeOperation is a static method of the test class, and it's best to call it that way so you know exactly what your code is doing here.
2. No sense opening a second topic for this, so second question: Similarly, is there a good way to refer to System.out.println without the System.out.? Like the using keyword in C++.Again, you could use static imports, but again, I don't recommend it. Myself, I use Eclipse and set up its template so that when I type sop it automatically spits out System.out.println(). Most decent IDE's have this capability.
Also, you may wish to look up Java naming conventions, since if you abide by them, it will make it easier for others to understand your code.
Much luck and welcome to this forum!

Similar Messages

  • I would like to import two different cf cards from two different cameras into the same project/folder and have them be in order of the times they were taken, is there a trick?

    I would like to import two different cf cards from two different cameras into the same project/folder and have them be in the order of the times they were taken, any ideas on how to do this?

    Just import them normally and sort the project by date. They will fall into place. If you tried this and it isn;t happening then make sure the data and times on the two cameras are identical and make sure you are sorting by date and time and nothing else.

  • HT1473 If I already own a song (from a different album) and the same song is in an album which I want to get, do I still have to pay for the song?

    Other details:
    First album/s- Dookie (Green Day), american idiot (green day)
    and 21st century breakdown (green day)
    Album with same songs in it- international super hits (green day)

    If I already own a song (from a different album) and the same song is in an album which I want to get, do I still have to pay for the song?
    Yes.
    The album which the song has been listed under (on the song's page) is listed in your library under that album. The song is then removed automatically from the first album
    No it's not.
    Purchasing a new song or album will not affect any other song or album in your library.
    In the case of the two albums you mention, if you purchase them both, you will have the same song (different copies) in both albums.

  • Different photos with the same file name!! How to change this?

    While I was organizing my photos, I realized there are about 30 or so photos that have the same exact file name as another photo. Example: There are two IMG_1243.jpg, but they are different pictures. They were taken at different times, even different years. I have used more than one camera to import photos. I have changed the name of one of the photos in the Title area in the information section of iPhoto. When I try to put the newly named photo into a folder that has the other IMG_1243, I get a message that says" An older item named "IMG_1243" already exists. Do you want to replace it with the newer one you are moving?"
    I want to have both IMG_1243.jpg photos in the same folder. How can I do this? Also, I have a few thousand pictures, so how can I tell exactly how many photos have the same file name as another photo?

    Celtic Mom
    Welcome to the Apple user to user discussion forums
    While I was organizing my photos, I realized there are about 30 or so photos that have the same exact file name as another photo. Example: There are two IMG_1243.jpg, but they are different pictures. They were taken at different times, even different years. I have used more than one camera to import photos. I have changed the name of one of the photos in the Title area in the information section of iPhoto. When I try to put the newly named photo into a folder that has the other IMG_1243, I get a message that says" An older item named "IMG_1243" already exists. Do you want to replace it with the newer one you are moving?"
    I want to have both IMG_1243.jpg photos in the same folder. How can I do this? Also, I have a few thousand pictures, so how can I tell exactly how many photos have the same file name as another photo?
    It sounds like you are using the finder inside the iPhoto library - do not do that - you will corrupt your library and lose the edits, keywords, etc that you have
    iPhoto does not care about duplicate file names - it handles it fine
    changing the title of a photo does not affect the file name - although when you export the photo you can use the title for the file name as an option
    What are you doing and what do you want to accomplish?
    Remember do not ever make any changes in the iPhoto library using the finder or any other program
    LN

  • Problems calling a method from a different class

    Like many programmers, I'm having a go at making my own chat room. All has been going well so far, however I am having trouble calling the method which connects the client to the server, from the method which actually starts the server.
    The method for starting the server:
    public static void serverStart () throws IOException {
            new Thread () {
            public void run() {
                try {
                    ServerSocket serverSock = new ServerSocket (client.serverPort);
                while (true) {
                    Socket serverClient = serverSock.accept ();
                    ChatHandler handler = new ChatHandler(serverClient);
                    handler.start ();
                } catch (IOException ex) {     
                    connectTo.handleIOException(ex);     
            }.start();
            try {
                connectTo.start();
            } catch (IOException ex) {
                connectTo.handleIOException(ex);
        }The part of interest is the "connectTo.start()" line, as this is the one which calls a method in the class connectToMethod which tells the client to connect to this newly started server. Now for the client connection code:
    public synchronized void start () throws IOException {
          if (listener == null) {
              Socket socket = new Socket (client.serverAddr, client.serverPort);
              try {
                  dataIn = new DataInputStream
                          (new BufferedInputStream (socket.getInputStream ()));
                  dataOut = new DataOutputStream
                          (new BufferedOutputStream (socket.getOutputStream ()));
              } catch (IOException ex) {
              socket.close ();
              throw ex;
          listener = new Thread (this);
          listener.start ();
      }Now when the server starts, it should automatically start the connection method "start()" and connect to itself. However I am getting a NullPointerException error at the line "connectTo.start();" from the server code. The server and connection client actually work separately, just not when I try to connect from the server itself. I have tried a few ways of getting around this problem, all without success. If anyone could give some input on what might be wrong, or a possible way to fix it, I'd be very grateful.

    Sorry, connectTo comes from:
    connectToMethod connectTo = new
    connectToMethod();
    That doesn't necessarily mean this variable reference is the same one as in the code where the NullPointerException was thrown though.
    Or the exception was thrown inside the start() method. The runtime isn't lying to you. You have a null reference (pointer) where it says you do.

  • Can I view another page from a different application in the same workspace?

    I'm a newbie and I've searched through the threads and can not find exactly what I'm looking for.
    I do not wish to copy a page from a different APP. What I want to do is create an application where on tab is actually a tab from a different App.
    Like this, I have SCHEDULED_TASKS application that has a calander that is updated weekly. I have another appliction that is used for our Database Testers to track testing on the database.
    I have a Tab in CAS_TESTING named TESTING_SCHEDULE. It is this tab that I want to have referance the SCHEDULED_TASKS Calender so testers can view the schedule for service packs.
    Is there a way that I can do this?
    Thanks,
    Mike Long
    Message was edited by:
    mikedlong

    Mike,
    In terms of the UI and tabs, you can use parent tabs (use a two-level tab page template). Or you could just put links in on app's pages that go to the other app using Lists, for example. In any of these links from one app to the other, you must include the session ID (&APP_SESSION.).
    If the application's are both public (no authentication required), you're done.
    If the apps require authentication, edit each app's authentication scheme and put some name in for cookie name (anything you like), using the same name in both apps. Depending on the authentication method, you then have to figure out who owns the login page, etc.
    That should do it.
    Scott

  • How to Get Choices as a Dropdown from a different Column for the same Item In a Document Library?

    Hello All,
    I was trying to see if there is any way that we can get the choices for a Field from another filed in the same item in a Document Library.
    To be specific.
    I have Created a Project Document Set, Which has a Column called "Project Members" where all the members will be listed. This will be inherited to all the documents in that Project Document Set. This is used to grant Permission using Workflow.
    I also have "Document Members" Column(This is only for Documents) who will be given Edit permissions to that Document using a Workflow. This can be any type of column(choice, People or Group etc) As long as I can select multiple values.
    I am looking for a way to get the "Project Members"(Values or Users) as choices for "Document Members". I know this is possible in the List as you can customize in the InfoPath Form. But not sure in the Document Library.
    Document Members can only be the members from the Project Members, In order to grant granular Permissions for the project And Documents using a Workflow
    Document Library
    Project Document Set Name
    File Name
    Project Members
    Document Members
    Project A
    User1;User2;User3
    Doc1
    User1;User2;User4
    User1;
    Doc2
    User1;User2;User5
    User1;User2;
    Doc3
    User1;User2;User6
    User1;User2;User3;
    Project B
    User5;User6;User7;
    Doc1
    User5;User6;User7;
    User7;User5
    Doc2
    User5;User6;User7;
    User7;User5
    Doc3
    User5;User6;User7;
    User5;User6;User7;
    Thanks for your time.

    >
    Jenny Karunakaran wrote:
    > Hi Jung,
    >
    > Thanks for the reply. But I dont know how to assign value set to this attribute(i.e. Context atribute to which filter value property is bound). Can I use a supply function for this ?
    >
    >
    > Regards,
    > Jenny
    No. A value set and a supply function are two completely different things. You use this Context API to populate the value set for an attribute:
    IF_WD_CONTEXT_NODE_INFO=>SET_ATTRIBUTE_VALUE_SET
    Value Sets are also how ByKey UI elements (like the DropDownByKey) are built.  Here is a help document that discusses value sets - but in the context of the ByKey UI elements.  The process is the same for creating the value set however:
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/bb/69b441b0133531e10000000a155106/frameset.htm

  • How do I enable opening firefox from two different computers sharing the same home directory without having to delete a lock file (linux).

    I just don't want to have to delete a lock file - which has a purpose - in order to use firefox simultaneously from two locations on the network - where the home directory, i.e. .mozilla directory - is located

    You need to use two separate profiles if you want to have two Firefox instances open at the same time.
    See also http://www.mozilla.org/unix/remote.html

  • HT2534 How can i download from two different store with the same account?

    I live in both countries but my credit card is registered in a french bank, therefore it is not recognised by the Aussie store on itunes. There are apps or music i want to get form the Aussie store as well as music and other apps from the french one...
    Is it possible to have two stores under the same account????? I wish apple could fix this, which could result in more spending as you can buy from different store!

    Wait 90 days
    Why would you start a new account?  Why not just correct the original account?

  • How to get a Previously purchased app  from the App Store from a different account on the same computer?

    Recently had to replace my hard drive and some info has gone missing.  An App from the App Store for one.  How can I get it back now that I have a new account?  It wont let me sign on with the old one anymore.

    There's no need to create a new Apple ID just because the hard drive was replaced.
    Apps can only be re downloaded using the same Apple ID they were purchased with originally.
    You will have to re purchase the app using the new Apple ID.

  • Remote devive access and acquiring signals from a different PC in the same LAN

    Well, I'm still interested in knowing if the way to see the DAQ channels from one PC to another located in the same LAN is the Remote device acess RDA?
    If the answer is yes I would appreciate the information from sombody who has done it.
    Thanks

    Please don't create another question. I answered you to a previous one that is the same than this. Here is also the response.
    Hello,
    the only easy way in order to do that is to use RDA ( Remote Device Access ). This is a component that is installed when you install NI-DAQ. Currently, RDA is only supported by Traditional NI-DAQ. So, if you have programmed your application using NI-DAQmx, it might be more dificult because you will have to use networking communication VIs as Datasocket,TCP/IP, ....
    Here you have a link about RDA. There, there is a link to an Application Note called Networking Two PCs for Remote Data Acquisition
    http://digital.ni.com/public.nsf/websearch/5CC9792C6CD4A34C862565BC0072D5DF?OpenDocument
    I hope this helps.
    Regards
    crisR

  • Connect to Exchange 2013 on local network from a different domain on the same local network.

    Hi we have domain a and domain b both on the same local networks using the same ip subnet.
    domain a is Small Business server 2003
    doimain b is Windows 2008 and Exchange 2013
    How can I set this up so that client logging into domain a using Windows XP or Windows 7 can set up an exchange profile on Office 2010 to log into domain b running exchange 2013.  I need to know how to set up the autodiscover (i think) or how to enter
    the server settings manually on the Outlook 2010 client (on domain a).  My understanding is that Outlook Anywhere means I can set up a profile "anywhere" even on the same local network segment as the exchange 2013 server.
    thanks

    Let me explain the way i understood
    Domain A - domainA.mail.com
    Domain B - domainB.mail.com
    To have common autodiscover record for the both the domain
    Step 1: Create autodiscover record having the name of parent domain - e.g Autodiscover.mail.com
    Step 2: Add this name in your Exchange certificate
    Step 3: Create Host record for domainA.mail.com and domainB.mail.com
    Step 4: Install IIS on a Windows server ensure you choose HTTP Redirection
    Step 5 :Create a folder C:\inetpub\wwwroot\autodiscover add a blank file called autodiscover.xml
    Step 6: Create a new virtual directory called ‘autodiscover’.
    Step 7: Select this new virtual directory > click on Content View > Right click on autodiscover.xml > Select ‘Switch to Features View’
    Step 8: Double click on HTTP Redirect
    Step 9: Change the HTTP Redirect settings to https://autodiscover.mail.com/autodiscover/autodiscover.xml
    Step 9: Right click on Default Web Site > click on Edit Bindings - Add domainA.mail.com and domainb.mail.com in the http bindings
    How it works: Autodiscover uses http redirection in which it get redirected to the respective domain to the autodiscover record
    Exchange Queries

  • Problem Using toString method from a different class

    Hi,
    I can not get the toString method to work from another class.
    // First Class Separate file MyClass1.java
    public class MyClass1 {
         private long num1;
         private double num2;
       public MyClass1 (long num1, double num2) throws OneException, AnotherException {
            // Some Code Here...
        // Override the toString() method
       public String toString() {
            return "Number 1: " + num1+ " Number 2:" + num2 + ".";
    // Second Class Separate file MyClass2.java
    public class MyClass2 {
        public static void main(String[] args) {
            try {
               MyClass1 myobject = new MyClass1(3456789, 150000);
               System.out.println(myobject);
             } catch (OneException e) {
                  System.out.println(e.getMessage());
             } catch (AnotherException e) {
                  System.out.println(e.getMessage());
    }My problem is with the System.out.println(myobject);
    If I leave it this way it displays. Number 1: 0 Number 2: 0
    If I change the toSting method to accept the parameters like so..
    public String toString(long num1, double num2) {
          return "Number 1: " + num1 + " Number 2:" + num2 + ".";
       }Then the program will print out the name of the class with some garbage after it MyClass1@fabe9. What am I doing wrong?
    The desired output is:
    "Number 1: 3456789 Number 2: 150000."
    Thanks a lot in advance for any advice.

    Well here is the entire code. All that MyClass1 did was check the numbers and then throw an error if one was too high or too low.
    // First Class Separate file MyClass1.java public class MyClass1 {
         private long num1;
         private double num2;
         public MyClass1 (long num1, double num2) throws OneException, AnotherException {              
         // Check num2 to see if it is greater than 200,000
         if (num2 < 10000) {
                throw new OneException("ERROR!:  " +num2 + " is too low!");
         // Check num2 to see if it is greater than 200,000
         if (num2 > 200000) {
                throw new AnotherException ("ERROR!:  " +num2 + " is too high!");
         // Override the toString() method
         public String toString() {
              return "Number 1: " + num1+ " Number 2:" + num2 + ".";    
    // Second Class Separate file MyClass2.java
    public class MyClass2 {
        // Main method where the program begins.
        public static void main(String[] args) {
            // Instantiate first MyClass object.
            try {
               MyClass1 myobject = new MyClass1 (3456789, 150000);
               // if successful use MyClass1 toString() method.
               System.out.println(myobject);
                         // Catch the exceptions within the main method and print appropriate
                         // error messages.
             } catch (OneException e) {
                  System.out.println(e.getMessage());
             } catch (AnotherException e) {
                  System.out.println(e.getMessage());
             }I am not sure what is buggy. Everything else is working fine.

  • How can i call a main method  from a different class???

    Plzz help...
    i have 2 classes.., T1 and T2.. Tt2 is a class with a main method....i want to call the main method in T2......fromT1..is it possibl..plz help

    T2.main(args);

  • Calling a method from a different class?

    Ok..
    I been trying for hours... but im stumped.
    How can I get this to work?
    (Note: I cut this code down from over 600+ lines of code.. I left in a REALLY raw framework that shows where the basic problem is.)
    public class Client extends JPanel implements Runnable {
    // variable declarations...
        Socket connection;
        BufferedReader fromServer;
        PrintWriter toServer;
        public Client(){
    // GUI creation...
    // Create the login JFrame
        Login login = new Login()
        public void connect(){
        try {
                //Attempt to connect to the server
                connection = new Socket(ip,port);
                fromServer = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                toServer = new PrintWriter(connection.getOutputStream());
                //Launch a thread here to read incoming messages from the server
                //so I dont block on reading
                new Thread (this).start();
        } catch (Exception e) {
            e.printStackTrace();
        public void run(){
            // This keeps reading lines from the server
            String s;
            try {
                //Read messages sent from the server - add them to chat window
                while ((s=fromServer.readLine()) != null) {
                txtChat.append(s);
            } catch (Exception e) {}
        public static void main(String args[]){
            // some init frame stuff
            frame = new JFrame();
            frame.getContentPane().add(new Client(),BorderLayout.CENTER);
         frame.setVisible(true);
    class Login extends JFrame {
        JPanel pane;
        public Login() {
         super("Login");
         pane = new JPanel();
         JButton cmdConnect = new JButton("Connect");
            pane.add(cmdConnect);
         setContentPane(pane);
         setSize(300,300);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         cmdConnect.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent ae){
              // I want to connect to the server when this button is pressed.
              // How can I call the connect method in the Client class?
    }

    Your posted code shows Login as an inner class. So one way to solve your problem is.
    1. Make an instance variable to hold the instance. For example, after "PrintWriter toServer;" add "private Client client;"
    2. In the Client constructor, add a line "client = this;"
    3. In the Login actionPerformed(), use "client.connect();"
    Another way is to have Login keep a reference to the Client that created it.
    1. Add an instance variable to Login "private Client client;"
    2. Change the Login constructor "public Login(Client c) {"
    3. Add a line in the constructor "client = c;"
    4. In the actionPerformed() "client.connect();"

Maybe you are looking for

  • Iphone 4s battery melts after ios 7.1

    Last Friday I've upgraded to IOS 7.1. especially after learning that the upgrade is especially helpful for iphone 4s, Yes it fastens the device but the battery "melts" I've searched the issue from the web and applied all the suggestions to improve ba

  • Problem with sound recording

    I am trying to record sound from my microphone. I have just read a part of the tutorial and I did what it said there, but it doesn't work. The class for recording is here: private class SoundSender implements Runnable{         public void run() {    

  • Lync 2013 On Premises integration with Exchange Online Unified Messaging

    I am working on deploying Lync 2013 Server on premises and integrating it with Exchange Online. We do not use Exchange on premises. My question is how to integrate with Unified Messaging specifically. Other functions like Calendar, call logs seem to

  • HTML5 gallery tag

    hello Dreamweavers. Whats the hmtl5 tag for gallery? Would it be called <Section>? Thank you.

  • Help! Just want to share DSL between new iMac & existing Windows laptop

    I have existing laptop running on Windows XP, connected to a DSL modem via ethernet cable. The modem also has an additional USB slot. I want to access the Internet from my new iMac G5, using the same DSL line, but not share anything (files, printer,