How do Streams work?  I mean specifically, how Java handles it

I mean this...this is my code
class Wilson implements ConstantsBase
     public static void main(String[] args) throws IOException
          Maze mazeArray = new Maze();
          int count = 0;
          int character = System.in.read();
          while (character != -1)
               System.err.println(count++);
               System.out.print((char)character);
               character = System.in.read();
          mazeArray.printMaze();
I run java Grid.Wilson and then the prompt comes up and I type
"test"
the output is
test
0
t1
e2
s3
t4
5
so I am just wondering, does it work like this:
streams comes in chunks, everytime you hit enter, a stream is released. So that is why even though my code looks like it should be outputting one letter at a time, each time I type, it actually won't get a stream until I hit enter, then it gets this stream and goes through the loop. But it is still weird in my head, I wish I had a trace option on this IDE

A stream is just a sequence of bytes in the case of 'in.read(char)': - I believe I read somewhere that a java char is two bytes, then there may be an additional identifier so the output/ program knows what it is - int, char, or string etc. In the case of your output i would 'guess' its a little chunk of bytes then another.

Similar Messages

  • Confused about CLASSPATH and how java handles import statements...

    Hello,
    I must admit I don't get it. I read the articles about setting CLASSPATH etc. but I still wonder:
    If you use an import statement, what does the compiler do? I.e. where does it look for the specified classes? I find it confusing because I see in different locations different .jar files:
    C:\jdk1.3.1_03\lib\dt.jar
    C:\jdk1.3.1_03\lib\htmlconvertor.jar
    C:\jdk1.3.1_03\lib\tools.jar
    and also
    C:\jdk1.3.1_03\jre\lib\i18n.jar
    C:\jdk1.3.1_03\jre\lib\rt.jar
    C:\jdk1.3.1_03\jre\lib\jaws.jar
    C:\jdk1.3.1_03\jre\lib\sunrassign.jar
    Can someone explain me what the purpose is of these files?
    And why do I have the same contents in
    C:\Program Files\JavaSoft\JRE\1.3.1_03\lib
    and in
    C:\jdk1.3.1_03\jre\lib
    Why is that?
    Thanks for answering my questions!
    -mike

    Thanx for the answers, but I still wonder, everyone
    here says I need to set the classpath, but I don't.Probably because your classes are already in the class path. The compiler/jvm also look for classes by themselves not just in jar files, when just a directory is supplied in the class path. And a period (".") is a valid directory.
    Programs importing different classes compile with no
    problem. So what's up with that?
    Presumably you are referring to your own code - because they are in the class path.
    Second, I still don't understand why the runtime needs
    the .jar files. The runtime uses classes, like String, that have to come from somewhere.
    This would also mean that end-users
    need to set the classpath to the .jar files in their
    JRE directory to be able to run programs that import
    classes from these .jars. But this is not true, right?No it is true. The end-users will have to set the class path. There are variations on this which make it seem like no class path is set. For instance applets in a browser are java but the end-user does not need to set a class path. That is because the browser knows how to download classes/jars and how to set it up so it uses them. (Actually it uses a class loader, but that is probably more information that you need.)
    Because if I make some nice classes myself and import
    them, how can I expect my end-user to install these
    classes and make a classpath for them?That would be between you and you end-user.
    First installation is not part of java. For installation you will have to find something outside of java to accomplish the goal.
    Additionally how the class path gets set is OS specific. Java does not deal with that. You will also have to find some way to deal with this (most likely part of the installation.)
    There are also variations on this. For example the browser example I gave above. Or using the ext directory. Or creating an executable jar. Or simply setting the class path.
    In my understanding it should only be needed in the JDK, not
    in the JRE. True or am I mistaken?Mistaken. The class path is needed in the JRE as well. You will need to set it.

  • How java handles package/class names

    I am developing a strategy for internationalizing our company's middle-ware product. While I have no problem with the GUI's, exceptions, log files etc, I have no concept of how things like classpaths and packages can be specified in an asian language.
    For instance, if I have configuration information of com.abccompany.mypackage.MyClass, what will this look like to the asian user? Will they be able to change it to perhaps com.abccompany.mypackage.MyClass2 by entering localized data in Chinese or Arabic? I don't understand how this part works. On the command-line, will they type English script names? Do they run commands like so: java -cp com.abc.pkg1.jarfile.jar MyClass? Will my english filenames, packages, etc be represented in asian characters?
    We have a lot of configuration information that specify java classes as String data. I am concerned about the ability to modify this data and have it work correctly in languages that do not use the ascii character set. Is this something I need to be worried about?
    I appreciate any input. Thanks in advance.

    You do not need to warry about configuration information of com.abccompany.mypackage.MyClass
    and command-line no matter what languages used in Asia. Asian users also type in English script names or java -cp com.abc.pkg1.jarfile.jar MyClass as you do so. The only thing you need to note is
    that any text strings or messages which you want to show on any panel/dialog/window/frame and so on should be store in a resource file for internationalizing.

  • How Java handle duplicated class?

    I am trying to send out email using SUN JavaMail. However, an old version of JavaMail was shipped with Oracle AppServer 10 R2. If I package the new JavaMail into the WAR file, the old JavaMail is still functional, and cause problem to my program. Is there a way to tell the AppServer to use the JavaMail in my WAR file instead of the old one shipped with the server?
    Thanks very much!
    Edited by: huaichen on Nov 6, 2008 2:02 PM

    Hi,
    does this help you? It's from an older vesion but might wor kin your case.
    How do I setup OC4J to load local classes packaged in my Web Application overriding System classes or classes in the higher level?
    OC4J 9.0.3 has a configurable option to load local classes first, overriding classes at a higher level. You have to include the following to directive in the orion-web.xml for your web module to ask OC4J to load local classes:
    <web-app-class-loader search-local-classes-first="true" />Timo

  • How 'java' handles classname passed to it

    Hi,
    After compiling the .java file, the .class is passed to 'java'
    and that runs the program.
    Does the 'java' work this way: when we give "java classname", 'java'
    strictly would search for classname.class and proceeds thereafter,
    The reason i got this doubt is when i gave a command "java
    classname.class" an error was raised pointing no class definition.
    Thanks for your time.
    Kris.

    When the java virtual machine looks for a class it uses a ClassLoader. What the default classloader does is:
    1) Converts any dots in the "fully qualified name" to the appropriate path separater / or \ depending on the operating system.
    2) If it's an inner class, the inner class name is separated from the outer class by a $
    4) adds .class to the end
    5) Walks along the CLASSPATH. For every directory on the CLASSPATH it adds the string processed above and looks for a file. For every .jar file it tries to find the entry of the same string.
    Note "." in a classname is used to separated package name from class, as in java.util.Map, for example. "classname.class" would look for a class called "class" in a package called "classname".
    You can't compile a class called "class", by the way, because it's a reserved word.

  • How Java handle event??

    for example,An application want to receive the event of KeyBoard,The event Should be received by OS ,I think.and Then??OS Should send the event to Where ?? Who would receive the event??Wher does Application receive the event ??

    He, I now I remind : Look at the end of
    http://forum.java.sun.com/thread.jsp?forum=57&thread=293208
    But note that there is no unique response to your question: It's hihgly dependant of your JVM and of your OS.

  • How do I stream music from non-iTunes apps to Airport (mac air core-i7 OS 10.7.5 airport firmware 7.6.1 --- option-clicking speaker icon only shows internal speakers - audio streaming works from iTunes just fine.

    How do I stream music from non-iTunes apps to Airport (mac air core-i7 OS 10.7.5 airport firmware 7.6.1 --- option-clicking speaker icon only shows internal speakers - audio streaming works from iTunes just fine.

    Hello Achates:
    I did not read the rather long post. If you wish to reinstall OS X 10.4, use your software install DVD. Backup is essential. To minimize your risk, I would use an archive and install:
    http://docs.info.apple.com/article.html?artnum=107120
    In that way, you will have a fresh copy of OS X and your current settings will be preserved.
    Incidentally, I do not agree that the printer problem is best solved by reinstalling OS X. I have had HP printers for sometime and, on one occasion, had difficulty after an upgrade. HP technical support walked me through uninstalling all traces of the HP driver and then reinstalling.
    Barry

  • HT4759 However, having a windows XP is not supported... how am I supposed to get the photo stream working on iCloud? I guess that is not a priority for Apple?

    I have an iPod touch 4th generation, which is exactly what I wanted for a wifi supported multimedia device. I am trying to get the iCloud to work properly and despite of everything else working smoothly, I cannot seem to be able to get the Photo Stream working, in order to get the backup on iCloud. I tried to download the control panel and realised that it only supports the Vista SP2 and higher on Windows. Is there another way to get the settings on iCloud to include the photo stream?
    Thank you.

    Your issue has been escalated to a Verizon agent. Please go to your profile page for the forum, and look in the middle, right at the top where you will find an area titled "My Support Cases".  You can reach your profile page by clicking on your name beside your post, or at the top left of this page underneath the title of the board.
    Under “My Support Cases” you will find a link to the private board where you and the agent may exchange information.  This should be checked on a frequent basis  as the agent may be waiting for information from you before they can proceed with any actions. Please keep all correspondence regarding your issue in the private support portal.
    If a forum member gives an answer you like, give them the Kudos they deserve. If a member gives you the answer to your question, mark the answer that solved your issue as the accepted solution.

  • How to handle the table control While working with LSMW?

    How to handle the table control While working with LSMW?

    its possible in lsmw,
    Hi,
    LSMW will have a Indicator for headr and itam, i do not remember the correct field, but it will have an indicator, check the fields, there will be a single charecter lenght field, that should be the indicator, and using that we can write the logic.
    check that single charecter field, it that is X that means the header record is processed, and do the items.
    and, this is another way, try this out also
    YOu can do this in "Define Source Structures" step,
    the HEADER is defined first,
    then the DETAIL below the HEADER.
    add the fields to the structures.
    Both should have some common key field
    Please take care that the name of the common field is the same.
    Once you do this it is linked. The you have a header and item corresponding to that header. then run the LSMW as you would.
    Thanks

  • Certain web sites try to open a tab for billing or other info. fire fix 3 worked fine , 4 & 5 bring up a box asking how to handle a aspx file and nothing will work. am running XP service pack 3. how do I reload 3 again?

    with firefox 3 everything works fine. with 4 and 5 when I try to complete billing info I get a question about how to handle aspx files. nothing works. all I get is a new tab with a blank screen, not data no nothing. When I loaded firefox 4 and had the problem I reinstalled 3 to solve it. I hoped when 5 came along it would include a fix, no such luck. I read many questions about AOL logon that is the same as my problem and have tried all the suggestions with no luck.

    What are you expecting when the aspx window comes up, a PDF or a regular web page?
    Here's the process to roll back:
    First, I recommend backing up your Firefox settings in case something goes wrong. See [https://support.mozilla.com/en-US/kb/Backing+up+your+information Backing up your information]. (You can copy your entire Firefox profile folder somewhere outside of the Mozilla folder.)
    Next, download and save Firefox 3.6 to your desktop for future installation. http://www.mozilla.com/firefox/all-older
    Close Firefox 5.
    You could install Firefox 3.6 over it (it usually worked with Firefox 4) or you could uninstall Firefox first. If you uninstall, do not remove your personal data and settings, just the program.
    Unless you have installed an incompatible add-on, Firefox 3.6 should pick up where you left off. If there are serious issues, please post back with details.
    Note: I haven't actually tried this myself!

  • How to handle the situation to forward work item manually?

    Hi All,
    In my workflow -
    For agent determination I have some custom logic to determine agents. If custom logic donu2019t return any agents then the requirement is work item needs to send back to workflow initiator.
    My issue-
    When no agent determines
    1.Work item needs to send back to workflow initiator - and he should not able to Approve or Reject work item - He Can only forward work item to any other person manually (he determines to whom it should forward).
    2. After manually forwarding the work item it is normal process 2 level of approval from that point .
    Please let me know for the first item how to handle the situation?
    I have developed 2 section - one goes with regular agent determination -
    and the other one when no agent determines then I am assigning back to workflow initiator. Now I want to handle that - initiator should not accept or reject and he can only forward to someone. How to develop this?
    Please let me know your thoughts.
    Thanks in advance.
    Rajesh,

    Hi All,
    Thanks for the answers.. sorry for late replay.. requirement was not confirmed.
    1. As I described in my question
    After my custom conditions.. I have to send workitem back to initator ( Now initiator forwards the work item to someone else  ( need to restrict  users  based on role - )..
    While doing this process initiator should not have access to approve or reject he should only forward the workitem.
    After forwarding the work item -this person should have approve or reject options.
    My question is not answered..
    1. As Vijay told..
    Dont give Approve and Reject Options and in Description u specify like
    If I dont provide approve/reject when I am sending the work item to initiator - After initiator forwarding this work item - how do we the other approver will get options  Approve and Reject?
    2.  AS -surjith kumar
    If your Using the Rule or Expression you have to restrict via coding -  This will solve one of my problem -
    How I can restict  users with role based?
    My problem is not solved.. Initiator should not have access to approve but He should only forward the work item...
    Please let me know...

  • How JAVA works with collection from function

    All,
    I have a DB function which returns object collection of values. Could someone please tell me how java talks with the function and get the value?
    Thanks

    This is database function. my question is how java get those values from the function.
    Could you please post some sample code also?
    CREATE OR REPLACE
    Type T_PREO_RoleINFO is Object
    ROLE_ID NUMBER(10),
    ROLE_NAME VARCHAR2(20))
    CREATE OR REPLACE
    TYPE T_RoleInfo IS TABLE OF PREORDER.
    T_PREO_RoleINFO
    Function F_GetUserRole(Userid in number)
    return T_RoleInfo as
    V_Role T_RoleInfo;
    begin
         select T_PREO_RoleINFO(PREO_Role.ROLE_ID,PREO_Role.ROLE_NAME)
         BULK COLLECT INTO V_Role
         from preorder.PREO_Role, preorder.PREO_User_Role
         where PREO_Role.Role_id = PREO_User_Role.Role_id
         and PREO_User_Role.user_id = userid;
         return V_Role;
    end;

  • How find system specification in java

    is it possible to find out system specification in java e.g. motherboard, bios vendor & serial id etc.

    Welcome to the Forums.
    Please go through the FAQ of the Forum.
    You has posted your query in the wrong Forum, this one is dedicated to Oracle Forms.
    Please try {forum:id=1050}.
    Regards,

  • Missing start boundary exception, caused by an empty Part, how to handle?

    Hello,
    i wrote an application that automatically handles mails from laboratories. The only essential part of the mail is the attachment, where chemical analyses are submitted (from permitted addresses, recognized by whitelist and fileheader of the attachment). Other ways to submit data weren't allowed.
    Currently a mail was received that can't be parsed. It's from a laboratory, that
    use its provider's (a german internet suplier named Arcor) webmail, a browser-based mailing portal. It always worked fine, because they wrote some greetings. But this time they sent a blank message. The result is following structure of the mail:
    MIME-Version: 1.0
    Content-Type: multipart/mixed;
    boundary="----=_Part_50112_10709369.1203586767396"
    //Some X-Flags
    ------=_Part_50112_10709369.1203586767396
    Content-Type: multipart/alternative;
         boundary="*----=_Part_50111_24141780.1203586767396*"
    ------=_Part_50111_24141780.1203586767396--
    ------=_Part_50112_10709369.1203586767396
    Content-Type: application/octet-stream
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment; filename=somefile.bin
    ABCDEF.... //Some binary data
    ------=_Part_50112_10709369.1203586767396--
    It seems the webmailer creates an empty mailpart and only writes the end boundary (Line: ------=_Part_50111_24141780.1203586767396--).
    I know, the start boundary is really missing.
    I checked it out by getting a mailaccount from Arcor, and it always creates this structure when sending a message without a text. By the way, the Message-ID (header) generated from Arcor's server seems to be from javamail. (.....1234.567890.....JavaMail.ngmail@....).
    I don't know how many mailclients create "empty" parts, but impossible is nothing (e.g. other or future webmailer services).
    But how to handle?
    The error occures when calling MimeMultipart.getCount(), which causes to parse the mail if not parsed. All actions, which cause the mail to be parsed, will end in this exception (for this mail).
    I looked at the javamail source and found out, that the line of the empty part is not recognized as a boundary, because of its ending delimiters:
    if (line.equals(boundary))
    break;
    So the boundary is added to the preamble. It goes on with reading lines from the stream, until line == null.
    if (line == null)
    throw new MessagingException("Missing start boundary");
    Because there is no test, if the line matches the end boundary, it's not recognized. Wouldn't it be better in this case, to add an empty bodypart and set a variable to false (e.g. complete) instead of throwing an exception? Because MimeMultipart.parse() is called by other methods, like getCount, getBodyPart and writeTo, I can't nearly do anything automatically with the mail. How should i walk through the bodyparts and fetch the parts I'm interested in?
    Subclassing seems to be difficult to me:
    Object content = message.getContent();
    //javax.mail.Message, won't return a subclassed multipart
    if (content instanceof Multipart) {
    //recursive method!
    handleMultipart((Multipart) content); //collecting parts from multipart
    Of course, I could ask the laboratory: "please send me a greeting!" ;-)
    Greetings,
    cliff

    Interesting.
    Yes, it's probably a bug that JavaMail allows you to
    create a multipart with no body parts, since the
    MIME specification doesn't allow that. Still, the
    webmail application should be fixed so that it doesn't
    try to do that, at least including an empty plain text
    body part.
    Please contact the webmail provider and tell them of
    this bug in their application.
    I'll also look into making JavaMail cope with these
    broken messages more gracefully. Contact me
    at [email protected] and I'll let you know when
    I have a version ready to test.

  • Model of how APEX handles data (values)?

    Reference {thread:id=2486655}
    I'm trying to get a model of how APEX handles data (values). There are several places(?) that data (values) can exist. Or so it seems. I'm trying to understand how these work -- to put all the pieces together.
    Question:
    A) Where data can be?
    1) In the database
    2) In the session
    3) Rendered -- and hence displayed on the screen, if a displayed value -- but not in the session
    4) In perhaps(?) some working memory pool(?) but different from the page rendered values I see on the screen?
    5) Other?
    Why do I think this is relevant?
    Question:
    B) If there are rendered values and session values different from the rendered values, then when code executes, which of these values (rendered or session) is it executing against?
    And maybe the answer is, "You don't understand what's going on." Yes, "Exactly!" Hence the question.
    Best wishes,
    Howard

    Howard (DBA in Training) wrote:
    I'm putting this together now. For example:
    I set the value of a Page Item (say, :P2_DATA) to "BEFORE" in a Before Region process and change it to "AFTER" in an After Region Process. 'BEFORE' was displayed on the screen but 'AFTER' was in the session state. So I see that PL/SQL changes these values in the session state. But it doesn't "go back" to change the HTML after the region has been rendered -- hence we see BEFORE shown on the screen. (I'll have to think about what a Dynamic Action does.)
    Also, if a page item has a default value, say 'DEFAULT' then that value doesn't get into the session state. At least, not with my current settings. Oh, that explains a lot of confusion!! I suppose there's a logical reason for this but who would expect default values to be differently from other PL/SQL operations on the item?
    Questions:
    1) So why does a default value not get put into the session state?Several reasons, among them:
    *1. When/why is the value required?* Region items (and thus their source and default values) are rendered in region/item sequence order. The item's source/default value would therefore not be available in session state until it's rendering point. This is frequently later in page show processing than the value is actually required, such as the common use case of including a data value in the page or region title. Setting the value in a Before Header/Regions computation or process makes it available as required before the item is actually rendered.
    *2. The rendered page might not be submitted.* Default values are typically set when a page will create a new row. Consider the situation where the user clicks a "Create" button and is presented with an order entry form containing several default values. They then decide they don't want to create a new order after all, and navigate away from the form page via some mechanism that uses a redirect rather than a submit (such as a default "Cancel" button). This means that no page submit processing is performed, and generally that no session state management is performed. If the default values were set in session state, the order entry page would contain the default values for the non-existent order despite the user never submitting it. This may have unwanted side-effects if these values are referenced elsewhere in the application, and therefore would require extra session state management to be built into the application.
    *3. A rendered item might not be submitted with the page.* Per the HTML specification, the values of disabled controls unchecked checkboxes are not POSTed on page submit. Consider a situation where a checkbox item is set with several default values, but the application requires that the checkboxes be cleared and disabled by a dynamic action if the user chooses certain options from a select list. In this case, on page submission no values are submitted into session state for the checkbox item. If the defaults had been set in session state, then the application would be in an inconsistent state, with the user-selected option indicating that none of the checkboxes were checked, but with session state holding values showing that they were. This would require additional processing to ensure that the application's state was consistent before saving it to the database.<sup>1</sup>
    2 & 3 are particularly significant in basic wizard-generated applications. Doing things in this way, the wizard-generated DML and navigation "just works", without the need for additional session state management.
    2) Is there a Page Item setting that causes the default value to be saved to the session state?No. Hopefully the explanations above provide sufficient reason to show why this is genearlly not desirable. On the rare occasions when it is required, set the session state value using a computation or process.
    <sup>1</sup> There are other reasons&mdash;mainly security related&mdash;that make it good practice to perform such checks in more complex and internet-facing applications anyway.

Maybe you are looking for

  • Power outtage: Can no longer mount disk?! Please help

    Firmware 7.2.1 and seagate 500 gb disk. everything has been fine for a while until our power went out last night. when i woke up to check some of my overnight downloads, i could no longer mount the disk. when i clicked on my alias it said it could no

  • How to convert sapscript(Purchage order) inot pdf format & send in  mail

    Dear Gentlemen, I got one req. <b>convertion of sapscript(purchage order) to pdf format and send converted pdf format in the mail.</b>   Can anybody please give detail & proper way to achive this requriment. It is very useful to me, I am thankful to

  • Which clients are using my Sun One server for authentication?

    We use Sun One ver. 5.2 . Our LDAP clients use it for authentication. How can I list which clients recently used the Sun One server to authenticate? The reason I need that is because I want to upgrade the Sun One server and I want to notify the clien

  • PO FREE INDICATOR flag

    I am unable to identify the underlying table which stores FREE INDICATOR flag. Can anyone provide me the table name in which this free indicator get stored ?It will be of much helpful. Thanks

  • HOW DOES THE SYSTEM CALCULATES THE TAXES

    Hello Experts, Tell me the method of calculating taxes  pricing procedure in purchase order. Thanks and Regards Nilu S.