C++ programmer  needs help in Java.

Greetings, I am new to Java after programming in C++ and am having a few troubles finding parallels to a few essential operations, such as:
What are the Java equivalents to cout, cin and getch()?
Or simply, how do you do output, get input from the user, and pause execution?
Thank you all for any help you can offer.
Dagkhi

Look over this group of threads that a search of the Forum using "system.in" listed:
http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=%2Bforum%3A54&qt=system.in&x=14&y=6

Similar Messages

  • C++ programmer needs help w/Java :)

    Hey,
    I'm working on a project and I'm supposed to write it in java. So I've been looking around and haven't been able to figure out exactly how input/output works. My main concern is the input function. I know that in C++ we use cin << and fin << to read in data from the command line or a file. How can I translate this to java code? I'm approaching this program as I would with a c++ program so I probably won't understand if you use html source code in your reply...yes engineers can be dumb...I'm living proof. Or if you could explain how I/O works in java I would apprecitate that as well.
    Thanks,
    Mayo

    I was wrong above. here is the way below.
    I don't know what I was thinkin earlier,
    well you know what you said engineers.:-)
    If there is any questions about the below
    code please feel free to ask.
    import java.io.*;
    public class ReadKeys
         public static void main(String args[])
            BufferedReader bread;
              try {
            bread = new BufferedReader(new InputStreamReader(System.in));
            String str;
            while( (str = bread.readLine()) != null  ) {
              System.out.println(str);
           }catch(IOException io) { }
    }

  • Need help with java

    ok so i have a midterm and need help this question that is gonna be on the midterm. i dont know how to do it and its worth 16 marks!!!! here it is
    the UW Orchestra wants to produce a CD containing all the pieces of music
    from its upcoming concert. In order to do that, it needs to calculate the total length of time for the
    CD. In addition, the conductor wishes to know which piece of music has the longest duration.
    Sample output for the program.
    The Swan (3.88)
    The Bee (0.98)
    Claire de Lune (6.02)
    Liebesfreund (3.38)
    Ragtime (3.48)
    The total time for the CD is 18.74 minutes.
    The longest piece is Claire de Lune.
    Do not include the HTML that is required to embed the program into a Web page (that is, show
    only what you would write between <script> and </script> tags).
    [4 marks] In the following space, define a function, Print, that takes two parameters, Title and
    Length, and outputs a line of text such that Title appears in italics, followed by Length in
    parentheses. The function also returns the value of Length.
    For example, Print("My World",30) will output the line
    My World (30)
    and return the value 30.
    Put your JavaScript program for the remainder of this question in the space provided on the next
    two pages.
    [9 marks]. For each piece of music, your program should input the title of the piece and the
    duration (in minutes) for that piece, and it should output a line showing those values using the
    Print function just defined. After all pieces have been listed, the program should output the
    total length of time for the CD, adding in 0.25 minutes between each piece of music (which is
    needed on the CD to separate the pieces).
    [3 marks] The program should also output the name of the piece that has the longest playing
    time.
    Use reasonable variable names, indentation and good programming style. Documentation and
    comments are not required, but you may add them to explain any assumptions you might want to
    make. You need not check that the input is valid, and you may assume that no two pieces have the
    same duration.
    can anyone help me out! i would be indebt of ur kindness if u can help me out!

    This forum is for Java, not JavaScript. The two have nothing to do with each other.
    And anyway, this is your studying, so you should try to do it, put forth your best effort, and ask specific questions (on the proper fourm).

  • Need help with Java Script to perform a calculation in Adobe Acrobat Pro 9 form

    I have a form (test) that I am creating in Adobe Acrobat Pro 9.
    I need help creating custom Java Script so I can get the desired answer.
    1) There are several questions in each group that require a numerical answer between 0-4
    2) There is a total field set up to sum the answers from all above questions
    3) The final "score" takes the answer from Step 2 above and divides by the total possible answer
    Any help on what Java Script I need to complete this would be greatly appreciated!
    I've attached a "spreadsheet" that shows it in more detail as well as what formulas I used in Excel to get the desired end result.
    Thanks in advance.

    Have you tried the "The field is the average of:"?

  • Need help in Java Script

    i Need some help in Java Script,
    am using the following code :
    <script type="text/javascript">
    var newwindow;
    function poptastic(url)
    newwindow=window.open(url,'name','height=300,width=400,left=100, top=100,resizable=yes,scrollbars=yes,toolbar=yes,status=yes');
    if (window.focus) {newwindow.focus()}
    else {newwindow.close()}
    //     if (window.focus) {newwindow.focus()}
    </script>
    In HTML,
    thWorld Environment
    Day, June 5<sup>th</sup>,2005
    Am using onmouseover event, so that when my mouse in on the link, popup is opened....and when my mouse is out of the link, the new window should b closed....
    but according to the above code, the new window is opened but have to close it manually....
    Is there any other way to close the popup when my mouse is out of the link

    Prawn,
    This is not really a good way to make friends. With the cross posting and the posting in a wrong forum anyway thing you have going.
    Please kindly take your question to an appropriate JavaScript forum.
    Have a happy day.
    Cross post from http://forum.java.sun.com/thread.jspa?messageID=3797201

  • Need Help Regarding JAVA BEAN

    Is any one tell me that JAVA BEAN only used in WEB or also you in Desktop applications???? and aslo tell how i implement Java class and use JAVA BEAN. I need help regarding above matter
    thanks in advance
    Rehan MIrza

    Here is a good link that indicate that JavaBean is not only for applets
    http://java.sun.com/docs/books/tutorial/javabeans/whatis/beanDefinition.html
    quote:
    The JavaBeans API makes it possible to write component software in the Java programming language. Components are self-contained, reusable software units that can be visually composed into composite components, applets, applications, and servlets using visual application builder tools. JavaBean components are known as Beans.
    Francois

  • Need help on Java in sound application

    A good day to everyone here,
    I need help on using Java.My project is mainly manipulating WAV sound files with Java. There is some problem.I hope you all can help me. I couldn't find much info about Java in sound manipulating,sample coding or something like that. I need to find the command to
    1) Find each sampling point value in a sound file.
    2) Find the number of sampling point and the average value of the all the sampling point.
    3) Record the sound file in a different bit rate format.
    I dont know how to go about it.I really hope you all can help me, or direct me to any resources that may help me. Your help is very much appreciated.
    Thank you very much....

    i found this coding in a website n i not very sure that i understand it.
    can anyone tell me if i can find the sample point value of a sound file with this coding (byte[] source is byte array of the sound file).
    thanks...for all the help
    public byte[] executeAmplitudeTransformationInternal(byte[]
    source)
    int[] sampleArray = getSampleArray(source);
    int[] newSampleArray = executeTransformation(sampleArray);
    //convert 16 bit samples back to 8 bit byte[]
    return getByteArray(newSampleArray);
    public int[] getSampleArray(byte[] eightBitByteArray) {
    //create an array 1/2 the size (since every 2
    //8bit samples makes 1 16bit sample)
    int[] toReturn = new int[eightBitByteArray.length];
    int index = 0;
    for (int t = 0; t < eightBitByteArray.length; t += 2) {
    //read the high bit
    int low = (int) eightBitByteArray[t];
    //read the low bit
    int high = (int) eightBitByteArray[t + 1];
    //bit shift the high bit 8 bits to the left and
    // "And" the low bit against 255 to drop any
    //sign extended data in the top 8 bits.
    //refer to the tutorial for more clarification
    toReturn[index] = (high << 8) (low & 0x00ff);
    index++;
    return toReturn;
    public byte[] getByteArray(int[] sampleArray) {
    //create a new byte[] twice as big as the sample array
    //because it takes two 8-bit bytes to represent one
    //16-bit sample
    byte[] toReturn = new byte[sampleArray.length * 2];
    int index = 0;
    for (int t = 0; t < sampleArray.length; t++) {
    int sample = sampleArray[t];
    //this places the low byte in the array.
    //the downcasting automatically lops off the high byte
    toReturn[index] = (byte) sample;
    index++;
    //this byte shifts the sample 8 bits to the right
    //this puts the old high byte in the position of the low byte.
    //this way the high byte remains after the downcasating from
    //an int to a byte
    toReturn[index] = (byte) (sample >> 8);
    index++;
    return toReturn;
    public int[] executeTransformation(int[] sampleArray) {
    //create a clone sample array
    int[] newSampleArray = new int[sampleArray.length];
    //apply algo to each sample
    for (int t = 0; t < sampleArray.length; t++) {
    int result = (int) (sampleArray[t] );
    //add the sample
    newSampleArray[t] = result;
    return newSampleArray;

  • Need help with Java always get error

    hey guys need help
    this the problem i get :
    I go to certain websites and I get this error with firefox.
    This Site requires that JavaScript be enabled.
    It is enabled.
    This is the one of the errors in java script console with firefox.
    Error: [Exception... "'Component does not have requested interface' when calling method: [nsIInterfaceRequestor::getInterface]" nsresult: "0x80004002 (NS_NOINTERFACE)" location: "<unknown>" data: no]
    I have installed the java script from there home site and did a test and says everything is fine. Any ideas?
    please help

    Hi 49ers,
    Sorry not to have any real idea of how to help you out here, but this is a Java forum, not JavaScript.
    Some Firefox expert may stumble across your post and be able to offer some advice (I hope they do) but this isn't really the best place to post such questions.
    Try here: http://www.webdeveloper.com/forum/forumdisplay.php?s=&forumid=3
    Good luck!
    Chris.

  • Need Help with Java Desktop CP Icon

    I just formatted and reinstalled Windows XP Home SP2 and installed the JRE 1.5.0.02. I usually see an icon in my Control Panel but it only appears in the Administrator's CP which I can reach in Safe Mode of course, but it would be easier to deal with if it appeared somewhere on my desktop/taskbar or CP (I am also an Admin). In Safe Mode I made sure that the right settings were made for displaying, but it doesn't.
    I know precious little about Java so I need help here.

    This forum is dedicated to Sun's Java Desktop System, an alternative desktop operating environment. Try reposting here:
    http://forum.java.sun.com/forum.jspa?forumID=54

  • Need help for java program

    Hi,
    I need help with my web application. When i tried to run it using
    localhost:8080
    it's giving me error that
    signup.do file is not available.
    can someone tell me what could be wrong with my code?
    I want to know what is .do file and what needs to do to have remove the error
    I have also used struts config file.
    Please help me.
    Message was edited by:
    star4588

    See struts documentation here http://struts.apache.org/1.2.9/userGuide/building_controller.html#action_mapping_example
    you should have something like that :
    <action-mappings>
            <action
                path="/signup"
                type="org.apache.struts.webapp.example.SignupAction"
                name="signupForm"
                scope="request"
                input="/signup.jsp"
                unknown="false"
                validate="true" />
        </action-mappings>in your struts-config.xml.
    Hope That Helps

  • Newbie Java programmer needs help

    Everytime I go to run my program, I get the error
    "the class welcome.Welcome does not exist" and it's right, there is no such thing, nor will there ever be. There is a Welcome.class though, but it doesn't want to see it. Is there some setting I'm missing(i'm using Borland JBuilder 5 Personal) or is my code wrong. Here it is though, please help!
    import javax.swing.JOptionPane;
    public class Welcome
    public static void main( String args[] )
    JOptionPane.showMessageDialog(
    null, "Welcome to Java Programming" );
    System.exit( 0 );
    }

    Your code compiled and ran perfect on my machine.
    Your problem lays in either:
    1) your WYSIWYG (JBuilder or whatever)
    2) your class path
    I may be wrong. I have never used this program that you are talking about. but it seems to me that if you were able to get this program(IDE) running in the first place it should aready have some kind of JRE installed.
    You may wan't to just download the newest JDK if you don't already have it. Or try to locate the path for the command named "java" and try it like this:
    C:\whatever\path\it\is\java Welcome
    while in the same directory of the Welcome class.
    Hope this helps,
    Ian

  • Immature Java Programmer needs help...

    I do not want to generate html code inside my java code, rather open a html page by referencing it in my java code to see it in the browser. For example, here is my code:
    package mrpt;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Login extends HttpServlet
         public void doGet(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException
              response.setContentType ("text/html");
              PrintWriter out = response.getWriter ();
              response.sendRedirect ("http://localhost:8080/Login.htm");
    The code compiles but when I open it in the browser (.\servlet\mrpt.Login) I get an error page "HTTP Status 500 -". I'm using the Tomcat Apache server. I have my html in the root directory and my .java and .class in the .\webapps\ROOT\WEB-INF\classes\mrpt. Can this be done? Is my code correct?

    I do not want to generate html code inside my java
    code, rather open a html page by referencing it in my
    java code to see it in the browser. For example, here
    is my code:
    package mrpt;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Login extends HttpServlet
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
         throws ServletException, IOException
    I don't think this is right. try leaving it out ---          response.setContentType ("text/html");
              PrintWriter out = response.getWriter (); response.sendRedirect
    t ("http://localhost:8080/Login.htm");
    The code compiles but when I open it in the browser
    (.\servlet\mrpt.Login) I get an error page "HTTP
    Status 500 -". I'm using the Tomcat Apache server. I
    have my html in the root directory and my .java and
    .class in the .\webapps\ROOT\WEB-INF\classes\mrpt. Can
    this be done? Is my code correct?

  • Non-Programmer Needs Help!!! (desperately)

    Ok, I want to create games for a virtual world website. I also want the website to be a game itself. Right now, I am working on creating a card game for two players (with the option of playing the computer). They each have 2 decks to draw from and a place for 2 cards to be displayed (their "hand") before they place it on the game board. I don't want their opponent to see the cards in their "hand" until they are placed on the game board. When a player has two cards in his hand, I want them to have the capability of enlarging the image of the card to full size in a pop-up type window, so they can calculate their strategy. The game itself is similar to the popular battle card games, so regular playing card games don't help me. I want the image of the card to be displayed on the game board either right side up or upside down depending upon the button pushed by the player. I want each player to play 1 card from one pile (blue-50 cards total) and 4 cards from the other pile (red-200 cards total). They can only draw 1 blue card, and 1 red card on their first turn. After that, they can only draw 1 red card per turn, until they have drawn 4 red cards total. The total number of cards each player can have on the game board is 5 cards, then the round ends. Each deck has the same cards but shuffled in random order. The decks can't be stacked the same, for each player. Each card has a certain value. The card from the blue pile is the main card that the cards from the red pile will add to or subtract from. If the match between the opponents is tied, no score is given to either player, but the cards from both players to go to the corresponding "tie" piles (one red and one blue) that will be randomly distributed by the computer, once each player has exhausted their own decks first. The tie piles are used at the end of the game to play the final round or rounds of the game. After each round, the victor of that round gets the points on his opponents cards, plus 1000 points for winning the round. I want the cards to just "disappear" or placed in the computer's "discard" pile after each round, so they cannot be used again. I want each player to have a turn being first at the beginning or each round. (If player 1 is first in round 1, player 2 will go first in round 2 and so on.) I want the scores for each card to be calculated and placed in a box according to which player the cards belong to. Once the round is ended, the victor will receive the final score in their "total score" box. I also want a "round number" box to indicate which round it is. No winner will be declared until the players use all their cards and/or the computer deals all the tie deck cards (which are shuffled before dealing). At the end of the game, the person with the highest score is the winner.
    I also would like to allow players to challenge each other and accept or decline a challenge. In order to do that, the players must login first. There must also be a list of available players to challenge.
    Is there a program that not only builds the user interface, but also will allow me to insert my graphics? Kind of like WYSIWYG HTML builders? (Preferably FREE) I have a gui builder, but have no clue as to how to put in the graphics or get it to work. I don't have any connections to the programming world, nor am I able to return to school at this time. The programs that Sun offers are not adequate for me, because I need to be able to install it, and run it without going through the "msdos classpath" thingy. I need a "wizard" type program that is truly for "dummies." Something that I can just put in my images and tell it what I want it to do IN PLAIN ENGLISH. For instance, if I want the "login button" to save the login information to a file and/or to the game. The players can have their same login info stored in a file, and they can return without creating a new name. The website service I want to place this on, doesn't allow chmoding for CGI, so I can't use that. Another example, if I want each card to have a differnt point level and either subtract from or add to the blue. Or how to get the pop-up for the card displayed in the player's hand. I don't know what else to do. Any suggestions?

    <blockquote>
    The programs that Sun offers are not adequate for me, because I need to be able to install it, and run it without going through the "msdos classpath" thingy. I need a "wizard" type program that is truly for "dummies." Something that I can just put in my images and tell it what I want it to do IN PLAIN ENGLISH. For instance, if I want the "login button" to save the login information to a file and/or to the game. The players can have their same login info stored in a file, and they can return without creating a new name. The website service I want to place this on, doesn't allow chmoding for CGI, so I can't use that.
    </blockquote>
    This is a surely a joke. You honestly expect to get this for free. Even for an experienced programmer, to write 3/4 decent games - configure them to your network and meet these conditions. You're talking BIG or big-ish project here. As per your request, there is no such thing as point and click programming and there never ever will be.
    Use Macromedia Director. Closest thing you'll get to
    WYSIWYG programming. It's for simpletons and
    non-programmers.Ah, noooo. The shockwave games have been programmed in Lingo, which is quite powerful and much harder as a programming language than java (its also outdated, has some nasty featured and its a definite falling star). Flash gets a bit nearer with a point and click effort and you can do a surprising amount without knowing about programming, also as a media for the Internet its better supported than Shockwave and even java for the Web. But for any sort of worthwhile game need sprogramming knowledge.
    To conclude:
    you don't want to learn to program.
    noone is going to do this for you.
    You're a bit f***ed then aren't you.
    On a brighter note, if you pay me ?1,000.00 (half in advance), I'll think about it - solution in java or Flash, 3 games, ?1,500.00 for both. I can take it or leave it btw, couldn't give a sh*t either way.

  • Lost VB Programmer needs help

    Hi,
    I have created a JFrame with a JSplitPane and placed a JTree in the left side of the SplitPane. I made a class that populates the tree with a tree of options. When the user clicks the tree I want he right pane to change. The treemenu was an event listner that is working fine.
    The problem is the left pane is in a separate .java file called TreeMenu. On the JFrame I simply create a new instance of it and it populates the tree for me.
    As a VB programmer I would declare my TreeMenu to have an event such as MenuChanged("Selected Help"). The JFrame would see the message and call the right pane to update.
    How do I do this in Java? My problem occurs when I move code out to a separate class. If everything was done frm the one frame then I would be fine, but i want to modularise the application.
    Please help.
    Aaran

    Here's a bit of code that may help you with your modularity issues.
    File: Switchboard.java
    interface Switchboard {
        void operator(TreeData identity);
    }File: CallMaker.java
    import java.awt.event.*;
    public class CallMaker implements TreeSelectionListener {
        private TreeData identity;
        private Switchboard destination;
        CallMaker( TreeData id, Switchboard swbd ) {
            identity = id;
            destination = swbd;
        public void valueChanged( TreeSelectionEvent e ) {
            destination.operator( identity );
    }For what you're trying to do I would suggest the following:
    1)Declare the Tree Populator to implement the Switchboard interface.
    2)put the code that populates the table into the operator method, or
    simply call the class/method that populates the tree from the
    operator method.
    3)Use an instance of the CallMaker class as a Listener on your tree.
    It should work something like this:
    public class PanePopulator implements Switchboard;
    //Other code and whatnot...
       public void operator(TreeData td) {
          //Decide how to populate the right pane
          //based on the TreeData.  Call other classes/methods.
    }In a separate file...
    public class TreeSide {
       JTree tree = new JTree();
       //initialize the tree.
       TreeData treeInfo = new TreeData();
       PanePopulator rightPane = new PanePopulator();
       tree.addTreeSelectionListener(new CallMaker(treeInfo, rightPane));
       treeInfo = (TreeData)theCurrentTreeSelection;
    }as long as treeInfo contains the data you need to populate the right pane, you'll be fine.
    When a selection is made the CallMaker instance calls: rightPane.operator(treeInfo);
    This provides your rightPane instance with the information it needs to populate the rightPane.

  • Need help regarding Java decoding of IMAP attachment (IOStream related ques

    Hi ,
    I need some help regarding the processing of an IMAP attachment , It is a basic IOStream related question I guess.
    I have some attachment to a mail , I try to fetch it using javamail and read the content and write it to a file , I was able to do it successfully when I was using stream.read( tempBuffer) function but when I started using stream.read( tempBuffer, 0, m_maxDataSize ); it is giving me following exception
    java.io.IOException: Error in encoded stream: needed at least 2 valid base64 characters, but only got 1 before padding character (=), the 10 most recent characters were: "/59PT/eXQ="
         at com.sun.mail.util.BASE64DecoderStream.decode(BASE64DecoderStream.java:259)
         at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:148)
    ***Here is the snippet of code that is running this:***
    m_contentObj = m_message.getContent();
    if(m_contentObj instanceof InputStream)
         System.out.println(" Content is type of InputStream");
         InputStream stream = (InputStream) m_contentObj;
         byte[] tempBuffer = new byte[m_maxDataSize];
         stream.skip( m_currPos );
         int bytesRead=stream.read( tempBuffer, 0, m_maxDataSize );
         System.out.println(" Read the following no of bytes from the Object::"+bytesRead);
         m_currPos+=     bytesRead;
    Please suggest what to do.
    Thanks & Regards
    Saurabh

    BUMP, just incase its been missed by a new board member

Maybe you are looking for

  • Error while enhancing the Extract structure in LBWE

    Hi All, When I am trying to change the extract structure os logistic extractors in LBWE, it is giving me an error saying "Entries for application 11 still exist in the extraction queue". Below is my scenario: I have 3 clients in the same R/3 system,

  • Vista on Macbook Pro (Not Unibody)

    I'm going to upgrade my XP Boot Camp to Vista. I've run the Vista upgrade advisor, and it says it's all good to upgrade to ultimate edition. My question is this, do I get the 32 or 64bit version of Vista Ultimate? And is there much difference between

  • Duplicate records in hierarchy

    In R/3 we can create a set with duplicate values in different nodes, but the same hierarchy cant be loaded into BI due to the duplicate records. Is there a way i can load the hierarchy with duplicate values? I dont want to supress the duplicate value

  • Parent Control Issues

    My wife and I just purchased an Ipad mini for our 8 year old son as a reward for a summer reading goal.  We have read about parent controls and restrictions but can not seem to find the kind of app or setting that will allow us the sort of restrictio

  • Spreads and single pages export to pdf

    Hi I have a document that is laid out as spreads 2 a4's next to each other. ie the back page is shown as the first with the front page as page 2. I need to export for both single page pdf electronic copy (ie front cover currently page 2 as page 1 of