Skip to content

marwankau/cpit305-fall-2022

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPIT 305 Advanced Programming

This repository contains all code done during lectures.

Topics

  1. Review
  2. IO Stream
  3. Exception Handling
  4. Threads

Review

IO Stream

Here the class diagram for all IO Stream IO Stream Class diagram

  • User Input using System.in and Scanner
  • Text File
    • Write text file using
    • Read text file using FileInputStream and array of byte
    • Read text file using BufferedReader and InputStreamReader Lecture 04
  • Binary File with fixed string an example of data recored (int, char[15], double)
    • Write binary file
    • Read binary file using DataInputStream
      • read single recored from file by moving file currsor into specifc position in the file Lecture 04
      • read whole file recored by recored until reaching end of file using EOFException Lecture 04
  • Using input mark and reset from BufferedInputStream Lecture 05
  • Read/Write binary file using RandomAccessFile Lecture 05
  • Binary file simulate database management system that include (add/edit/delete/search) using RandomAccessFile Lecture 06
  • File usage:
    • Reterive file information and check its existance Lecture 07
    • Create new file and delete it Lecture 07
    • Create new Directory and delete it using Lecture 07
    • Using JFileChooser and list selected directory files Lecture 07
    • List all files and directories and sub-directories recursively as a tree Lecture 07
  • Working with class instance to be stored/read in/from a file using ObjectOutputStrea and ObjectInputStream Lecture 09
    • First you make sure your class is serializable (implements Serializable)
    • Write Object onto file Lecture 09
    • Read Several stored objects from a binary file Lecture 09

Exception Handling

Threads

Thread States

  • Example of calculating the sum of an array using:
  • Example of shared resource between threads:
    • Counter: Two threads increasing static variable shared between them. Each thread increases the counter 1000000 times, so the final value of counter after both threads should be 2000000
      • incorrect way to increase a counter using several threads Lecture 09
      • solve for previous example
    • Bank and ATM: A bank has several customers' accounts. ATMs use an instance of that bank and call transfer method in order to transfere from account to another. Each ATM works as a thread. The transfer occors in the same time which may cause unexpected result. That is, bank instance initilized with number of accounts with initial amount of 1000.0 SAR. Assume that number of accounts is 10. The total balance of the bank should always 1000.0 * 10 = 10000.0; however, do to the concurrent transfer the total bank balance change which it should not.
      • Unsolved example: Lecture 10
      • Solved example:
        • using synchronized keyword with transfer method signture Lecture 10
        • using synchronized block Lecture 10

Folder Structure

The workspace contains two folders by default, where:

  • src: the folder to maintain sources
  • lib: the folder to maintain dependencies

Meanwhile, the compiled output files will be generated in the bin folder by default.

If you want to customize the folder structure, open .vscode/settings.json and update the related settings there.

Dependency Management

The JAVA PROJECTS view allows you to manage your dependencies. More details can be found here.