Midterm 2 Review Sunday 1june2014
Midterm 2 Review Sunday 1june2014
Topics
1.
2.
3.
4.
5.
6.
7.
Git
TDD & JUnit
Makefile
Unix Shell Scripting
Ant & XML
Java Logging API
Profiling
Git
Git
Things you should know
What is git?
What is distributed version control?
What is centralized version control?
What is a push?
What does a staged file mean?
General git commands
Git
git status
Gives the status of all of the modified, newly added or newly removed files in the
local files
git log
Prints a log of all the recent git commands
git add
Stages a file to be committed
git remove
Removes a tracking of a file
git commit
Makes all the staged changes
git push
Puts all of the changes to a remote repo
git pull
Gets all the changes from a remote repo
Git Visualized
You must understand the system before writing tests for it!
Unit Testing
What is a unit?
Unit is a single method! You are testing individual methods (units)
from the class they belong to!
Why should you use Unit Testing?
increased productivity
goal driven-code
and more...
Why you should not use it?
Does NOT test the full software
Consumes too much time
etc..
JUnit is a widely used framework for unit (remember what this is?) testing
of Java software!
JUnit:
Define and execute tests and test suites
Test Suites has many tests!
Write and debug code
and more
JUnit Terminology
Other Frameworks
JUnit - JAVA
cppUnit - C++
PHPUnit - PHP
NUnit - .NET
All have: 1. Test Runner 2. Test Cases 3. Test fixtures 4. Test suites
5. Test Execution
Makefiles
Makefiles
Questions you should know the answer to about Makefiles
What is the point of a Makefile?
Why dont we just compile it again?
Why dont we just use a shell script?
What is the format of a Makefile?
How do we define variables in Makefiles?
How do we make in a subdirectory?
Basic Example:
default:
javac *.java
clean:
rm *.class
new: clean, default
= g++
= -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB
= -pipe -std=c++11 -O2 -Wall -W -D_REENTRANT -fPIE
= -I/software/common/qt-5.0.1/mkspecs/linux-g+
Declaring Variables
For makefiles, we can define by simply creating a variable in all caps (by
convention) and setting it equal to a string. When we use the variable, it will be
replaced by the string we set it to.
Basic Example:
COMPILE
SRC
= javac
= *.java
$(COMPILE) $(SRC)
Real Example:
DEFINES
CFLAGS
Making in a directory
To make in a subdirectory do:
make -C directory/ target
Unix/Shell Scripting
Piping/Filtering
A pipe is a way to send the output of one command to another; the output
of the first becomes the input of the second
To make a pipe, put a vertical bar | on the commandline between two
commands
Examples:
ls -l | grep Apr
ls | wc -l
man ksh | grep "history" | wc -l
A filter is a program that takes input from another program and transforms
it in some way
Shell Scripting
Lines starting with # are comments, but the first line #! is not a comment; it
indicates the location of the shell that will be run
Quote characters
double quote: if a string is enclosed in the references to variables
will be replaced with their values
single quote: taken literally
` back quote: treated as command
echo Date is: `date`
Array declarations:
y=(Hello hi hey)
To access declared variables, use $ and braces
echo ${y[0]} Hello is printed
Shell Syntax
Instead of using braces {} to control logic flow and statement blocks, shell
uses terminating words:
if, then/ fi
for i in {1..10}
case / esac
do
for, do, done
if [ $[i % 2] = 1 ]; then
while, do, done
echo $i is odd
else
echo $i is even
fi
done
Examples
for (( c=1; c<=5; c++ ))
do
echo "Welcome $c times"
done
__________________________
c=0
while [ $c -lt 10 ]
do
echo The counter is $c
let c=c+1
done
Examples (more)
ls | while read line
do
echo Hello ${line}!
done
_______________________
filename=$1
while read line
do
echo Hello ${line}!
done < $filename
filename=$1
cat $filename | while read line
do
echo Hello ${line}!
done
Site to test:
http://www.compileonline.com/execute_bash_online.php
XML
Sibling of HTML
<tag></tag> and <title></title> and <midterm></midterm>
XML Data Components
Elements
Hierarchical structure with open-close tag pairs
Nesting, same names is allowed, order matters
<review mdate=2014-06-01...>
<presenter>Kristiyan Dzhamalov</presenter>
</review>
Attributes
named values are not hierarchical, order does NOT matter
mdate=2014-06-01
XML Example
<review>
<presenter name=Kristiyan >
<topic>Ant</topic>
<topic>XML</topic>
<topic>JUnit</topic>
</presenter>
<presenter name=Zack>
<topic>Makefile</topic>
</presenter>
and more
</review>
Tool for automated software builds - Very useful in industry with Java dev.
Similar to make
Uses XML to describe the building process and its dependencies
By default the XML file is named build.xml
You can obtain the value of a variable using ${property_name}
How to make a variable?
<property name=public.dir location=public />
Ant - Cont.
General Concepts
Each log message has an associated log Level
The Level class specifies the importance and urgency of
a log message
Seven standard log levels ranging from FINEST (the
lowest priority) to SEVERE (the highest priority).
Tracing
Tracing involves logging messages which
report the state of the application at different
stages of execution
Useful for following the flow of your program
Profiling
Profiling
- Why ?
- What ?
- How ?
What ?
Memory
CPU Usage
HDD Usage (Swap files etc)
Network Usage
Battery
In short, any resource that your
application depends on
How ?
hprof
hprof
heap=dump|sites|all
This option helps in the analysis of memory usage.
It tells HPROF to generate stack traces, from which
you can see where memory was allocated.
heap=dump option, you get a dump of all live objects in the heap.
heap=sites, you get a sorted list of sites with the most heavily allocated
objects at the top.
The default value all gives both types of output.
hprof
hprof
UNIX Time
Thank you !