Changes between Initial Version and Version 1 of Software/WhyJava


Ignore:
Timestamp:
Sep 5, 2017, 7:22:09 AM (8 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Software/WhyJava

    v1 v1  
     1FRC robots are controlled by their on-board roboRIO computer.  The computer runs software (programs) that are written by Control Systems students using a programming language.  Programming languages are very compact, precise ways of telling the robot what to do.  Programming languages are very different from spoken languages (English, Spanish, Chinese, etc.) and often consist of as few as [https://www.programiz.com/c-programming/list-all-keywords-c-language 32 words]!  What's really cool about programming languages is that using that tiny set of words, you can write programs of amazing sophistication.
     2
     3FRC supports many different programming languages, but Team 2537 uses [https://en.wikipedia.org/wiki/Java_(programming_language) Java].  Java is the primary language taught by most high schools and colleges because the [http://media.collegeboard.com/digitalServices/pdf/ap/ap-course-overviews/ap-computer-science-a-course-overview.pdf AP Computer Science exam] requires Java.  Although it is not an ideal language for robotics, using Java allows participation in robotics to help reinforce material learned through the school curriculum.  Java is also among the [https://spectrum.ieee.org/computing/software/the-2017-top-programming-languages most popular programming languages] so it is well worth learning.  Java is part of the family of programming languages that includes C, C++, and C# which collectively have dominated computer programming for the last several decades.
     4
     5The small set of Java words includes verbs (words that invoke an action like '[https://www.tutorialspoint.com/java/java_do_while_loop.htm do]'), conditionals like '[https://www.javatpoint.com/java-if-else if]', and you can introduce nouns that are the subjects or objects that other words can act on.  Like all languages, Java has specific rules of syntax (grammar, spelling, etc.) that dictate how the language is used.  Learning the key words and syntax are the first challenges when learning Java.  Let's examine the simple turtle-graphics exercise and see how it might look in Java:
     6
     7{{{#!th rowspan=3 align=justify
     8|| English || Turtle || Java ||
     9{{{#!td
     101. Draw with a Black pen
     112. Do this Four Times:
     12  1. Move Forward 10 Paces, Drawing
     13  2. Turn Right 90 Degrees
     14}}}
     15{{{#!td
     16COLOR BLACK [[BR]]
     17REPEAT 4[[BR]]
     18  DRAW 10 [[BR]]
     19  RIGHT 90 [[BR]]
     20NEXT
     21}}}
     22{{{#!td
     23setColor(Color.Black); [[BR]]
     24int edge = 0; [[BR]]
     25while (edge < 4) {
     26  edge = edge + 1; [[BR]]
     27  moveAndDraw(10); [[BR]]
     28  turn(90); [[BR]]
     29}
     30}}}
     31}}}
     32
     33Notice that each Java command ends with a semi-colon and that groups of commands are enclosed in curly-braces.  These are examples of Java syntax.
     34
     35Like all programming languages, Java allows you to combine groups of commands into a single unit that forms an abstraction.  For example, the words shown above that draw a square could be combined into a single new word that can be used to replace the individual words.  This allows programs to be built with increasing abstraction so high level concepts such as 'put the ring on the peg' can be expressed clearly and concisely.