Midterm 2 Review Sunday 1June2014

Embed Size (px)

Citation preview

  • Midterm 2 ReviewRyan, Zack, Kristiyan, Jeffery, Alok

  • Goals of CSE 15L Team for weekly Labs:

  • Topics1. Git 2. TDD & JUnit 3. Makefile4. Unix Shell Scripting 5. Ant & XML6. Java Logging API7. Profiling

  • Git

  • GitThings 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

  • TDD & JUnit

  • Test Driven Development JUnit is a tool for Test Driven Development [TDD]

    In TDD, tests are written before the software itself.

    You must understand the system before writing tests for it!

    Regression testing -> change to code = build project + run tests

  • 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..

  • And now JUnit itself! 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 Test fixture sets up the data needed to run tests. Unit Test - A piece of code written by developer that executes a particular

    part of the code being tested. Test case - Tests the response of a single method to a particular set of

    inputs. Test suite - Collection of test cases. Test runner - Software that runs your tests. Integration test - how well classes work together. Not good in JUnit.

    http://www.vogella.com/tutorials/JUnit/article.html

  • Test in JUnit that returns without

    failing or throwing an exception is

    considered pass.

    Failure happens when JUnit

    assertion fails.

    Goal for perfect implementation is to

    pass all tests, and for imperfect is to

    fail at least one test.

  • Other Frameworks JUnit - JAVA cppUnit - C++ PHPUnit - PHP NUnit - .NET

    All have: 1. Test Runner 2. Test Cases 3. Test fixtures 4. Test suites5. Test Execution

  • Makefiles

  • MakefilesQuestions 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?

  • The Makefile FormatThe format is just something you should memorize. Dependencies can be files. If a dependency is more recent, than the target will be made.Format:target: dependencies

    action

    Basic Example:default:

    javac *.java

    clean:rm *.class

    new: clean, default

  • The Makefile FormatReal Example:

    CXX = g++DEFINES = -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIBCXXFLAGS = -pipe -std=c++11 -O2 -Wall -W -D_REENTRANT -fPIE $(DEFINES)INCPATH = -I/software/common/qt-5.0.1/mkspecs/linux-g+

    boggleutil.o: boggleutil.cpp boggleutil.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o boggleutil.o boggleutil.cpp

  • Declaring VariablesFor 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 = javacSRC = *.java

    $(COMPILE) $(SRC)

    Real Example:DEFINES = -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIBCFLAGS = -pipe -O2 -Wall -W -D_REENTRANT -fPIE $(DEFINES)

  • Making in a directoryTo make in a subdirectory do:

    make -C directory/ target

    As an example there is:

    make -C lib/ new

    So in a makefile it may look likeclean:

    make -C lib/ cleanmake -C bin/ cleanrm *.class

  • 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`

  • Shell Scripting (declarations) Array declarations:

    y=(Hello hi hey) To access declared variables, use $ and braces

    echo ${y[0]} Hello is printed

    Declarations must not include spaces around equals sign

  • Shell Syntax Instead of using braces {} to control logic flow and statement blocks, shell

    uses terminating words: if, then/ fi case / esac for, do, done while, do, done

    for i in {1..10}do

    if [ $[i % 2] = 1 ]; thenecho $i is odd

    elseecho $i is even

    fidone

  • Examplesfor (( c=1; c
  • Examples (more)ls | while read linedo

    echo Hello ${line}!done_______________________

    filename=$1cat $filename | while read linedo

    echo Hello ${line}!done

    filename=$1while read linedo

    echo Hello ${line}!done < $filename

  • What you should know Know the difference between echo and cat Variable declarations How to call variables How strings , ``, work in bash How to use simple constructs like if statements, for loops, etc Commands like cd, rm, mv, cp, etc

    Site to test:http://www.compileonline.com/execute_bash_online.php

  • XML & Ant

  • XML Sibling of HTML and and XML Data Components

    Elements Hierarchical structure with open-close tag pairs Nesting, same names is allowed, order matters

    Kristiyan Dzhamalov

    Attributes named values are not hierarchical, order does NOT matter mdate=2014-06-01

  • XML Example

    AntXMLJUnit

    Makefile

    and more

  • Ant - Another Neat Tool

    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?

  • Ant - Cont. Each Ant XML file contains:

    1 project and at least 1 target Targets have multiple tasks

    Projects contain 3 attributes - name, default and basedir default means which target to compile if not specified

    Target contains a name and optionally depends and description There can be dependencies between targets Task represents an action that needs execution

    Read lecture slides and lab

  • Java Logging APILink to lecture slide

  • Java Logging API Why use it?

    The Java Logging API provides a standardized process of logging statements (automatically recording diagnostic output from a program)

    Better than using System.out.println() statements scattered throughout your code

    You can leave all logging statements in your code and control which ones are printed out using logging.properties file

  • 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).

  • Severity Levels (Descending order)1. SEVERE: Used for logging fatal runtime error events2. WARNING3. INFO4. CONFIG5. FINE: Usually at the level of object creation, catch clauses for exceptions

    that do not constitute errors, and so on.6. FINER: Entering and exiting should be used for tracing method entry and

    exit; arguments and return values can be specified.7. FINEST: This level of tracing can be used to track the state of instance

    variables in a class e.g. before a method call, inside a method or a loop and after a method call.

  • 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

  • Loggers and Handlers Loggers are objects that allow the application to log

    without regard to where the output is sent/stored Handlers receive the log message from the logger and

    export it to a certain target. Examples of Handlers:

    ConsoleHandler: Write the log message to console FileHandler: Writes the log message to file

  • 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

  • hprofheap=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 !

    Have a nice Summer !