Program efficiency question

Hello all, I was just wondering about the efficiency of some programming practices. I have a program I am working on with about 20 different files. One of the files contains all of my constants ("Constants.java")... I am wondering if it is a bad practice to just call all of the variables statically i.e.
System.out.println(Constants.menu);
or would it be more efficient for the classes that use Constants to implement Constants?? I believe in that case I would be able to just use:
System.out.println(menu);
As of right now I am using the 1st method, but I wasn't anticipating the growth of the program to be so large. Any input on this subject would be greatly appreciated. Thanks,
dub

or would it be more efficient for the classes that
use Constants to implement Constants?? No.
Using interfaces for constants is an antipattern.
Don't dwell on these micro "efficiency" issues. Write code that's simple and easy to understand. Worry about performance in broader terms--e.g., prefer an O(N) operation to an O(N^2) one. Only diddle with those minutuae if you've determined that they're actually causing problems and the change you make will create a significant improvement.

Similar Messages

  • Efficiency Question - Cutting Clips

    Efficiency Question - Cutting Clips.
    So I was wondering if there is a better way to cut my clips that I am not using. Basically I often have large long clips of raw footage that I cut down to the usable segments. Each raw file may be over an hour long and have 100s of small segments of live commentary, often I find I am cutting out slightly to long pauses in the talking and other stuff before I have a clip ready to send to the main edit.
    Anyway, often I am zoomed will in so I can edit, and I press C, make a cut.. then make another a bit further up, press V, click on the segment I just cut out.. press delete and then click on and move the rest of the raw clip to the left to bump up where I made the first cut, often needing to zoom well out and then back in again to continue editing.
    Is there a better way to do this? So I do not need to zoom in and out all the time... is there a way to delete a chunk of video form the sequence and have the clip automatically "close the gap" for me?
    --Thanks

    I would take the Source Clip into the Source Monitor.
    Mark an In Point  ("I")  where the good content starts...and an Out Point ("O")  where the good content stops.
    Hit "," to Insert it to the Sequence.
    Back to Source Monitor and repeat for the next section of good content in the same Source Clip..
    No gaps . Done
    Then ..if necessary...I would play thru  the Sequence and do Trim Edits at the editpoints.
    Many different ways to "skin the cat" at Trim stage.
    Alternatively in the first part:
    I would take the Source Clip into the Source Monitor.
    Mark an In Point ("I") where the good content starts...and an Out Point ("O") where the good content stops.
    CTRL-Drag to the Program Monitor.

  • Another Programming Newbie Question:

    I have read many of the posts from programming newbies like myself looking for advice as to which language to start their programming journey. While helpful, my situation is slightly different and I would appreciate thoughts from those of you who have been doing this for a while.
    On one level, like the others, I am interested in beginning programming for my own personal interest and hobby. I want to be able to poke around building stuff for my Mac as I see the need. The second driver however, is a professional one; I work as a management consultant within an IT company.
    Much of my work relates to Business strategy and IT alignment. At that level I am expected to bring a business perspective to IT issues and to provide assessments that confirm proposed technology/software solutions are in fact going to add value for the company overall. Basically big picture stuff.
    In this role I am not usually asked to bring the same "technical" perspective that a true business analyst would. However, I would like to better understand the methods, terms and concepts that my colleagues use in developing their software. On occasion I am asked to provide a high level requirements analysis, which draws largely upon my business knowledge, but given that that this information is then presented to my developer colleagues I would like to understand things at a more technical level.
    So my question is whether I am free to choose any language to begin my learning quest or if there is a language that will better lead me to understanding and communicate the technical side of software development.
    Also I know that a lot of the work done in my company is in Java - but there are obviously a wide range include various applications that sit atop various data bases.
    I hope my various questions have been communicated clearly enough. I welcome any thoughts or advice that any of you may be able to share with me.
    Thanks!
    Power Book 12   Mac OS X (10.4.1)  

    The case of the employee wishing to merge his own admirable desire to learn programming with the requirements of his position is an interesting case that shows, perversely (or so it seems at first--it's actually perfectly logical) that corporations do not necessarily benefit from the talents, drive and ambition of individual employees--and this is not a cynical or sinister notion. Etresoft's analysis and advice is spot-on and I only wish to add a footnote to it: Along with the "getting the job done quickly and simply as possible" fallacy, and the at first glance counter-intuitive proposition that the complex, fragile, and massive solutions actually benefits the corporation qua corporation, one must remember that corporations are not and never pretended to be pure meritocracies nor are they conceived of as sets of individual employees in competition with each other for rewards. That is to say, trying to make one's personal interests into job requirements is far too questing and individual a project to succeed in any corporate (in the neutral sense of "aggregate," not in the sense of conformist) environment The corporate nature of the incorporated business is, after all, its defining characteristic. This means solutions by consensus aimed as much at institutional self-perpetuation as at the maximization of profit will be favored over mavericks following instincts, absolutists assimilating all power to themselves, or the efficient yet eccentric (again, in the neurtral sense of the word) initiatives of earnest employees trying to unite where possible the requisites of their given post with their own private interests. The upshot to all this is this: the attempt to use pre-existing corporate structures and processes for the fulfillment of individual growth and personal satisfaction (which may as a by-product, or accident in the Aristotelian sense, generate corporate wealth) is to look past stated categories and definitions and to ignore historically-observed outcomes. Corporations will not appreciate or benefit from individualistic impulses not because individual satisfaction is suspect but because its ways are inimical to corporate ways--the friction of the indivduals trying to redefine mutually-agreed upon positions and outcomes for selfish purposes costs too much to be indulged. From the corporate point of view, it is a threat to be contained, not an asset to be exploited. Robinson Crusoe had to spend 28 years on an island alone in order to adequately enact his individualism as it relates to capitalism.* The adaptable, nimble, individual-identified employee with his productivity tied to his own appetites, cannot, at least in the abstract, help but work against the aggregate needs of the corporation.
    *Excursus: Defoe's 1719 novel is the foundational narrative of capitalist self-production and its major offspring is Max Weber's Protestant Ethic and the Spirit of Capitalism (1920).This is where 18th-century economic theory including Adam Smith, leads us astray today--it was formulated not before the Industrial Revolution--the transition to capitalism took place in the 17th century--but before the aqdvent of the modern corporate structure.

  • Hash Table efficiency question

    Hi experts,
    In my program, I want to read in a lot of string and store the occurance of each string. I found that hash table is the best and most efficient option, but the problem is that, hash table only store one item.
    So, I either have to:
    1) store an array object into each hash table entries. ie String[String][Occurance]
    2) create two hash table based on the hash code of the string.
    For 2) I am planning to store all distinct String into one hashtable using the string as the hashcode, then create another hashtable to store the occurance using the String as the hashcode.
    My question is that:
    1)which implementation is more efficient? Constantly creating String array for each entry or create two hashtables?
    2) Is the second implementation possible? Would the hashcode be mapped to different cell in the hashtable even the two hashtable are using the same hashcode and the same size?
    Thank you very much for your help.
    Kevin

    I am wondering what it is you are trying to do, but I am assuming you are trying to find the number of occurrences for a particular word, and then determining which word has the highest value or the lowest value? You can retrieve the initial String value by using the keys() method of the hashtable. You can use it to traverse the entire table and compare the counts there.
    If you really wanna store another reference for that string, create a simple object
    public final class WordCount {
       * The Word being counted.
       * @since 1.1
      private String _word;
       * Count for the Number of Words.
       * @since 1.1
      private int _count;
       * Creates a new instance of the Word Count Object.
       * @param word The Word being counted.
       * @since 1.1
      public WordCount(final String word) {
        super();
        _word = word;
        _count = 0;
       * Call this method to increment the Count for the Word.
       * @since 1.1
      public void increment() {
        _count++;
       * Retrieves the word being counted.
       * @return Word being counted.
       * @since 1.1
      public String getWord() {
        return _word;
       * Return the Count for the Word.
       * @return Non-negative count for the Word.
       * @since 1.1
      public int getCount() {
        return _count;
    }Then your method can be as follows
    * Counts the Number of Occurrences of Words within the String
    * @param someString The String to be counted for
    * @param pattern Pattern to be used to split the String
    * @since 1.1
    public static final WordCount[] countWords(final String someString, final String pattern) {
      StringTokenizer st = new StringTokenizer(someString, pattern);
      HashMap wordCountMap = new HashMap();
      while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (wordCountMap.containsKey(token)) {
          ((WordCount) wordCountMap.get(token)).increment();
        } else {
          WordCount count = new WordCount(token);
          count.increment();
          wordCountMap.put(token, count);
      Collection values = wordCountMap.values();
      return (WordCount[]) values.toArray(new WordCount[values.size()]);
    }Now you can create your own comparator classes to sort the entire array of Word Count Objects. I hope that helps
    Regards
    Jega

  • Efficiency Question: Simple Java DC vs Used WD Component

    Hello guys,
    The scenario is - I want to call a function that returns a FileInputStream object so I can process it on my WD view. I can think of two approaches - one is to simply write a simple Java DC that does so and just use it as a used DC so I can call the functionality from there. Or create another WD DC that exposes the value (as binary) via component interface.
    I'm leaning on the simple Java DC approach - its easier to create. But I'm just curious on what would be the Pro-side (if there's any) if I use the WD Component interface approach? Is there a plus for the efficiency? (Though I doubt) Or is it just a 'best/recommended practice' approach?
    Thanks!
    Regards,
    Jan

    Hi Jan
    >one is to simply write a simple Java DC that does so and just use it as a used DC so I can call the functionality from there
    Implemented Java  API for the purpose mentioned in your question is the right way, I think. The Java API can be even located in the same WebDynpro DC as your WebDynpro components. There is not strongly necessity to put it into separate Java DC.
    >Or create another WD DC that exposes the value (as binary) via component interface
    You should not do this because in general WD components' purpose is UI, not API. Implementing WD component without any UI, but with some component interface has very-very restricted use cases. Such WD component shall only be a choice in the cases when the API is WebDynpro based and if you have to strongly use WebDynpro Runtime API in order to implement your own API.
    If your API does not require WebDynpro Runtime API invocations or anything else related to WebDynpro then your choice is simple Java API.
    >But I'm just curious on what would be the Pro-side (if there's any) if I use the WD Component interface approach? Is there a plus for the efficiency?
    No. Performance will be better in simple Java API then in WebDynpro component interface. The reason is the API will not pass thought heavy WebDynpro engine.
    BR, Siarhei

  • Java Programming Language questions...???

    Hi everybody....
    Can I post here my questions about Java Programming Language....or only to to the relevant Sun's forum....http://forum.java.sun.com/index.jspa???
    My greetings,
    Simon

    Simon,
    sure, the worst thing that could happen is that people point you to the SUN forum. Usually this forum answers general Java questions.
    Frank

  • RFC Sender Adapter configuration - Program ID question

    Hello All,
    I am working on a Sync RFC(R/3) --> XI --> Webservice scenario. I have a question on Program ID's. We're going to be having different RFC's call the same webservice. In that case, we'll have one scenario for each RFC sender.
    Do we need to create different TCP/IP ports and Program ID's in R/3 for each RFC sender or just one TCP/IP port and Program ID can be used by all RFC's from R/3?
    Please respond with your suggestions.
    Thanks in advance.
    Karthik

    Aamir,
    Buddy please correct me if i'm wrong!! As u said u will design this as single scenario with conditional receiver determination, Wht happen if I create RFC channel under some other Business Service with same Program ID. In this case my receiver is different isn't it!!!
    The key is Outbound Interface .. If the RFC sends BAPI_GET_DETAIL with say ProgramID TEST_1000 the corresponding interface in XI will be triggered, similarly if the RFC sends RFC_READ_TABLE with same program ID TEST_1000 the corresponding interface will be triggered?
    Is the above example make sense, please correct me if my understanding is wrong.
    raj.

  • Noobish "efficiency" question on DataOutputStream

    So, I currently have this:
    byte[] buf = some_bytes;
    DataOutputStream out = new DataOutputStream(socket.getOutputStream());
    out.writeInt(buf.length);
    out.write(buf);I've always thought that calling write(byte[]) and any given OutputStream will be "efficient", in that things will be chunked under the hood to avoid incurring whatever I/O overhead is present for each and every byte. So, as I understand it, we only need to explicitly use BufferedOutputStream if we're writing one or a few bytes at a time.
    Now I'm not so sure.
    Digging through the core API source code a bit, it seems that this ultimately calls OutputStream.write(byte) in a loop, which, presumably, is bad unless the OutputStream in question is a Buffered one.
    Am I shooting myself in the foot here? Should I be wrapping that DataOuputStream around a BufferedOutputStream? Or vice versa?
    Or should I just scrap the DataOuputStream altogether and write the int's bytes out myself?
    I'm going to test it both ways, but in the meantime, and just in case the tests are not definitive, I'm wondering if anybody here can tell me what I should expect to see.
    I think I've been staring at this stuff for a bit too long and am second-guessing myself to death here no matter which way I look at it. So thanks in advance for any nudge you can give me back toward sanity.
    Edited by: jverd on Feb 16, 2012 3:59 PM

    EJP wrote:
    So, what's the point of the basic OutputStream not being buffered then?I guess the idea was that if you want buffering you say so,Ok.
    I think you'll find that every significant class that extends OutputStream (specifically FileOutputStream and SocketOutputStream) overrides write(byte[], int, int) to do an atomic write to the OS, so it isn't really such an issue except in the case of DataOutputStream (and not ObjectOutputStream, see above).Okay, so, in this case, I've got a DataOutputStream wrapped around a SocketOutputStream. It's not an issue for SOS, but it is for the wrapping DOS. Yes?
    So to overcome the DOS doing a bunch of piddly 1-byte writes to the SOS, which in turn could result in a bunch of piddly 1-byte writes to the network, which I don't want, I inject a BOS between them. Yes?
    Thanks for the help. I can't believe after all these years I never got these details sorted out. I guess it never came up quite this way before.

  • Program RSUPGRCHECK  - Question

    Hi Guys,
       The program is used to verify if the object are active in bw before to execute the PREPARE fase. My question is will it validate this a metadata level and not at application level?. Because, I have an ODS not activate at workbench level, but a metadata repsitory show me as active
    Can someone clarify this for me?
    Thanks in advance
    I.

    hi I.,
    i think you should get it activated. and make sure there is no transport request in modifiable status (all should be released, not necessary to be transported) before you do PREPARE to avoid unnecessary problems.
    another thing is for data loading request, there should be no 'yellow' status with any request, and all requests which have 'data target' should be updated in data target, can check in rsa1->monitor->status overview.
    also no inconsistency with any infoobjects (rsd1).
    hope this helps.

  • My Java Scheduler Program - A question

    Hi all, I have just started experimenting with java after programming a lot in ANSI c++. I am writing a GUI scheduler program (cuz i sure need it! and... to get me familiar with aspects of Java such as Swing, multi-threading,etc. My program is going fine and i am almost done. I just had one question about the scheduler program:
    1. My scheduler uses a Jlist to display all events that the user. Now if the user closes the scheduler completely, and then restarts the program, i want the events to be displayed again and all my internal data structures to be filled in again as they were when the user closed the program. As of now, the only way i know how to do this would be to keep a separate text file, which would store all the scheduled events in it when the user closed the program, and every time the program was started, it would read in from the text file and replinish the data structures and my visual Jlist.
    This method, though possible, seems a bit cumbersome and not so elegant. Can anybody give me another way for me to do this?...I would much appreciate any comments/ideas.

    Sounds like you want to serialize some of your classes. See this link to a Sun tutorial:
    http://java.sun.com/docs/books/tutorial/essential/io/providing.html

  • ABAP efficiency question

    Hi
    I have an internal table of the type STRING which may contain thousands of records and I am trying to get to lines which starts with a set of characters. There may be a few lines starting with that sequence and it is possible to do what I have shown below, however, is there a more efficient way to do this?
    Ideally what I would like to do is to find the lines or the index (SY-TABIX) using LOOP AT.......WHERE....My current way of doing it is not the best. Any ideas?
    DATA t_spooltext TYPE TABLE OF string. "contains thousands of lines
    DATA l_text(200) TYPE c.
    DATA l_index     TYPE i.
    LOOP AT t_spooltext INTO DATA(l_current_line).
      CONDENSE l_current_line.
      l_text = l_current_line.
      IF l_text+0(5) EQ 'H046A'.
        l_index = sy-tabix.
        ELSE
            CONTINUE.
      ENDIF.
    ENDLOOP.

    Sharath,
    Fixing what you posted, I add the sample code below:
       REPORT  z_test.
    DATA: t_spooltext TYPE TABLE OF string,
          results_tab TYPE TABLE OF match_result.
    DO 10 TIMES.
      APPEND 'H046A' TO t_spooltext.
    ENDDO.
    DO 3 TIMES.
      APPEND 'H046B' TO t_spooltext.
    ENDDO.
    FIND ALL OCCURRENCES OF 'H046A'
    IN TABLE t_spooltext
    IN CHARACTER MODE
    RESULTS results_tab.
    BREAK-POINT.
    Archana, in my point of view the user Sharath are correctly, only thing you have to watch is the form that is set to result table, as I showed above

  • "Good programming practice" question about writing classes

    I am taking a java class this year and my teacher has taught us to never use global variables in a class (but still private). I find it much easier to explain with a simple example. Say I have a class that looks like this:
    public class Demo
            private int int1, int2;
         public Demo()
              int1 = 1;
              int2 = 2;
         public void demoMethodOne(int int1, int int2)
              //... code using the ints passed to the method
         public void demoMethodTwo()
              //... code directly accessing the private ints of the class
            public int getInt1() { return int1; }
            public int getInt2() { return int2; }
    }My teacher says to ALWAYS use methods of the type demoMethodOne (to pass all of the variables it will use to it) and avoid using the type demoMethodTwo. But in my programming experience, I have found it very repetitive and pointless to use that method in some cases. For example if I call demoMethodOne like this:
    demoMethodOne(demo.getInt1(), demo.getInt2());
    That seems very repetitive but that is how I am told to do it. Should I program that way even if it seems very pointless or is it ok to use "public" variables like in demoMethodTwo. Thanks.

    I think you may have misunderstood your teacher.
    If your object method is doing something with the object's state, then it's perfectly appropriate to modify the object's fields, which embody the state.
    And generally it's good to adopt a functional programming approach, in which there are few side effects. This principle is sort of independent of the previous one.
    The danger is when you treat object fields as global variables (and not as the embodiment of the object's state). In this case the global variable doesn't really represent anything, it's just a place to store data temporarily to avoid designing your methods properly. So for example you'd have two methods, one sets a field and then calls another method, which reads the field; the field doesn't really mean anything to the object as a whole, it's just a lazy way to pass data between the two methods. This is asking for bugs. The correct thing would have been to pass the value as an argument to the second method.
    Also, if you have a method that doesn't really express the behavior or effect the state of an object, but is called just for its return value (like some kind of utility method), then it's pointless and dangerous to make it effect the state of an object.

  • How to make this program efficient?

    Hola Amigos, I'm trying to explore all the possibilities about comparing two arrays. I know the following code is O(n^2) is it possible to make it O(n) without recursion or is recursion the only way. I ask this because we are being taught recursion and I don't quite understand it. I don't see the relation from recursion taught in Discrete Math with the one taught in programming, Thanks.....
    public class twoArrays
         public static int max = -1;
         public static int findMax(int oneArray [], int twoArray [])
              for (int i = 0 ; i < oneArray.length ; i ++)
                   for ( int j = 0; j < twoArray.length ; j++)
                        max = Math.max(max,Math.max(oneArray,twoArray[j]));     
              return max;
         public static void main (String [] args)
              int[] a = {1,5,8,30,80,99,140,160,170,180,190,200};
              int[] b = {2,4,7,45,60,85,98,150,155,175,195,205};
              findMax(a,b);
              System.out.println("The highest value is: " + max);
    Ah, one more thing the word "static" how can I call a method from a non-static context. Very confussing for me, thanks again.

    To call a non-static method you can use an instance of the class.
    Example:
    public class twoArrays {
    public static int max = -1;
    public int findMax(int oneArray [], int twoArray []){//non-static
         for (int i = 0 ; i < oneArray.length ; i ++){
         for ( int j = 0; j < twoArray.length ; j++)                    max = Math.max(max,Math.max(oneArray,twoArray[j]));          }
         return max;
    public static void main (String [] args)     {          
    int[] a = {1,5,8,30,80,99,140,160,170,180,190,200};
    int[] b = {2,4,7,45,60,85,98,150,155,175,195,205};
    ( new twoArrays() ).findMax(a,b);/*through an anonymous instance of the class, you can call findMax method */
    System.out.println("The highest value is: " + max);          
    Hope it will help you.
    p.d.: max is initialized -1 cause then into findmax, you asure that max will never again has value -1 (the two arrays contains numbers > -1 )so max at least will be higher than -1.
    Sorry for my english.
    Saludos

  • Catalog efficiency question in Lightroom 3.6

    I currently have one catalog with over 22,000 photos and numerous collections in it. I recently heard about creating separate "catalogs" to better LR3's efficiency and to cut down the clutter so that I'm just working on one catalog at a time. Does anyone know the best way to go about this so as not to ruin all of my collections I have created over the past year?

    Don't do it is the answer. For most uses one catalog is the best solution.

  • Deitel, Java How To Program exercise question

    Hi, :)
    I'm new to programming and I'm using the Java How To Program Fourth Edition from Deitel and Deitel as my text. I've run into a problem with Exercise 2.16 Where I'm asked:
    "Write an application that asks the user to enter two numbers, obtains the numbers from the user and prints the sum, product, difference, and quotient of the numbers."
    From that I have written this code:
    // Exercise 2.16
    /* An application that asks the user to enter two numbers, obtains the numbers from the use and prints the sum,
    product, difference and quotient of the numbers. Using the techniques shown in Fig 2.9 */
    //Java extension packages
    import javax.swing.JOptionPane;
    public class Exercise2_16{
         //Main method
         public static void main(String args[]){
         String firstNumber, secondNumber;                          //introduce variables
         int number1, number2, sum, product, difference, quotient;          //introduce variables
         firstNumber=JOptionPane.showInputDialog("Enter first integer:");     //Create input window
         secondNumber=JOptionPane.showInputDialog("Enter second integer:");     //Create input window
         number1=Integer.parseInt(firstNumber);                         //String to integer
         number2=Integer.parseInt(secondNumber);                         //String to integer
         //perform operations
         sum = number1+number2;
         product = number1*number2;
         difference = number1-number2;
         quotient = number1/number2;
         //Display results
         JOptionPane.showMessageDialog(null, "The sum is " + sum,
         "The product is " + product, "The difference is " + difference,
         "The quotient is " + quotient, "Results", JOptionPane.INFORMATION_MESSAGE);
         //End program
         System.exit(0);
         }//End main method
    }//end class Exercise2_16
    When I compile this code I get an error and I can't figure out why. Any help is really appreciated as I'm stumped and given the simplicity of the app I'm kinda bummed it has me stuck :(.

    I substituted your line and this is the error I'm receiving now:
    F:\jdk1.3\Learning Java>javac Exercise2_16.java
    Exercise2_16.java:32: unclosed string literal
    JOptionPane.showMessageDialog(null, "The sum is " + sum + ", The product is" + product + ",
    The difference is" + difference + ", The quotient is" + quotient + ", \"Results\", JOptionPane.INFORMATION_MESSAGE);
    ^
    Exercise2_16.java:35: ')' expected
    System.exit(0);
    ^
    2 errors
    It doesn't really matter to me if there are returns but maybe for readability there should be and so I learn how to as well.

Maybe you are looking for

  • Leopard lost my external HD, how to boot from Tiger

    When I upgraded (?) to Panther, it wanted to do a backup to my external HD, but it was going to be to large, so I told it not to. The next day when I started up, I typed in the password to my external HD and got a window saying Device not found. I ha

  • Error on BP

    Dear All I am facing the following error kindly help : No BP roles exist with BP role category MKK "I have done cong in golden client now i am testing in unit test client"

  • JCheckBox-icon not showing

    Hi there, i hope this has not been covered already, i searched this forum looking for all kind of JCheckBox posts but did not find what i was looking for. If i missed it i'm really sorry and would appreciate any kick that get's me into the right dire

  • Auto-dimming in upcoming 3.0 upgrade?

    The one major thing that frustrates me about the "touch" is that I either have to choose between a few "timed" settings before the screen goes into blank lock mode or I have to leave it on forever which kills the battery. Does anyone know if the upco

  • F4 Button in FM

    Hi, I have created a Z-Function module..where 1 pop-up will come and while pressing F4 it will go to process on value-request..and it is working fine in SE37 But when i am using in my program..same FM with same parameter ...the F4 button is not worki