Recitation 2: Variables, Initialization, Assignment, Declaration, Boolean Expressions, installing and running java programs

Recitation 2 What are variables? What is declaration, assignment, initialization, a boolean expression, types, and syntax?

A variable is a piece of memory that can contain a data value.

A declaration is writing out the type and variable name. <type> <var name>; ex. int x;

An initialization is assigning a value to a variable <var name> = <value>; ex. x = 5;

An assignment is the whole thing, meaning you do both. <type> <varname> = <value>; ex. int x = 5;

In programming languages every variable has a type. In java there are two categories: primitives and reference. Let’s focus on primitives for now. They are:

Boolean expressions evaluate to true or false. They use operators like <,<=,&&,||,!. You can find these expressions in the conditional part of if statements. Boolean expression can be found in the parenthesis of if(<Boolean Expression>), while(<Boolean Expression>), and for(;<Boolean Expression>;).

How to install Java, compile and run java code

The extended post is here, which describes what exactly the JDK and all of this is, but here are the steps and basics.

  1. 1) Download the JDK (java so you can code in it and run your programs) for your operating system.

  2. 2) Run the installer (whatever.EXE for windows, something.dmg for OSX, or run a command this command for linux sudo dpkg -i /path/to/deb/file followed by sudo apt-get install -f )

  3. 3) Open up CMD/Powershell (windows) or Terminal (OSX, Linux)

  4. 4) Type in the command java and you should see a bunch of text. java -version will also let you know if you have it installed and will obviously output the version.

  5. 5) Type in the command javac and you should see some documentation like Usage: javac <options> <source files> where possible options include:. Now if you are on windows and don’t see it you should update your system path variable to include the bin folder. Here is a link or too on how to do that. If you have a MAC here is how to set the path variable.

  6. 6) Now the commands you need to know are cd <folder/path> (cd .. to go up a directory), pwd (tells you where you are in your file system), javac <> - to compile, java <FileName> - to run. Technically your filename is the same as your class name as we will learn later in the semester.


Post originally posted on 2018-01-29 01:00:00 +0000

Post last modified on

comments powered byDisqus