<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Computer languages &#8211; Henry Poon&#039;s Blog</title>
	<atom:link href="https://blog.henrypoon.com/blog/tag/computer-languages/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.henrypoon.com</link>
	<description></description>
	<lastBuildDate>Wed, 05 Oct 2022 01:55:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">83044199</site>	<item>
		<title>Serial Communication in Java with Example Program</title>
		<link>https://blog.henrypoon.com/blog/2011/01/01/serial-communication-in-java-with-example-program/</link>
					<comments>https://blog.henrypoon.com/blog/2011/01/01/serial-communication-in-java-with-example-program/#comments</comments>
		
		<dc:creator><![CDATA[hp]]></dc:creator>
		<pubDate>Sun, 02 Jan 2011 01:46:37 +0000</pubDate>
				<category><![CDATA[computer stuff]]></category>
		<category><![CDATA[9]]></category>
		<category><![CDATA[All That]]></category>
		<category><![CDATA[APT]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[Chan]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Comment]]></category>
		<category><![CDATA[Computer]]></category>
		<category><![CDATA[Computer languages]]></category>
		<category><![CDATA[Const]]></category>
		<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[D]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Dia]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[Drive]]></category>
		<category><![CDATA[EAR]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Final]]></category>
		<category><![CDATA[Find]]></category>
		<category><![CDATA[Flag]]></category>
		<category><![CDATA[Go]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Hole]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[IME]]></category>
		<category><![CDATA[Introduction]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[ise]]></category>
		<category><![CDATA[It]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Lag]]></category>
		<category><![CDATA[Lie]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[Object-oriented programming languages]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Over]]></category>
		<category><![CDATA[Page]]></category>
		<category><![CDATA[Parameter]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Plan]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Programming languages]]></category>
		<category><![CDATA[RAR]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[Rolling]]></category>
		<category><![CDATA[Run]]></category>
		<category><![CDATA[Serial]]></category>
		<category><![CDATA[Serial communication]]></category>
		<category><![CDATA[Software design patterns]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Speed]]></category>
		<category><![CDATA[STR]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[Struct]]></category>
		<category><![CDATA[Swing]]></category>
		<category><![CDATA[Thou]]></category>
		<category><![CDATA[Time]]></category>
		<category><![CDATA[UNC]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[Variable]]></category>
		<category><![CDATA[Vol]]></category>
		<category><![CDATA[Wiki]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress.com]]></category>
		<category><![CDATA[Writing]]></category>
		<category><![CDATA[XBee]]></category>
		<category><![CDATA[Z]]></category>
		<category><![CDATA[Zip]]></category>
		<guid isPermaLink="false">http://henrypoon.mooo.com/blog/serial-communication-in-java-with-example-program</guid>

					<description><![CDATA[This is more of a follow-up to my previous post about serial programming in Java (here) and how to install the RXTX libraries (here).&#160; This post also assumes that Java is already properly set up with RXTX. Generally, communication with serial ports involves these steps (in no particular order): Searching for serial ports Connecting to [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">This is more of a follow-up to my previous post about serial programming in Java (<a title="Java Serial&nbsp;Programming" href="http://henrypoon.wordpress.com/2010/10/11/java-serial-programming/" target="_blank" rel="noopener">here</a>) and how to install the RXTX libraries (<a title="Installing RXTX for Serial Communication with&nbsp;Java" href="http://henrypoon.wordpress.com/2010/12/25/installing-rxtx-for-serial-communication-with-java/" target="_blank" rel="noopener">here</a>).&nbsp; This post also assumes that Java is already properly set up with RXTX.</p>



<p class="wp-block-paragraph">Generally, communication with serial ports involves these steps (in no particular order):</p>



<ul class="wp-block-list"><li>Searching for serial ports</li><li>Connecting to the serial port</li><li>Starting the input output streams</li><li>Adding an event listener to listen for incoming data</li><li>Disconnecting from the serial port</li><li>Sending Data</li><li>Receiving Data</li></ul>



<p class="wp-block-paragraph">I wrote an example program that includes all of those steps in it and are each in their own separate method within the class, but first I will go through my hardware set up.</p>



<h1 class="wp-block-heading">Hardware Setup</h1>



<p class="wp-block-paragraph">My current hardware setup is as follows:</p>



<ul class="wp-block-list"><li>PC connected to an XBee</li><li>Arduino connected to an XBee</li></ul>



<p class="wp-block-paragraph">User input is given from the PC through the a Java GUI that contains code for serial communication, which is the code presented here.</p>



<p class="wp-block-paragraph">The Arduino is responsible for reading this data.&nbsp; This set up is pretty much using my computer as a remote control for whatever device is on the Arduino end.&nbsp; It could be a motor control, on-off switch, etc.</p>



<h1 class="wp-block-heading">Existing Code</h1>



<p class="wp-block-paragraph">The purpose of this post is to discuss serial programming in Java, and not GUI’s.&nbsp; However, I did create a GUI for testing purposes.&nbsp; See the Code Downloads section for the actual files.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" decoding="async" width="300" height="136" src="https://i0.wp.com/blog.henrypoon.com/wp-content/uploads/2011/03/javagui.png?resize=300%2C136&#038;ssl=1" alt="" class="wp-image-933" srcset="https://i0.wp.com/blog.henrypoon.com/wp-content/uploads/2011/03/javagui.png?resize=300%2C136&amp;ssl=1 300w, https://i0.wp.com/blog.henrypoon.com/wp-content/uploads/2011/03/javagui.png?w=640&amp;ssl=1 640w" sizes="(max-width: 300px) 100vw, 300px" /></figure>
</div>


<p class="wp-block-paragraph">Above is the picture of the GUI complete with the buttons that I use to interact with the program.&nbsp; I also added key bindings which I can use to control the throttle.</p>



<p class="wp-block-paragraph">When the program is first started, none of the GUI elements will work except for the combo box and the connect button.&nbsp; Once a successful connection is made the controls are enabled.&nbsp; This is done through the use of the <em>setConnected(true)</em> and the <em>toggleControls()</em> methods shown in the example code that follows.</p>



<h1 class="wp-block-heading">Imports</h1>



<p class="wp-block-paragraph">The imports i used for this program were as follows:</p>



<pre class="wp-block-code"><code lang="java" class="language-java">import gnu.io.*;
import java.awt.Color;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.TooManyListenersException;</code></pre>



<p class="wp-block-paragraph">Depending on the Java IDE it might already know to tell you to use these imports except for the first one.&nbsp; That first import is specific to RXTX, and all its library methods/classes are in there.</p>



<h1 class="wp-block-heading">Class Declaration</h1>



<p class="wp-block-paragraph">The code here reads:</p>



<pre class="wp-block-code"><code lang="java" class="language-java">public class Communicator implements SerialPortEventListener</code></pre>



<p class="wp-block-paragraph">I named my class <em>Communicator</em>, but the name is really up to the programmer.&nbsp; The name pretty much reflects its intended use.</p>



<p class="wp-block-paragraph">The class should also <em>implement</em> the <em>SerialPortEventListener</em> class.&nbsp; This is a class in RXTX and is required in order to receive incoming data.</p>



<p class="wp-block-paragraph">On some IDE’s this may generate a public void method called <em>serialEvent()</em>.&nbsp; This method will be defined later.</p>



<h1 class="wp-block-heading">Class Variables and Constants</h1>



<p class="wp-block-paragraph">Below are the variables and constants that I defined in my class.&nbsp; What the variables are for is in the comments but a more detailed explanation will follow.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //passed from main GUI
    GUI window = null;

    //for containing the ports that will be found
    private Enumeration ports = null;
    //map the port names to CommPortIdentifiers
    private HashMap portMap = new HashMap();

    //this is the object that contains the opened port
    private CommPortIdentifier selectedPortIdentifier = null;</code></pre>



<p class="wp-block-paragraph">I could have easily put the variable definitions in the constructor but it wouldn’t change anything.</p>



<p class="wp-block-paragraph">The <em>GUI</em> object is another class that I wrote separate from this one that contains all the GUI elements.&nbsp; The GUI class extends <em>javax.swing.JFrame</em>.</p>



<p class="wp-block-paragraph">The <em>HashMap</em> is for mapping each of the ports’ names to the actual object. What that means is that I can associate (<em>put()</em> method) the name of a serial port, say a string that says COM1, to an object in the code.&nbsp; Later, I can access the name COM1 from the <em>HashMap</em> by using the <em>get()</em> method and it will return the object that it was associated with previously.</p>



<p class="wp-block-paragraph">The <em>CommPortIdentifiers</em> object is needed to gather the list of ports that are available for connection. by using its <em>getPortIdentifiers()</em> method.</p>



<p class="wp-block-paragraph">The <em>SerialPort</em> object is for storing the data for the port once a successful connection is made.</p>



<p class="wp-block-paragraph">The <em>InputStream</em> and <em>OutputStream</em> is the object that is required for sending and receiving data.</p>



<p class="wp-block-paragraph">The Boolean variable <em>bConnected</em> is just a flag that I use for enabling and disabling elements on the GUI.</p>



<p class="wp-block-paragraph">The constant <em>TIMEOUT</em> is a number required when opening the port so that it knows how long to try for before stopping.</p>



<p class="wp-block-paragraph">The constants for the ASCII values are some values that I use to send through the output stream that act as delimiters for data.</p>



<p class="wp-block-paragraph">The string <em>logText</em> is basically what the comment says.&nbsp; When stuff happens in the program, the program stores a string in this variable and it will be appended to a text area in the GUI.</p>



<h1 class="wp-block-heading">Searching for Available Serial Ports</h1>



<p class="wp-block-paragraph">The method below is for searching for available serial ports on the computer.&nbsp; Code adapted from Discovering Available Comm Ports from the Reference Material.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //search for all the serial ports
    //pre style="font-size: 11px;": none
    //post: adds all the found ports to a combo box on the GUI
    void searchForPorts()
    {
        ports = CommPortIdentifier.getPortIdentifiers();

        &lt;span style="color: blue;"&gt;while (ports.hasMoreElements())
        {
            CommPortIdentifier curPort = (CommPortIdentifier)ports.nextElement();

            //get only serial ports
            &lt;span style="color: blue;"&gt;if (curPort.getPortType() == CommPortIdentifier.PORT_SERIAL)
            {
                window.cboxPorts.addItem(curPort.getName());
                portMap.put(curPort.getName(), curPort);
            }
        }
    }</code></pre>



<p class="wp-block-paragraph">The method <em>getPortIdentifiers()</em> returns an Enumeration of all the comm ports on the computer.&nbsp; The code can iterate through each element inside the Enumeration and determine whether or not it is a serial port.&nbsp; The method <em>getPortType()</em> can identify what kind of port it is.&nbsp; If it is a serial port, then the code will add its name to a combo box in the GUI (so that users can pick what port to connect to).&nbsp; The serial port that is found should also be mapped to the HashMap so we can identify the object later.&nbsp; This is helpful because the names listed in the combo box are the actual names of the object (COM1, COM2, etc), and so we can use these names to identify the actual object they are tied to.</p>



<h1 class="wp-block-heading">Connecting to the Serial Port</h1>



<p class="wp-block-paragraph">The method below is for connecting to the serial port once they have been found (see previous section).&nbsp; See How to Open A Serial Port in the Reference Material for more information.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">
    //connect to the selected port in the combo box
    //ports are already found by using the searchForPorts
    //method
    //post: the connected comm port is stored in commPort, otherwise,
    //an exception is generated
    public void connect()
    {
        String selectedPort = (String)window.cboxPorts.getSelectedItem();
        selectedPortIdentifier = (CommPortIdentifier)portMap.get(selectedPort);

        CommPort commPort = null;

        try
        {
            //the method below returns an object of type CommPort
            commPort = selectedPortIdentifier.open("TigerControlPanel", TIMEOUT);
            //the CommPort object can be casted to a SerialPort object
            serialPort = (SerialPort)commPort;

            //for controlling GUI elements
            setConnected(true);

            //logging
            logText = selectedPort + " opened successfully.";
            window.txtLog.setForeground(Color.black);
            window.txtLog.append(logText + "n");

            //CODE ON SETTING BAUD RATE ETC OMITTED
            //XBEE PAIR ASSUMED TO HAVE SAME SETTINGS ALREADY

            //enables the controls on the GUI if a successful connection is made
            window.keybindingController.toggleControls();
        }
        catch (PortInUseException e)
        {
            logText = selectedPort + " is in use. (" + e.toString() + ")";

            window.txtLog.setForeground(Color.RED);
            window.txtLog.append(logText + "n");
        }
        catch (Exception e)
        {
            logText = "Failed to open " + selectedPort + "(" + e.toString() + ")";
            window.txtLog.append(logText + "n");
            window.txtLog.setForeground(Color.RED);
        }
    }</code></pre>



<p class="wp-block-paragraph">Using the <em>HashMap</em> we can retrieve the <em>CommPortIdentifier</em> object from the string that was mapped earlier.&nbsp; This is achieved through the <em>HashMap’s</em> <em>get()</em> method.&nbsp; The object must also be casted as a <em>CommPortIdentifier</em> because the <em>get()</em> method has a return type of <em>Object</em>.</p>



<p class="wp-block-paragraph">The <em>setConnected </em>method just changes a boolean flag so that the program can store whether or not it is connected to a serial port or not.</p>



<p class="wp-block-paragraph">The <em>CommPort</em> must also be initialized because the port object will be stored here once a successful connection is made.</p>



<p class="wp-block-paragraph">The main method of interest here is the <em>open()</em> method.&nbsp; This instructs the program to open the port, and this method will return the object for the opened port, which I store in in the previously initialized <em>CommPort </em>object.&nbsp; I then cast this object as a <em>SerialPort</em> and store it as well.&nbsp; This is helpful for accessing the methods and variables specific to the <em>SerialPort</em> class.</p>



<p class="wp-block-paragraph">It should also be noted that the <em>open()</em> method requires the use of a try-catch block.&nbsp; So applying that, I catch two different exceptions.&nbsp; The <em>PortInUseException</em> is what the name says.&nbsp; If the port is in use, then this exception is thrown.&nbsp; The next catch block is just for the generic exceptions that occur.&nbsp; I never came across that during testing, nor do I know how to replicate that.</p>



<p class="wp-block-paragraph">I neglected to include any code for setting the baud rate and other settings on the XBee’s (see Hardware Configuration), because I already set those parameters previously using X-CTU (more on setting up XBee’s here).</p>



<h1 class="wp-block-heading">Initializing the Input and Output Streams</h1>



<p class="wp-block-paragraph">This method is pretty short and is pretty straightforward to read.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //open the input and output streams
    //pre style="font-size: 11px;": an open port
    //post: initialized input and output streams for use to communicate data
    public boolean initIOStream()
    {
        //return value for whether opening the streams is successful or not
        boolean successful = false;

        try {
            //
            input = serialPort.getInputStream();
            output = serialPort.getOutputStream();
            writeData(0, 0);

            successful = true;
            return successful;
        }
        catch (IOException e) {
            logText = "I/O Streams failed to open. (" + e.toString() + ")";
            window.txtLog.setForeground(Color.red);
            window.txtLog.append(logText + "n");
            return successful;
        }
    }</code></pre>



<p class="wp-block-paragraph">The streams are initialized by returning the input and output streams of the open serial port.&nbsp; In order for the serial port object to not be null, it must store the object for the open serial port.</p>



<p class="wp-block-paragraph">The <em>getInputStream()</em> and <em>getOutputStream()</em> methods both require a try-catch block.&nbsp; The important exception to catch here is the <em>IOException</em> to signify whether the streams failed to open or not.&nbsp; For more information see How to Open A Serial Port in the Reference Material.</p>



<p class="wp-block-paragraph">I also call a method called <em>writeData(0, 0)</em>.&nbsp; This is the method that encapsulates the code required to write serial data.&nbsp; More on that later.&nbsp; Right now it is just used to set variables on the microcontroller side to zero.</p>



<h1 class="wp-block-heading">Setting Up Event Listeners to Read Data</h1>



<p class="wp-block-paragraph">Once the port is open, the serial port must know whenever there is data to be read.&nbsp; This approach is event driven rather than by polling.&nbsp; When the event is hit, a special block of code will run.&nbsp; This is advantageous to polling because polling requires constantly asking if data is available.&nbsp; The code for the event driven approach is below.&nbsp; See Event Based Two Way Communication for more information.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //starts the event listener that knows whenever data is available to be read
    //pre style="font-size: 11px;": an open serial port
    //post: an event listener for the serial port that knows when data is received
    public void initListener()
    {
        try
        {
            serialPort.addEventListener(this);
            serialPort.notifyOnDataAvailable(true);
        }
        catch (TooManyListenersException e)
        {
            logText = "Too many listeners. (" + e.toString() + ")";
            window.txtLog.setForeground(Color.red);
            window.txtLog.append(logText + "n");
        }
    }</code></pre>



<p class="wp-block-paragraph">The code here is pretty much the whole reason why this class implements <em>SerialPortEventListener</em>.&nbsp; The parameter for adding the event listener is just the object itself.&nbsp; The base class has a method called <em>serialEvent(event)</em> that should be overridden before the event code will work.&nbsp; Overriding that method defines what happens when the event is hit.</p>



<p class="wp-block-paragraph">The method <em>addEventListener(this)</em> is the event that is always checking for <em>SerialEvents</em>.&nbsp; It isn’t really important to know what the events actually are, just that the one we’re interested in is the one that tells us whenever data is received.&nbsp; Adding the event listener is complemented by the method <em>notifyOnDataAvailable(true)</em>, which definitely helps us achieve what I mentioned previously.</p>



<p class="wp-block-paragraph">This code requires a try-catch box.&nbsp; The exception here is that there may be too many event listeners.&nbsp; I only use one in the code, so this exception should never be hit.</p>



<h1 class="wp-block-heading">Disconnecting from the Serial Port</h1>



<p class="wp-block-paragraph">Once all the communication is completed, the serial port must be disconnected.&nbsp; In some instances, some ports stay stuck open, which isn’t exactly a good thing.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //disconnect the serial port
    //pre style="font-size: 11px;": an open serial port
    //post: closed serial port
    public void disconnect()
    {
        //close the serial port
        try
        {
            writeData(0, 0);

            serialPort.removeEventListener();
            serialPort.close();
            input.close();
            output.close();
            setConnected(false);
            window.keybindingController.toggleControls();

            logText = "Disconnected.";
            window.txtLog.setForeground(Color.red);
            window.txtLog.append(logText + "n");
        }
        catch (Exception e)
        {
            logText = "Failed to close " + serialPort.getName()
                              + "(" + e.toString() + ")";
            window.txtLog.setForeground(Color.red);
            window.txtLog.append(logText + "n");
        }
    }</code></pre>



<p class="wp-block-paragraph">The code here requires a try-catch block so there it is.&nbsp; The exception to catch here is pretty generic.</p>



<p class="wp-block-paragraph">Before closing the port, I reset the data on the microcontroller.&nbsp; That step is optional depending on the application.&nbsp; For example, if the value sent to the microcontroller is controlling the speed of a motor, I’d want the motor to turn off if I turn off the remote control.</p>



<p class="wp-block-paragraph">The event listener should be removed as it is no longer needed.</p>



<p class="wp-block-paragraph">The method to close the port is the <em>close()</em> method.</p>



<p class="wp-block-paragraph">The input and output streams should also be closed via the same method as above.</p>



<p class="wp-block-paragraph">See How to Close A Serial Port in the Reference section for more information.</p>



<h1 class="wp-block-heading">Reading Data – The <em>serialEvent</em> Method</h1>



<p class="wp-block-paragraph">This is a follow-up to the section on preparing to Read Data.&nbsp; It has information on how to process the data that the program reads.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //what happens when data is received
    //pre style="font-size: 11px;": serial event is triggered
    //post: processing on the data it reads
    public void serialEvent(SerialPortEvent evt) {
        if (evt.getEventType() == SerialPortEvent.DATA_AVAILABLE)
        {
            try
            {
                byte singleData = (byte)input.read();

                if (singleData != NEW_LINE_ASCII)
                {
                    logText = new String(new byte[] {singleData});
                    window.txtLog.append(logText);
                }
                else
                {
                    window.txtLog.append("n");
                }
            }
            catch (Exception e)
            {
                logText = "Failed to read data. (" + e.toString() + ")";
                window.txtLog.setForeground(Color.red);
                window.txtLog.append(logText + "n");
            }
        }
    }</code></pre>



<p class="wp-block-paragraph">Since we only want to read data if it exists, we test the condition in the if statement above.&nbsp; This could be redundant because we wouldn’t be in this method if the event never got triggered.</p>



<p class="wp-block-paragraph">Reading the data requires a try-catch block.&nbsp; The <em>read()</em> method returns an integer, but the value in it is actually a byte value so this is casted to a byte, in which I store in a variable called <em>singleData</em>.&nbsp; When I was testing this code before, I noticed that the data being read would always have random new line characters in it, and I never knew why this happened.&nbsp; I never wrote any new line characters.&nbsp; Since I don’t want these, I add an if condition saying that if it encounters that, don’t display that data on the screen.</p>



<p class="wp-block-paragraph">Java also has a nice way of converting bytes to a string.  A byte array can be used as a parameter when initializing a string, which is what I’ve done when I assign a value to <em>logText</em>.</p>



<p class="wp-block-paragraph">The exception here is just the usual generic one.</p>



<h1 class="wp-block-heading">Writing Data</h1>



<p class="wp-block-paragraph">Here is the method for writing data.&nbsp; In my application, I am writing two integers sequentially to my microcontroller.&nbsp; Data that is sent to the MCU can be used for such things such as controlling motor speeds, which is what I am trying to do here.&nbsp; I hope to use the data sent do control the PWM duty cycle of the motor for speed control.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //method that can be called to send data
    //pre style="font-size: 11px;": open serial port
    //post: data sent to the other device
    public void writeData(int leftThrottle, int rightThrottle)
    {
        try
        {
            output.write(leftThrottle);
            output.flush();
            //this is a delimiter for the data
            output.write(DASH_ASCII);
            output.flush();

            output.write(rightThrottle);
            output.flush();
            //will be read as a byte so it is a space key
            output.write(SPACE_ASCII);
            output.flush();
        }
        catch (Exception e)
        {
            logText = "Failed to write data. (" + e.toString() + ")";
            window.txtLog.setForeground(Color.red);
            window.txtLog.append(logText + "n");
        }
    }</code></pre>



<p class="wp-block-paragraph">The <em>write() </em>method here requires a try-catch block just like many of the other methods used for serial communication.&nbsp; Using the output stream, I call that method to write an integer value.&nbsp; I also write a dash and a space to separate the actual data being read.&nbsp; See the ASCII Table for the values of what these characters should be.&nbsp; This helps me differentiate the sets of data that is sent back and forth.&nbsp; The dash separates the two integers being sent and the space separates the entire set.&nbsp; On the Arduino end, four called to <em>read()</em> can separate the data without mixing things up.&nbsp; Example of that later.</p>



<h1 class="wp-block-heading">Putting All the Java Code Together</h1>



<p class="wp-block-paragraph">Once all these methods are setup, they need to be called somewhere in the program so we can put them to use.&nbsp; When the program starts, the code for searching for serial ports will run so that it can populate the combo box on the GUI.&nbsp; The GUI buttons also need to be disabled to reflect the fact they should be disabled when there is no connection to a port.&nbsp; When the connect button is pressed, the input and output streams are started and the event listener is added.&nbsp; The code for that is shown below.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">        private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {
            communicator.connect();
            if (communicator.getConnected() == true)
            {
                if (communicator.initIOStream() == true)
                {
                    communicator.initListener();
                }
            }
        }</code></pre>



<p class="wp-block-paragraph">The if statement is needed such that the code will not run if a successful connection was not made.&nbsp; This is the precondition for the <em>initIOStream() </em>and the <em>initLIstener() </em>methods.</p>



<p class="wp-block-paragraph">When the user decides to disconnect from the serial port, the user only needs to call the <em>disconnect()</em> method when the disconnect button is pressed.</p>



<p class="wp-block-paragraph">The up/down arrows on my GUI are set to write data to the serial port when they are pressed.&nbsp; When data is written to the Arduino, the MCU will send the data back to the Java program, which will signal the event listener to display that data back to the screen.</p>



<h1 class="wp-block-heading">Arduino Code</h1>



<p class="wp-block-paragraph">The Arduino code is pretty straight forward.&nbsp; There are just a few calls to the <em>read()</em> method.</p>



<p class="wp-block-paragraph">Update 6 May 2012: the syntax for the Arduino code has updated since the writing of this article. &nbsp;Apparently, the lines</p>



<pre class="wp-block-code"><code lang="c" class="language-c">Serial.print(separator, BYTE);
Serial.print(space, BYTE);</code></pre>



<p class="wp-block-paragraph">are no longer valid and have since been replaced by the following:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">Serial.write(byte(separator));
Serial.write(byte(space));</code></pre>



<p class="wp-block-paragraph">The code below hasn&#8217;t been edited with this change, but basically the code required for writing a byte value through serial communication has changed.</p>



<pre class="wp-block-code"><code lang="c" class="language-c">
// this is where we will put our data
int left = 0;
int right = 0;
byte space = 0;
byte separator = 0;

void setup(){
  // Start up our serial port, we configured our XBEE devices for 38400 bps. 
  Serial.begin(9200);
}

void loop(){
  // handle serial data, if any
  if (Serial.available() &amp;gt;= 4){
    left = Serial.read();
    separator = Serial.read();
    right = Serial.read();
    space = Serial.read();
    Serial.flush();

    Serial.print(left);
    Serial.print(separator, BYTE);
    Serial.print(right);
    Serial.print(space, BYTE);
    Serial.print("n");
  }
}</code></pre>



<p class="wp-block-paragraph">I first declare four variables to reflect the fact that I’m writing four different variables to the serial port.</p>



<p class="wp-block-paragraph">In the loop method, I added a condition which will check whether there are four pieces of data available before reading them.&nbsp; This again reflects the fact I’m writing four values.</p>



<p class="wp-block-paragraph">The four variables initially declared store the values in the order that they are written, and then are just printed to the screen.</p>



<p class="wp-block-paragraph">The <em>print()</em> method is able to convert the byte value to an actual character by adding a second parameter called <em>BYTE</em>.&nbsp; The left and right variables don’t need it because the values written were integers to begin with, however, the dash and space characters were written as ASCII values.</p>



<p class="wp-block-paragraph">For more information about Arduino and Java, and Arduino’s Serial library, please refer to those in the Reference Section.</p>



<h1 class="wp-block-heading">Code Downloads</h1>



<p class="wp-block-paragraph">Here are the code downloads for the GUI, key bindings and the serial communication.&nbsp; WordPress doesn’t allow uploads of zip or java files so I uploaded it all to Megaupload.</p>



<p class="wp-block-paragraph">Link to download:&nbsp;<a href="http://www.mediafire.com/?z2l26ncypmzn20z" target="_blank" rel="noopener">http://www.mediafire.com/?z2l26ncypmzn20z</a></p>



<h1 class="wp-block-heading">Other Examples</h1>



<p class="wp-block-paragraph">There are also other sites I looked at which had example code for serial port communication in Java.&nbsp; The sites are Programming Serial and Parallel Ports and Serial Port Access Using RXTX in Java, which are both in the Reference section.</p>



<h1 class="wp-block-heading">Reference Material</h1>



<p class="wp-block-paragraph">Below are a bunch of links to reference sites that I used to find some of the information written here.&nbsp; I mostly referred to bits and pieces of each article to understand the serial code and to come up with the example I present here.&nbsp; The list is in the order that I referenced them.</p>



<h2 class="wp-block-heading">Discovering Available Comm Ports</h2>



<p class="wp-block-paragraph"><a href="http://rxtx.qbang.org/wiki/index.php/Discovering_available_comm_ports" target="_blank" rel="noopener">http://rxtx.qbang.org/wiki/index.php/Discovering_available_comm_ports</a></p>



<p class="wp-block-paragraph">The code on this page is pretty specific to the title of this heading, and the code is pretty easy to follow.</p>



<h2 class="wp-block-heading">How to Open A Serial Port</h2>



<p class="wp-block-paragraph"><a target="_blank" rel="noopener">http://embeddedfreak.wordpress.com/2008/08/08/how-to-open-serial-port-using-rxtx/</a></p>



<p class="wp-block-paragraph">This page provides a very concise and detailed explanation on what each line of code does in order to get a serial port open.&nbsp; Definitely work a look if you’re trying to understand the code.</p>



<h2 class="wp-block-heading">Event Based Two Way Communication</h2>



<p class="wp-block-paragraph"><a href="http://rxtx.qbang.org/wiki/index.php/Event_Based_Two_Way_Communication" target="_blank" rel="noopener">http://rxtx.qbang.org/wiki/index.php/Event_Based_Two_Way_Communication</a></p>



<p class="wp-block-paragraph">This page has example code on how to connect to a serial port and how to interact with it.&nbsp; The code here uses events, rather than polling, to send data back and forth, which means that whenever data is received, the event code is triggered.</p>



<h2 class="wp-block-heading">How to Close A Serial Port</h2>



<p class="wp-block-paragraph"><a target="_blank" rel="noopener">http://embeddedfreak.wordpress.com/2008/08/08/how-to-close-serial-port-in-rxtx/</a></p>



<p class="wp-block-paragraph">This article is written by the same author who wrote the article on how to open serial ports.  Good example code here.</p>



<h2 class="wp-block-heading">ASCII Table</h2>



<p class="wp-block-paragraph"><a href="http://www.asciitable.com/" target="_blank" rel="noopener">http://www.asciitable.com/</a></p>



<p class="wp-block-paragraph">Having the ASCII Table is quite handy for serial data because data being sent and written are bytes, so being able to know what byte values correspond to what character really helps.</p>



<h2 class="wp-block-heading">Arduino and Java</h2>



<p class="wp-block-paragraph"><a href="http://www.arduino.cc/playground/Interfacing/Java" target="_blank" rel="noopener">http://www.arduino.cc/playground/Interfacing/Java</a></p>



<p class="wp-block-paragraph">This article discusses how to use the serial port communication with Java and Arduino, which is exactly what I am after.&nbsp; It has example code on pretty much the entire process of serial port communication, but it may be too much to read since there is little explanation about the code.</p>



<h2 class="wp-block-heading">Arduino Serial Class</h2>



<p class="wp-block-paragraph"><a href="http://arduino.cc/en/Reference/Serial" target="_blank" rel="noopener">http://arduino.cc/en/Reference/Serial</a></p>



<p class="wp-block-paragraph">A good reference for Arduino’s Serial class methods.&nbsp; Also has example code to look at.</p>



<h2 class="wp-block-heading">Programming Serial and Parallel Ports</h2>



<figure class="wp-block-embed is-type-rich is-provider-embed-handler wp-block-embed-embed-handler"><div class="wp-block-embed__wrapper">
https://docs.google.com/viewer?url=http%3A%2F%2Fjava.sun.com%2Fdeveloper%2FBooks%2Fjavaprogramming%2Fcookbook%2F11.pdf
</div></figure>



<p class="wp-block-paragraph">This article provides a brief introduction to programming serial ports and has information on the steps required to talk to the serial port.&nbsp; However, the code examples in there may be hard to follow for someone new to serial programming.</p>



<h2 class="wp-block-heading">Serial Port Access Using RXTX in Java</h2>



<p class="wp-block-paragraph"><a href="http://gomultidomain.blogspot.com/2008/06/serial-port-access-using-rxtx-in-java.html" target="_blank" rel="noopener">http://gomultidomain.blogspot.com/2008/06/serial-port-access-using-rxtx-in-java.html</a></p>



<p class="wp-block-paragraph">This page also has complete code for serial communication in Java, but what I was looking for here was how to use the write method to send serial data from Java.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.henrypoon.com/blog/2011/01/01/serial-communication-in-java-with-example-program/feed/</wfw:commentRss>
			<slash:comments>144</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">566</post-id>	</item>
		<item>
		<title>UnrealScript Language Reference</title>
		<link>https://blog.henrypoon.com/blog/2010/05/14/unrealscript-language-reference/</link>
					<comments>https://blog.henrypoon.com/blog/2010/05/14/unrealscript-language-reference/#respond</comments>
		
		<dc:creator><![CDATA[hp]]></dc:creator>
		<pubDate>Fri, 14 May 2010 22:27:10 +0000</pubDate>
				<category><![CDATA[computer stuff]]></category>
		<category><![CDATA[engineering]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Computer languages]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[D]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Go]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Inventory]]></category>
		<category><![CDATA[It]]></category>
		<category><![CDATA[Language]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[Pawn]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Programming languages]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[Technical communication]]></category>
		<category><![CDATA[Thou]]></category>
		<category><![CDATA[Unreal]]></category>
		<category><![CDATA[UnrealScript]]></category>
		<guid isPermaLink="false">http://henrypoon.mooo.com/blog/unrealscript-language-reference</guid>

					<description><![CDATA[From the article: &#8220;This is a technical document describing the UnrealScript language. It&#8217;s not a tutorial, nor does it provide detailed examples of useful UnrealScript code. For examples of UnrealScript the reader is referred to the source code of the engine, which provides tens of thousands of lines of working UnrealScript code which solves many [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">From the article:</p>



<p class="wp-block-paragraph">&#8220;This is a technical document describing the UnrealScript language. It&#8217;s not a tutorial, nor does it provide detailed examples of useful UnrealScript code. For examples of UnrealScript the reader is referred to the source code of the engine, which provides tens of thousands of lines of working UnrealScript code which solves many problems such as AI, movement, inventory, and triggers. A good way to get started is by looking at the &#8220;Actor&#8221;, &#8220;Object&#8221;, &#8220;Controller&#8221;, &#8220;Pawn&#8221;, and &#8220;Weapon&#8221; scripts.&#8221;</p>



<p class="wp-block-paragraph"><a href="http://udn.epicgames.com/Three/UnrealScriptReference.html" target="_blank" rel="noreferrer noopener">http://udn.epicgames.com/Three/UnrealScriptReference.html</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.henrypoon.com/blog/2010/05/14/unrealscript-language-reference/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">333</post-id>	</item>
		<item>
		<title>Description of C++ Keywords</title>
		<link>https://blog.henrypoon.com/blog/2010/01/18/description-of-c-keywords/</link>
					<comments>https://blog.henrypoon.com/blog/2010/01/18/description-of-c-keywords/#comments</comments>
		
		<dc:creator><![CDATA[hp]]></dc:creator>
		<pubDate>Tue, 19 Jan 2010 04:44:44 +0000</pubDate>
				<category><![CDATA[computer stuff]]></category>
		<category><![CDATA[9]]></category>
		<category><![CDATA[Assembly language]]></category>
		<category><![CDATA[British Columbia]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[C++ classes]]></category>
		<category><![CDATA[Chan]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Compilers]]></category>
		<category><![CDATA[Computer languages]]></category>
		<category><![CDATA[Const]]></category>
		<category><![CDATA[D]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Dia]]></category>
		<category><![CDATA[EAR]]></category>
		<category><![CDATA[Go]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[IME]]></category>
		<category><![CDATA[ise]]></category>
		<category><![CDATA[It]]></category>
		<category><![CDATA[Language]]></category>
		<category><![CDATA[Lie]]></category>
		<category><![CDATA[Monday]]></category>
		<category><![CDATA[Nature]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Outside]]></category>
		<category><![CDATA[Over]]></category>
		<category><![CDATA[Parameter]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[Programming languages]]></category>
		<category><![CDATA[RAR]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[Run]]></category>
		<category><![CDATA[Scope]]></category>
		<category><![CDATA[Sizeof]]></category>
		<category><![CDATA[Speed]]></category>
		<category><![CDATA[STR]]></category>
		<category><![CDATA[Struct]]></category>
		<category><![CDATA[Sunday]]></category>
		<category><![CDATA[Template]]></category>
		<category><![CDATA[Thou]]></category>
		<category><![CDATA[Time]]></category>
		<category><![CDATA[Typedef]]></category>
		<category><![CDATA[Typename]]></category>
		<category><![CDATA[UNC]]></category>
		<category><![CDATA[University of British Columbia]]></category>
		<category><![CDATA[Variable]]></category>
		<category><![CDATA[Virtual function]]></category>
		<category><![CDATA[Vol]]></category>
		<category><![CDATA[Week]]></category>
		<category><![CDATA[Words]]></category>
		<category><![CDATA[ypres]]></category>
		<category><![CDATA[Z]]></category>
		<guid isPermaLink="false">http://henrypoon.mooo.com/blog/description-of-c-keywords</guid>

					<description><![CDATA[Source: The University of British Columbia asm (seldom used) Used to insert assembly language commands directly into the code. This function is very tricky to use even for professional programmers and can cause portability issues. asm(&#8220;instruction&#8221;); auto Used to declare local variables but is purely optional. auto int i = 5; The previous declaration thus [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Source: The University of British Columbia</p>
<p><strong><code>asm</code></strong> (seldom used)</p>
<ul>
<li>Used to insert assembly language commands directly into the code. This function      is very tricky to use even for professional programmers and can cause portability      issues.<br />
<blockquote><p>asm(&#8220;instruction&#8221;);</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="auto"></a>auto</code></strong></p>
<ul>
<li>Used to declare local variables but is purely optional.<br />
<blockquote><p>auto int i = 5;</p></blockquote>
<p>The previous declaration thus has identical meaning to the following declaration.</p>
<blockquote><p>int i = 5;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="bool"></a>bool</code></strong> (C++ only)</p>
<ul>
<li>Used to declare a Boolean logic variable; a variable that can have the value      true or false. This variable type      is normally 8 bits (1 byte) long.<br />
<blockquote><p>bool t = true;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="break"></a>break</code></strong></p>
<ul>
<li>Used to break out of a loop independant of the loop condition. Also, used      to finish a switch statement, keeping the program from      &#8220;falling through&#8221; to the next case in the code.<br />
<blockquote>
<pre>while(x &lt; 100)
{
    if(x &lt; 0)
         break;
    cout &lt;&lt; x &lt;&lt; endl;
    x++;
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="case"></a>case</code></strong></p>
<ul>
<li>Used as a label to declare a single test in a switch statement.<br />
<blockquote>
<pre>case 1: command1;
        command2;
        break;
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="catch"></a>catch</code></strong> (C++ only)</p>
<ul>
<li>Used to handle exceptions generated by a throw statement.<br />
<blockquote>
<pre>catch(const char* e)
{
    //handle exception
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="char"></a>char</code></strong></p>
<ul>
<li>Used to declare character variables. This variable type is normally 8 bits      (1 byte) long.<br />
<blockquote><p>char c = &#8216;h&#8217;;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="class"></a>class</code></strong> (C++ only)</p>
<ul>
<li>Used to define a new class. Members of the class are private by default unless listed under the protected or public labels.<br />
<blockquote>
<pre>class class-name : inheritance-list
{
    public:
        public-members-list;
    protected:
        protected-members-list;
    private:
        private-members-list;
} object-list;
</pre>
</blockquote>
<ul>
<li>class-name is the name of the class that is being created.</li>
<li>inheritance-list is the optional list of classes inherited by the new          class.</li>
<li>public-members-list is the list of public members          of the class.</li>
<li>protected-members-list is the list of protected members of the class.</li>
<li>private-members-list is the list of private members          of the class.</li>
<li>object-list is an optional list used to immediately instantiate 1 or          more instances of the class.</li>
</ul>
<blockquote>
<pre>class Date
{
public:
    void display();

private:
    int day;
    int month;
    int year;
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="const"></a>const</code></strong> (C++ only)</p>
<ul>
<li>Used to tell the compiler that a certain object should not be modified once      it has been initialized.<br />
<blockquote><p>const int i = 5;</p></blockquote>
</li>
<li>Used to declare a pointer so that the value of the pointer (the memory     location to which it points)     <span style="text-decoration:underline;">can</span> be modified, but the data in the memory location <span style="text-decoration:underline;">cannot</span> be changed.<br />
<blockquote><p>const int* j = new int(3);</p></blockquote>
</li>
<li>Used to declare a pointer so the that value of the pointer (the memory     location to which it points)     <span style="text-decoration:underline;">cannot</span> be modified, but the data in that memory location <span style="text-decoration:underline;">can</span> be changed.<br />
<blockquote><p>int* const j = new int(3);</p></blockquote>
</li>
<li>Used to declare a member function that does not modify the object&#8217;s state,      meaning that it should be used for methods like print so that data in the     object cannot      be changed accidentally. If and attempt is made     to modify the object in any way, a compilation error will be triggered.<br />
<blockquote><p>void print(bool verbose) const;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="const_cast"></a>const_cast</code></strong> (C++ only, seldom used)</p>
<ul>
<li>Used to remove the const protection on a variable as      long as the original variable was not declared as a const.      The target type must be the same as the original type.<br />
<blockquote><p>const_cast&lt;target_type&gt; (object);</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="continue"></a>continue</code></strong></p>
<ul>
<li>Used to jump to the next iteration of a loop. The following example will      print out all of the numbers from 1 to 20 except for 10.<br />
<blockquote>
<pre>for(int i = 0; i &lt; 21; i++)
{
    if(i == 10)
        continue;
    cout &lt;&lt; i &lt;&lt; endl;
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="default"></a>default</code></strong></p>
<ul>
<li>Used as a label to declare the default case of a switch statement.<br />
<blockquote>
<pre>case 1:  command1;
         command2;
         break;

default: command1;
         command2;
         break;
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="delete"></a>delete</code></strong> (C++ only)</p>
<ul>
<li>Used to free memory allocated for a pointer back to the heap. The argument      should have been allocated through a call to new. To delete      an array, use the following form of delete: delete[]<br />
<blockquote>
<pre>delete p;
delete[] pArray;</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="do"></a>do</code></strong></p>
<ul>
<li>Used to create a loop that is executed at least once. The terminating condition      is tested at the end of the loop.<br />
<blockquote>
<pre>do
{
    cout &lt;&lt; "hello worldn";
    i++;
} while(i &lt; 5)
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="double"></a>double</code></strong></p>
<ul>
<li>Used to declare a double-precision floating-point type variable. This variable      type is normally 64 bits (8 bytes) long.<br />
<blockquote><p>double d = 12.55;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="dynamic_cast"></a>dynamic_cast</code></strong> (C++ only, seldom used)</p>
<ul>
<li>Used to cast from one type to another with a check performed at runtime.      If the cast types are incompatible, NULL is returned.<br />
<blockquote><p>dynamic_cast&lt;target_type&gt; (object);</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="else"></a>else</code></strong></p>
<ul>
<li>Used for an alternative condition in an if statement.<br />
<blockquote>
<pre>if(i == 1)
{
    // do something
}
else
{
    // do something else
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="enum"></a>enum</code></strong></p>
<ul>
<li>Used to define an enumerated type. Each of the names in the name-list are      given a distinct value. This should be used in place of defining variables      using &#8220;magic numbers&#8221; (eg. int Monday = 0, int Tuesday = 1, etc).<br />
<blockquote>
<pre>enum name {name-list};</pre>
</blockquote>
<ul>
<li>name is the name of the enumerated type that was created</li>
<li>name-list is the list of names of the elements</li>
</ul>
<blockquote>
<pre>enum weekdays {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="explicit"></a>explicit</code></strong> (C++ only)</p>
<ul>
<li>Used to make sure that a constructoor is only used for the creation of new      values and not used for the implicit conversion between two different types.      It will only be be used if the initialization exactly matches the call to      that constructor. This keyword is only needed with one-argument constructors.<br />
<blockquote>
<pre>class vector
{
    ...
    explicit vector(int v);
    ...
}
</pre>
</blockquote>
<p>Using this keyword, some mysterious errors can be caught by the compiler like      the following:</p>
<blockquote>
<pre>vector&lt;int&gt; v(10);
v = 5; // error, meant to write v[0] = 5
</pre>
</blockquote>
<p>The problem in this code if the explicit keyword was not specified is that      the v = 5 statement would invoke the constructor, creating a new vector of      size 5 and destroying the old one.</li>
</ul>
<hr>
<p><strong><code><a name="export"></a>export</code></strong> (C++ only, seldom used)</p>
<ul>
<li>Used to export a template to other modules. Most compilers require template      definitions to be explicitly specified in the header file since the Comeau      C++ compiler seems to be the only compiler that supports this keyword.<br />
<blockquote>
<pre>// In MyTemplateFunction.h
template
void myTemplateFunction(const T &amp;t1);

// In MyTemplateFunction.cpp
export template
void myTemplateFunction(const T &amp;t1)
{
    ...
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="extern"></a>extern</code></strong></p>
<ul>
<li>Used to inform the compiler of variables and functions that are defined      outside of the current scope or module. Variables defined as extern will not      have space allocated for them since they are defined elsewhere.<br />
<blockquote><p>extern char* message;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="false"></a>false</code></strong> (C++ only)</p>
<ul>
<li>Used to represent the Boolean value false.<br />
<blockquote><p>bool b = false;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="float"></a>float</code></strong></p>
<ul>
<li>Used to declare a single-precision floating-point type variable. This variable&lt;br&gt;      type is normally 32 bits (4 bytes) long.<br />
<blockquote><p>float f = 3.5;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="for"></a>for</code></strong></p>
<ul>
<li>Used to create a loop that is meant to initialize, test and update a variable.<br />
<blockquote>
<pre>for(int i = 0; i &lt; 10; i++)
{
    cout &lt;&lt; "i is " &lt;&lt; i &lt;&lt; endl;
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="friend"></a>friend</code></strong> (C++ only)</p>
<ul>
<li>Used to allow another class or function to have access      to the private features of that class.<br />
<blockquote>
<pre>friend void print(bool verbose);
friend class Vector;</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="goto"></a>goto</code></strong> (seldom used)</p>
<ul>
<li>Used to jump to another location in a function specified by a label. This      is generally considered harmful and should not be used unless necessary.<br />
<blockquote>
<pre>goto labelA;
...
labelA:</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="if"></a>if</code></strong></p>
<ul>
<li>Used to create a conditional branch statement so that different code can      be executed under different conditions. The conditions are evaluated in the      order that they appear in the code.<br />
<blockquote>
<pre>if (i &lt; 0)
{
    cout &lt;&lt; "i is negative";
}
else if(i == 0)
{
    cout &lt;&lt; "i is 0n";
}
else
{
    cout &lt;&lt; "i is posativen";
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="inline"></a>inline</code></strong> (C++ only)</p>
<ul>
<li>Used to tell the compiler that the function an its body are inserted into      the calling code meaning that it has to expand the function in-place instead      of just insert a call to the function. Functions that have static data, loops, switches or recursive calls cannot be inlined.<br />
<blockquote>
<pre>inline int test(int A)
{
    ...
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="int"></a>int</code></strong></p>
<ul>
<li>Used to declare an integer type variable. This variable type is normally        32 bits (4 bytes) long.<br />
<blockquote><p>int i = 3;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="long"></a>long</code></strong></p>
<ul>
<li>Used as a data type modifier for the int and double types to indicate that      they may have more bytes then the type has available. This variable type is      normally 32 or 64 bits (4 or 8 bytes) long.<br />
<blockquote><p>long int i = 100000;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="mutable"></a>mutable</code></strong> (C++ only)</p>
<ul>
<li>Used to specify that it is a data field that can be modified even if another      part of the data is declared const.</li>
</ul>
<hr>
<p><strong><code><a name="namespace"></a>namespace</code></strong> (C++ only)</p>
<ul>
<li>Used to create a new scope. Once created, the namespace must be refered      to either directly or with the using keyword.<br />
<blockquote>
<pre>   namespace CartoonNameSpace
    {
        int HomersAge;

        void incrementHomersAge()
        {
            HomersAge++;
        }
    }
    int main() {
        ...
        CartoonNameSpace::HomersAge = 39;
        CartoonNameSpace::incrementHomersAge();
        cout &lt;&lt; CartoonNameSpace::HomersAge &lt;&lt; endl;
        ...
    }
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="new"></a>new</code></strong> (C++ only)</p>
<ul>
<li>Used to allocate a new block of memory for the given type from the heap,      and return a pointer to that block of memory. Allocating arrays can be done      by providing the size of the array in square brackets.<br />
<blockquote>
<pre>pointer = new type;
pointer = new type( initializer );
pointer = new type[size];</pre>
</blockquote>
<ul>
<li>pointer is a pointer to the type that you want to allocate the memory          for</li>
<li>type is the type of the item that is to be stored in the memory that          is allocated</li>
<li>initializer is the optional information for the constructor</li>
<li>size is the size of the array to create</li>
</ul>
</li>
</ul>
<hr>
<p><strong><code><a name="operator"></a>operator</code></strong> (C++ only)</p>
<ul>
<li>Used to specify that you are overloading an operator.<br />
<blockquote>
<pre>   return-type class-name::operator#(parameter-list)
    {
        ...
    }
</pre>
</blockquote>
<ul>
<li>return-type is the return type for the function</li>
<li>class-name is the name of the class that the operator is a part of.          If it is not part of a class, this can be left out along with the &#8216;<strong>::</strong>&#8216;<strong>.</strong></li>
<li># is the operator that is to be overloaded, such as &#8216;++&#8217;. You cannot          overload the #, ##, ., :, .*, or ? tokens.</li>
<li>parameter-list is the list of parameters that the operator will take.          For unary operators, parameter-list should be empty, and for binary operators,          parameter-list should contain the operand on the right side of the operator          (the operand on the left side is passed as this).</li>
</ul>
</li>
<li>There are special conventions for some operators, such as the unary       ++ and &#8212; operators.
<ul>
<li> The unary ++ operator has both prefix (<code>++object</code> and postfix (<code>object++</code>) versions.</li>
<li>
<blockquote>
<pre>   return-type class-name::operator++()
    {
        ...
    }
</pre>
</blockquote>
<p>overloads the prefix version (the value returned is the        value of the object <span style="text-decoration:underline;">after</span> it is incremented, so this        is also known as the pre-increment version because the        increment takes place <span style="text-decoration:underline;">before</span> the value is returned). There is        no parameter specified because ++ is a unary operator.</li>
<li>
<blockquote>
<pre>   return-type class-name::operator++( int )
    {
        ...
    }
</pre>
</blockquote>
<p>overloads the postfix version (the value returned is the        value of the object <span style="text-decoration:underline;">before</span> it is incremented, so this        is also known as the post-increment version because the        increment takes place <span style="text-decoration:underline;">after</span> the value is returned). The parameter        <code>int</code> is not really a parameter (++ is still a unary        operator) but is there soley to differentiate the prefix and        postfix versions.</li>
</ul>
</li>
</ul>
<hr>
<p><strong><code><a name="private"></a>private</code></strong> (C++ only)</p>
<ul>
<li>Used within a class declaration to specify features of that class that can      only be accessed by itself and its friends.<br />
<blockquote>
<pre>class Date
{
public:
    void display();

private:
    int day;
    int month;
    int year;
}</pre>
</blockquote>
</li>
<li>Used to inherit a base class privately, which causes all public and protected members of the base class to become      private members of the derived class.<br />
<blockquote>
<pre>class AlarmClock : private Clock
{
public:
    void display();

}</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="protected"></a>protected</code></strong> (C++ only)</p>
<ul>
<li>Used within a class declaration to specify features of that class that are      private to its own class, but can be inherited by a      derived class.<br />
<blockquote>
<pre>class Date
{
public:
    void display();
protected:
    int day;
    int month;
    int year;
}</pre>
</blockquote>
</li>
<li>Used to inherit a base class, which causes all public and protected members of the base class to become      protected members of the derived class.<br />
<blockquote>
<pre>class AlarmClock : protected Clock
{
public:
    void display()
}</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="public"></a>public</code></strong> (C++ only)</p>
<ul>
<li>Used within a class declaration to specify features of that class that are      accessable to everyone.<br />
<blockquote>
<pre>class Date
{
public:
    void display();
protected:
    int day;
    int month;
    int year;
}</pre>
</blockquote>
</li>
<li>Used to inherit a base class publically, which causes all public and protected members of the base class to become public and protected members of the derived class.<br />
<blockquote>
<pre>class AlarmClock : public Clock
{
public:
    void display()
}</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="register"></a>register</code></strong></p>
<ul>
<li>Used to reccommend that a varibale be placed into a processor register so      that it is optimized for speed but the compiler is not obliged to do so. This      keyword is rarely used anymore since compilers have become better than programmers      at optimizing code.</li>
</ul>
<hr>
<p><strong><code><a name="reinterpret_cast"></a>reinterpret_cast</code></strong> (C++ only), seldom used</p>
<ul>
<li>Used to change one data type in a non-portable way. It is normally used      to cast between incompatible pointer types.<br />
<blockquote><p>reinterpret_cast&lt;target_type&gt; (object);</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="return"></a>return</code></strong></p>
<ul>
<li>Used to cause the execution to jump from the current function back to the      one that called it. An optional value can be returned but the function must      specify the type that it will return.<br />
<blockquote>
<pre>return;
return 5;</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="short"></a>short</code></strong></p>
<ul>
<li>Used as a data type modifier for the int type to indicate that there may      be less bytes then the type has available. This variable type is normally      16or 32bits (2 or 4bytes) long.<br />
<blockquote><p>short int i = 5;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="signed"></a>signed</code></strong></p>
<ul>
<li>Used to specify that the number type provided could potentially be negative,      so it must be stored in a different format. This is the default representation      that is chosen by most compilers if either signed or unsigned is not specified.<br />
<blockquote><p>signed int i = -12;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="sizeof"></a>sizeof</code></strong></p>
<ul>
<li>Used to return the size of the object (in bytes) that is passed to it.<br />
<blockquote>
<pre>int i = 5;
int size = sizeof( i );</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="static"></a>static</code></strong></p>
<ul>
<li>Used outside any function or class as a qualifier to a variable declaration      makes the scope of the variable the file in which the variable is declared,      and the extent is permanent (i.e., it is in the static segment).<br />
<blockquote><p>static int i;</p></blockquote>
</li>
<li>Used inside a function as a qualifier to a variable declaration makes the        scope of the variable the function in which the variable is declared, and        the extent is permanent (i.e., it is in the static segment).<br />
<blockquote>
<pre>void foo()
{
    static int i;
}</pre>
</blockquote>
</li>
<li>Used inside a class as a qualifier to a variable declaration makes the        scope of the variable the class in which the variable is declared, and the        extent is permanent (i.e., it is in the static segment).<br />
<blockquote>
<pre>class bar
{
    static int i;
}</pre>
</blockquote>
</li>
<li>Used outside any class as a qualifier to a function declaration makes the        scope of the function the file in which the function is declared. As with        all functions, the instructions for the function are in the code segment.<br />
<blockquote>
<pre>static void foo()
{
}</pre>
</blockquote>
</li>
<li>Used inside a class as a qualifier to a function (method) declaration makes        the scope of the function the class in which the function is declared (as        with all methods), and the instructions for the method are in the code       segment (as for all functions). What is different is that a static method       is invoked without requiring an object, using the qualifier syntax       <code>class::staticMethod( <em>parameters</em> )</code>, although it can       also be invoked on an object in the class in the usual way. Because no       object is associated with a static method, only static member variables       and other static member functions can be invoked by a static method.<br />
<blockquote>
<pre>class bar
{
    static void foo();
}</pre>
</blockquote>
<p><strong>Note:</strong> A method in a class cannot be both &#8220;static&#8221;        and &#8220;virtual&#8221;. The reason for this is       that virtual functions have to know the object to which they apply       (because of polymorphism) but static methods are not applied to an       object.</li>
</ul>
<hr>
<p><strong><code><a name="static_cast"></a>static_cast</code></strong> (C++ only, seldom used)</p>
<ul>
<li>Used for a normal conversion between types. No runtime checking is performed.<br />
<blockquote><p>static_cast&lt;target_type&gt; (object);</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="struct"></a>struct</code></strong></p>
<ul>
<li>Used to create a structure like a class, but the members      are public by default instead of private.      In C, structs can only contain data, cannot have inheritance and cannot have      data with different visibilities.<br />
<blockquote>
<pre>struct struct-name : inheritance-list
{
        public-members-list;
    protected:
        protected-members-list;
    private:
        private-members-list;
} object-list;</pre>
</blockquote>
<ul>
<li>struct-name is the name of the struct that is being created.</li>
<li>inheritance-list is the optional list of structs inherited by the new          struct.</li>
<li>public-members-list is the list of public members          of the struct.</li>
<li>protected-members-list is the list of protected members of the struct.</li>
<li>private-members-list is the list of private members          of the struct.</li>
<li>object-list is an optional list used to immediately instantiate 1 or          more instances of the struct.</li>
</ul>
<blockquote>
<pre>struct Date
{
    int day;
    int month;
    int year;
}</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="switch"></a>switch</code></strong></p>
<ul>
<li>Used to test an expression of an integer value against many constant integer      values and is commonly used to replace large if()&#8230;else if()&#8230; statements.      Break statements are required between each case statement, otherwise execution will &#8220;fall-through&#8221; to the next case statement. The default case is optional. If provided,      it will match any case not explicitly covered by the preceding cases in the      switch statement.<br />
<blockquote>
<pre>char keystroke = getch();
switch( keystroke )
{
    case 'a':
    case 'b':
    case 'c':
    case 'd':
        KeyABCDPressed();
        break;
    case 'e':
        KeyEPressed();
        break;
    default:
        UnknownKeyPressed();
        break;
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="template"></a>template</code></strong> (C++ only)</p>
<ul>
<li> Used to create generic functions and can operate on data without knowing      the nature of that data. They accomplish this by using a placeholder data-type      for which many other data types can be substituted.<br />
<blockquote>
<pre>template void genericSwap( X &amp;a, X &amp;b )
{
    X tmp;

    tmp = a;
    a = b;
    b = tmp;
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="this"></a>this</code></strong> (C++ only)</p>
<ul>
<li>Used as a pointer to the current object. All member functions of a class have this pointer.<br />
<blockquote><p>this.print();</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="throw"></a>throw</code></strong> (C++ only)</p>
<ul>
<li>Used together with try and catch statements to create an exception handling system. Throw is used to generate      an exception.<br />
<blockquote>
<pre>try
{
    cout &lt;&lt; "Before throwing exception"&lt;&lt; endl;
    throw 42;
    cout &lt;&lt; "Shouldn't ever see this"&lt;&lt; endl;
}
catch( int error )
{
    cout &lt;&lt; "Error: caught exception " &lt;&lt; error &lt;&lt; endl;
}
</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="true"></a>true</code></strong> (C++ only)</p>
<ul>
<li>Used to represent the Boolean value true.<br />
<blockquote><p>bool b = true;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="try"></a>try</code></strong> (C++ only)</p>
<ul>
<li>Used to attempt to execute exception-generating code.<br />
<blockquote>
<pre>try
{
    cout &lt;&lt; "Before throwing exception" &lt;&lt; endl;
    throw 42;
    cout &lt;&lt; "Shouldn't ever see this" &lt;&lt; endl;
}
catch( int error )
{
    cout &lt;&lt; "Error: caught exception " &lt;&lt; error &lt;&lt; endl;
}</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="typedef"></a>typedef</code></strong></p>
<ul>
<li>Used to create a new type from an existing type.<br />
<blockquote><p>typedef int seconds;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="typeid"></a>typeid</code></strong> (C++ only, seldom used)</p>
<ul>
<li>Used to get a reference to a type_info object that describes the object      it was passed.<br />
<blockquote><p>typeid(object);</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="typename"></a>typename</code></strong> (C++ only)</p>
<ul>
<li>Used to describe an undefined type or in place of the class keyword in a      template declaration.</li>
</ul>
<hr>
<p><strong><code><a name="union"></a>union</code></strong></p>
<p>Used to create multiple data fields that will occupy the same memory location.</p>
<blockquote>
<pre>union Data
{
    int i;
    char c;
};
</pre>
</blockquote>
<hr>
<p><strong><code><a name="unsigned"></a>unsigned</code></strong></p>
<ul>
<li>Used to specify that the int or char provided can only be posative and can      therefore contain a larger number since there is no need to worry about representation      of negative numbers.<br />
<blockquote><p>signed int i = -12;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="using"></a>using</code></strong> (C++ only)</p>
<ul>
<li>Used to import a namespace into the current scope.<br />
<blockquote><p>using namespace std;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="virtual"></a>virtual</code></strong> (C++ only)</p>
<ul>
<li>Used to create virtual functions that can be overridden by derived functions.
<ul>
<li>A virtual function indicates that a function can be overridden in a          subclass, and that the overridden function will actually be used.</li>
<li>When a base object pointer points to a derived object that contains          a virual function, the decision about which version of that function to          call is based on the type of object pointed to by the pointer, and this          process happens at runtime.</li>
<li>A base object can point to different derived objects and have different          versions of the virual function run.</li>
</ul>
<blockquote><p>virtual void print();</p></blockquote>
</li>
<li>Used to create a <span style="text-decoration:underline;">pure virtual function</span> which is a virtual function that      <em> <strong>must</strong></em> be overriden by some derived class.<br />
<blockquote><p>virtual void print() = 0;</p></blockquote>
</li>
<li><strong>Note:</strong> A method in a class cannot be both &#8220;virtual&#8221;        and &#8220;static&#8221;.</li>
</ul>
<hr>
<p><strong><code><a name="void"></a>void</code></strong></p>
<ul>
<li>Used to denote functions that return no value.<br />
<blockquote>
<pre>void print()
{
    cout &lt;&lt; "printn";
}
</pre>
</blockquote>
</li>
<li> Used to create generic variables which can point to any type of data.<br />
<blockquote>
<pre>void *p = 5;
</pre>
</blockquote>
</li>
<li>Used to declare an empty parameter list.<br />
<blockquote>
<pre>void print( void )
{
    cout &lt;&lt; "printn";
}</pre>
</blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="volatile"></a>volatile</code></strong></p>
<ul>
<li>Used to inform the compiler that the variables value can change in unexpected      ways (i.e. through an interrupt), which could conflict with optimizations      that the compiler might perform, so therefore the compiler will not optimize      these variables.<br />
<blockquote><p>volatile Date d;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="wchar_t"></a>wchar_t</code></strong></p>
<ul>
<li>Used to declare a wide character variable. This variable type is normally      16 bits (2 bytes) long.<br />
<blockquote><p>wchar_t c = &#8216;c&#8217;;</p></blockquote>
</li>
</ul>
<hr>
<p><strong><code><a name="while"></a>while</code></strong></p>
<ul>
<li> Used as a looping construct that will evaluate a list of statements as      long as the condition is true. Note: if the condition      starts off as false, the list of statements will never      be executed. (You can use a do loop to guarantee that the      list of statements will be executed at least once.)<br />
<blockquote>
<pre>bool done = false;
while( !done )
{
    ProcessData();
    if( StopLooping() )
    {
        done = true;
    }
}</pre>
</blockquote>
</li>
</ul>
<hr>
<p>Copyright (C) 2000-2005, The University of British Columbia</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.henrypoon.com/blog/2010/01/18/description-of-c-keywords/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">201</post-id>	</item>
		<item>
		<title>List of C++ Keywords and Operators</title>
		<link>https://blog.henrypoon.com/blog/2010/01/18/list-of-c-keywords-and-operators/</link>
					<comments>https://blog.henrypoon.com/blog/2010/01/18/list-of-c-keywords-and-operators/#respond</comments>
		
		<dc:creator><![CDATA[hp]]></dc:creator>
		<pubDate>Tue, 19 Jan 2010 04:33:13 +0000</pubDate>
				<category><![CDATA[computer stuff]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Computer languages]]></category>
		<category><![CDATA[Const]]></category>
		<category><![CDATA[D]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Go]]></category>
		<category><![CDATA[It]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Programming languages]]></category>
		<category><![CDATA[Sizeof]]></category>
		<category><![CDATA[STR]]></category>
		<category><![CDATA[Struct]]></category>
		<category><![CDATA[Template]]></category>
		<category><![CDATA[Typedef]]></category>
		<category><![CDATA[Typename]]></category>
		<category><![CDATA[Union type]]></category>
		<category><![CDATA[Vol]]></category>
		<category><![CDATA[Words]]></category>
		<category><![CDATA[Z]]></category>
		<guid isPermaLink="false">http://henrypoon.mooo.com/blog/list-of-c-keywords-and-operators</guid>

					<description><![CDATA[Keywords asm do if return typedef auto double inline short typeid bool dynamic_cast int signed typename break else long sizeof union case enum mutable static unsigned catch explicit namespace static_cast using char export new struct virtual class extern operator switch void const false private template volatile const_cast float protected this wchar_t continue for public throw [&#8230;]]]></description>
										<content:encoded><![CDATA[<table style="height:288px;" width="484" border="0">
<tbody>
<tr>
<th colspan="5">Keywords</th>
</tr>
<tr>
<td width="125">asm</td>
<td width="125">do</td>
<td width="125">if</td>
<td width="125">return</td>
<td width="125">typedef</td>
</tr>
<tr>
<td>auto</td>
<td>double</td>
<td>inline</td>
<td>short</td>
<td>typeid</td>
</tr>
<tr>
<td>bool</td>
<td>dynamic_cast</td>
<td>int</td>
<td>signed</td>
<td>typename</td>
</tr>
<tr>
<td>break</td>
<td>else</td>
<td>long</td>
<td>sizeof</td>
<td>union</td>
</tr>
<tr>
<td>case</td>
<td>enum</td>
<td>mutable</td>
<td>static</td>
<td>unsigned</td>
</tr>
<tr>
<td>catch</td>
<td>explicit</td>
<td>namespace</td>
<td>static_cast</td>
<td>using</td>
</tr>
<tr>
<td>char</td>
<td>export</td>
<td>new</td>
<td>struct</td>
<td>virtual</td>
</tr>
<tr>
<td>class</td>
<td>extern</td>
<td>operator</td>
<td>switch</td>
<td>void</td>
</tr>
<tr>
<td>const</td>
<td>false</td>
<td>private</td>
<td>template</td>
<td>volatile</td>
</tr>
<tr>
<td>const_cast</td>
<td>float</td>
<td>protected</td>
<td>this</td>
<td>wchar_t</td>
</tr>
<tr>
<td>continue</td>
<td>for</td>
<td>public</td>
<td>throw</td>
<td>while</td>
</tr>
<tr>
<td>default</td>
<td>friend</td>
<td>register</td>
<td>true</td>
<td></td>
</tr>
<tr>
<td>delete</td>
<td>goto</td>
<td>reinterpret_cast</td>
<td>try</td>
<td></td>
</tr>
</tbody>
</table>
<table style="height:141px;" width="252" border="0">
<tbody>
<tr>
<th colspan="3">Operators</th>
</tr>
<tr>
<td width="60" align="CENTER">+</td>
<td width="60" align="CENTER">++</td>
<td width="60" align="CENTER"></td>
</tr>
<tr>
<td align="CENTER">&#8211;</td>
<td align="CENTER">&#8212;</td>
<td align="CENTER"></td>
</tr>
<tr>
<td align="CENTER">*</td>
<td align="CENTER">/</td>
<td align="CENTER">%</td>
</tr>
<tr>
<td align="CENTER">&amp;</td>
<td align="CENTER">&amp;&amp;</td>
<td align="CENTER">||</td>
</tr>
<tr>
<td align="CENTER">&lt;</td>
<td align="CENTER">&lt;=</td>
<td align="CENTER">,</td>
</tr>
<tr>
<td align="CENTER">&gt;</td>
<td align="CENTER">&gt;=</td>
<td align="CENTER">;</td>
</tr>
<tr>
<td align="CENTER">=</td>
<td align="CENTER">!=</td>
<td></td>
</tr>
<tr>
<td align="CENTER">?</td>
<td align="CENTER">:</td>
<td align="CENTER">::</td>
</tr>
<tr>
<td align="CENTER">&gt;&gt;</td>
<td align="CENTER">&lt;&lt;</td>
<td align="CENTER">#</td>
</tr>
<tr>
<td align="CENTER"></td>
<td align="CENTER">&#8216;</td>
<td align="CENTER">&#8220;</td>
</tr>
<tr>
<td align="CENTER">()</td>
<td align="CENTER">[]</td>
<td align="CENTER">{}</td>
</tr>
<tr>
<td align="CENTER">!</td>
<td align="CENTER">^</td>
<td align="CENTER">˜</td>
</tr>
<tr>
<td align="CENTER">.</td>
<td align="CENTER">-&gt;</td>
<td align="CENTER">-&gt;*</td>
</tr>
</tbody>
</table>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.henrypoon.com/blog/2010/01/18/list-of-c-keywords-and-operators/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">193</post-id>	</item>
	</channel>
</rss>
