Task 1 - Download JDK (cont)- Select Java Platform (JDK), choose your operation platform (egWindow X86) and download it
Task 2 - Install JDK- Run the downloaded installer, which installs both the JDK (JavaDevelopment Kit) and JRE (Java Runtime). By default the JDK andJRE will be installed into directories C:Program FilesJava
Task 3 - Config PATH environment variables- Windows Operating System searches the current directory and thedirectories listed in the PATH environment variable for executableprograms invoked from the CMD shell. It helps programmer cancompile Java code in CMD shell.- Click the "Start" button > "Control Panel" > "System" > (Vista/7 only)"Advanced system settings"
Task 1 - Open your editor- For example: Notepad++
Task 2 - Write your code- Type this code bellow to editor window
Task 2 - Write your code (cont)- Save the code in a file with the name Helloworld.java- Note: File name must same as class name.
Task 3 - Compile and run on command-line- Launch a CMD shell > type javac to compile the source code andjava to run the program using the JDK runtime
Exercise 3Install and use Eclipse to write aJava program
Task 1 - Download Eclipse- Download Eclipse from http://www.eclipse.org/downloads. Forbeginners, choose the minimal Eclipse IDE for Java Developers.- Unzip the downloaded file into a directory of your choice.
Task 2 - Launch Eclipse- Open eclipse.exe in the Eclipse installed directory- Choose an appropriate directory for your workspace
Task 3 - Create a new Java Project- Choose "File" menu > "New" > "Java project"
Task 4 - Write a Java program- In the "Package Explorer" (left panel) > Right-click on "JavaLab" (oruse the "File" menu) > New > Class
Task 4 - Write a Java program (cont)- Enter the following codes
Task 5 - Compile and Execute- To run the program, right-click anywhere on the source file"HelloWorld.java" (or from the "Run" menu) > Choose "Run As" > "JavaApplication".
Task 1 - Create project and write a simpleprogram- Create a new class named Debug and enter the following code.
Task 2 - Set an Initial Breakpoint- Set a breakpoint at main() method by double-clicking on the left-margin of the line containing main().
Task 3 - Debug- Right click anywhere on the source code (or from the "Run" menu) >"Debug As" > "Java Application" > choose "Yes" to switch into "Debug"perspective Step-Over and Watch the Variables and Outputs.
Diagram (cont)The management of the A Bank is looking at automation as a means tosave time and effort required in their work. In order to achieve this, themanagement has planned to computerize the following transactions:• Creating a new account• Withdrawing money from an account• Depositing money in an accountThe CEO of the company and a team of experts have chosen yourcompany to provide a solution for the same. Consider yourself to be apart of the team that implements the solution for designing theapplication.
Diagram (cont)Create an application using exceptions and assertions to implement thetransactions. The application should consist of the following classes.1. Account.java2. Account Test.java3. InsufficientFundException.java4. NegativeAmountException.javaEach class has a specific purpose and functionality. The descriptions ofeach class are as follows.
Task 1 - Create Account class(The Account class represents an actual bank account. It stores thefollowing details of a bank account)• customerName• accountNumber• accountbalance• void displayAccountDetails() : This method displays the details ofthe account
Task 1 - Create Account class (cont)• void withdraw() : This method is used to withdraw money from an account.This method accepts the account number and the amount to be withdrawn fromthe account. The method then searches in the array of accounts for the accountnumber. Use assertions for checking whether the account number and theamount to be withdrawn are positive. Also use an assertion to check if the arrayof accounts contains a minimum of one account record. The method alsothrows the user-defined exception InsufficientFund***ception in case theamount to be withdrawn exceeds• void deposit() :This method is used to deposit money in an account. Theaccount number and the amount to be deposited in the account is acceptedfrom the user. Use an assertion to check whether the account number ispositive. The method searches for the account number and deposits theamount in the account if it exists. The displayAccountDetails() method is calledif the operation succeeds. Use appropriate try catch blocks to handle all thepossible exceptions that can be thrown due to the user inputs. A user-definedexception is thrown if the account number does not exist.
Task 2 - Create AccountTest class(The AccountTest class is a java main class used to test the Accountclass. It creates an instance of the Account class and displays thefollowing menu of options to the user)· Create a new account· Withdraw Cash· Deposit cash· ExitThe user can select any of the options and a corresponding method isinvoked on the instance of the Bank class. Use an assertion to checkfor the control-flow invariant in case the user types an invalid option.The application exits when the Exit option is selected.
Task 3 - Create InsufficientFundExceptionclass- This is a user-defined exception class derived from the base classException. This exception is thrown when the user tries to withdrawmore money than the current account balance.
Task 4 - Create NegativeAmountExceptionclass- This is a user-defined exception class derived from the base classException. This exception is thrown when the user tries to withdraw ordeposit a negative amount.
Outline- Read a file - BufferedReader- Write a file - BufferedWriter- Write a file - FileOutputStream- List the contents of a directory (Recursively)- Copying a file without Buffering- Copying a file with a Programmer-Managed Buffer- Copying a file with Buffered Streams- Best Copier- InputStreamReader and OutputStreamWriter- BufferedReader and BufferedWriter- PipedReader and PipedWriter- Serializable - ObjectOutputStream
Task 1 - Create WriteFileBuffered program- BufferedWriter is a character streams class to handle the characterdata. Unlike bytes stream (convert data into bytes), you can just writethe strings, arrays or characters data directly to file.
Task 1 - Create WriteFileStream program- FileOutputStream is a bytes stream class that’s used to handle rawbinary data. To write the data to file, you have to convert the data intobytes and save it to file.