1 Department of Networks College of Bardarash Technical Institute DUHOK Polytechnic University Subject: Programming Fundamental by JAVA Course Book Year 1 Lecturer's name: MSc. Sami Hussein Ismael Academic Year: 2017/2018
2 Course Book Course title Programming Fundamental by JAVA lecturer in charge Mr. Sami Hussein Ismael Dept/ College Networks Bardarash Technical Institute Contact details Tel: 750 424 81 88 Email:sami_alsalhi@yahoo.com Course link in the University 5. Time (in hours) per week Theory: 2 Practical: 3 Contact details Tel: Email: Course overview: Introducing the students to the concepts and terms of the JAVA programming and also introducing them to the special commands and instructions to solve and write programs using this language, and understanding the use of different data types to create files and write drawing programs. Course Objectives: Provide students with the skills to formulate an engineering problem and to develop a logical and efficient algorithm for solving the problem. Provide students with a basic understanding of variables, operators, control flow, functions, program structure, and arrays. Provide the skills necessary to structure, implement, and debug computer programs that are easily maintained. Teach programming skills using the Java language. Assessment scheme Semester evaluation Final evaluation Semester evaluation Marks evaluation Marks First Semester Activity 5 % Final Practical Midyear Theory Exam 15 % Exam 30% Midyear Practical Exam 15 % Final Theory Second Semester Activity 5 % Exam 30% Total 40 % Total 60 % Total 100 %
3 Syllabus Theoretical Week Detail What is a computer Programming? Introduction to Java Programming Language 1 What Java Is and How It Works How to Get the Most Out of This Course Write your first program (A Hello World Program) Write a simple program 2 Using Variables (Data Types) Constants (final) 3,4,5 6,7,8 Reading numbers from keyboard Reading numbers from console Formatting Console Output Operations Increment and Decrement Operators Strings: Working With Text Conditions Relational Expressions & Logical Expressions If and Else statements Nested if and else statements 9,10,11, 12 While Loops For Loops Do...While Break and Continue Nested Loop Switch Statements
4 Arrays 13,14,15 Copying Arrays Sorting Arrays Multi-Dimensional Arrays 16,17,18,19,20 21,22 23,24 25 26 Classes and Objects Methods Defining a Method Calling a Method Getters and Return Values Method Parameters Void method Setters and "this" Constructors Static (and Final) String Builder and String Formatting The tostring Method Casting Numerical Values Upcasting and Downcasting Reading Files Using Scanner Handling Exceptions 27,28 Multiple Exceptions Runtime vs. Checked Exceptions Reading Files With File Reader 29,30 Try-With-Resources Creating and Writing Text Files
5 Syllabus of Practical Part Weeks 1 2 Subjects Introduction to Java Programming Language Installing Eclipse and JDK Write your first program (A Hello World Program) Write a simple program Using Variables (Data Types) Constants (final) Reading numbers from keyboard Reading numbers from console 3,4,5 Formatting Console Output Operations Increment and Decrement Operators Strings: Working With Text 6,7,8 Conditions Relational Expressions & Logical Expressions If and Else statements Nested if and else statements 9,10,11, While Loops For Loops Do...While Break and Continue Nested Loop 12 Switch Statements 13,14,15 Arrays Copying Arrays
6 Sorting Arrays Multi-Dimensional Arrays Classes and Objects Methods Defining a Method 16,17,18,19,20 Calling a Method Getters and Return Values Method Parameters Void method Setters and "this" 21,22 23,24 25 Constructors Static (and Final) String Builder and String Formatting The tostring Method Casting Numerical Values Upcasting and Downcasting 26 Reading Files Using Scanner Handling Exceptions 27,28 Multiple Exceptions Runtime vs. Checked Exceptions Reading Files With File Reader 29,30 Try-With-Resources Creating and Writing Text Files
7 Sample Questions: Q1) Answer of the following: 1- What are different between Public and private of access Specifiers in JAVA? 2- What is method overloading? Q1) Answer: 1-1)Public can be accessed by other class member that is initialized outside the class. A public member can be accessed from anywhere even outside the namespace. 2) Private: can be accessed only inside the classes. The private members cannot be accessed outside the class 2-Method overloading: is the same method name with different type of parameters or different set of parameters is known as Method Overloading.. Q2) Select the correct answer from the following: 1- Which of the following will be the correct output for the JAVA program? namespace ConsoleApplication class Sample int i; Single j; public void SetData(int i, Single j) this.i = i; this.j = j; public void Display() Console.WriteLine(i + " " + j); class MyProgram
8 static void Main(string[ ] args) Sample s1 = new Sample(); s1.setdata(36, 5.4f); s1.display(); A. 0 0.0 B. 36 5.4 C. 36 5.400000 D. 36 5 2Which of the following statements is correct about the JAVA code?. class Student s1, s2; s1 = new Student(); s2 = new Student(); A. Contents of s1 and s2 will be exactly same. B. The two objects will get created on the stack. C. Contents of the two objects created will be exactly same. D. The two objects will always be created in adjacent memory locations. Q2)1- Answer: B 2- Answer: c Q3) Write complate a program to Create a class Rectangle has attributes such as length and width. Depending upon the design, it may need ways for accepting the values of these attributes, calculating the area, and displaying details. Q3) Answer
9 using System ; namespace RectangleApplication class Rectangle double length; double width; public void Acceptdetails() length = 4.5; width = 3.5; public double GetArea() return length * width; public void Display() Console.WriteLine("Length: 0", length); Console.WriteLine("Width: 0", width); Console.WriteLine("Area: 0", GetArea()); class ExecuteRectangle static void Main(string[] args) Rectangle r = new Rectangle(); r.acceptdetails(); r.display(); Console.ReadLine(); Q4) Complete the following blanks with suitable word 1- ----------------- variable directly contains data in the memory. 2- ----------------- are sequences of characters 3- Class definition consists of: 4-1-------------------2------------------3--------------4----------------- Q4) Answer
10 1- Value Type 2- Strings 3-1- Class declaration. 2- Inherited class. 3 Fields.4- Constructors Q5) Write method to calculate the sum of the elements in an array. "Main" should be like this: public static void Main() int[] example = 20, 10, 5, 2 ; Console.WriteLine( "The sum of the example array is 0", Sum(example)); Q5)Answer: using System; public class SumArray public static int Sum(int[] example) int total=0; for (int i = 0;i < example.length; i++) total += example[i]; return total; public static void Main() int[] example = 20, 10, 5, 2 ; Console.WriteLine("The sum of the example array is 0", Sum(example));