• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to link separate informations on the APIs available in the Javadoc or API Web index?  RSS feed

 
Rajib Ban
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose that I have these four APIs within the http://docs.oracle.com/javase/8/docs/api/index.html
  • PrintStream java.lang.System.out
  • void java.io.PrintStream.println(String x)
  • java.util.Arrays
  • String java.util.Arrays.toString(Object[] a)


  • What I mean is that, if I come across these above four API definitions/descriptions independently, I wouldn't be in a position to know that they could be weaved together into a meaningful form: unless I have specific examples.

    This is what I need to know:
    How to be able to weave together terms from the list: http://docs.oracle.com/javase/8/docs/api/index.html into code lines that work in a meaningful way?

    I have been given two important and independent directions:
  • (By Dr.Jong) ... How you can do things quickly and efficiently is something that you learn by practising, ...
  • (By Dr.Vilda) ... you need to look method declaration signature, which kind of parameters and their types method accepts as arguments ...


  • Dr. Jong also unexpectedly provided me with a very neat code in response to my request in one of my forum threads. The gift has to be acknowledged too:
    Dr. Jasper Jong wrote:When you write code, step 1 is to get clear about what you want your program to do. For example: I have an array of strings in the variable 'args' and I want to print out all the elements of the array.
    Step 2 is then to find out how you can translate that idea into code. There are often many different ways to do the same thing in code. One approach for this task is to write a loop that goes over the array and prints each element in turn:
    That would print every element of the array on a separate line.

    Needless to say, I was advised to post my queries by either of the gentlemen on the forum. I assured them that their replies will be acknowledged at, with my original posting to, the forum, after I have made some progress in assimilating the information given me.

    I have copied the suggestions verbatim, as they were originally received. I hope to collect different unique ideas, carefully weigh them and select apparently the currently the most-suited course for myself.
     
    Tony Docherty
    Bartender
    Posts: 3271
    82
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This is what I need to know:
    How to be able to weave together terms from the list: http://docs.oracle.com/javase/8/docs/api/index.html into code lines that work in a meaningful way?

    There is no magic solution or even a list of meaningful chained method calls. After all, what's meaningful in one context maybe totally useless in another context.
    What you need to learn is how to break your goal into discrete steps and then look at the methods available in the classes you have at your disposal to see which methods may help you.

    In the example you showed on printing out the contents of an array. The goal is to print out each element in an array. Now if you just try and think how to code that goal most beginners will be stuck but if you break that goal down into discrete parts you'll have a much better chance of coding the task. For example you have an array of items to print and you don't know how to do that but you do know how to print a single item so the first thing is to do is to get each element out of the array and into a variable which you can then print out. So how do you get each item out of an array, an easy way is to iterate over the array. You now have a basic structure, you need a for loop, an assignment and a print statement.


    or if you want to use  for-each


    Now once you get a bit more experienced and have done a lot more reading of the Java API you will no doubt have come across the Arrays class and having read the Java Docs you will have noticed it has some useful methods for working with arrays such as printing out their contents and thus, as a more experienced programmer, you can change your approach to use Arrays.toString().

    But these code examples don't produce the same output. The former examples write an element per line, the last example puts them all on one line so which you choose depends what your exact requirements are.
     
    salvin francis
    Bartender
    Posts: 1664
    37
    Eclipse IDE Google Web Toolkit Java
     
    Rajib Ban
    Ranch Hand
    Posts: 82
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    salvin francis wrote:...

    I did not post a question. I posted just the results of my research and others' contributions. Thank you.

    As an aside, http://answers.elteacher.info copied the Stackoverflow post by itself.
     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!