Download presentation
Presentation is loading. Please wait.
Published byEdwin Dennis Modified over 6 years ago
1
CE221 – Data Structures & Algorithms Lab Introduction
Course Assistants: A. Teoman Unay, Yiğit Oktar
2
LAB Introduction Teoman Unay Office : MB166
Please do not visit the office for asking questions about the lecture. There will be recitation hours for that purpose. Our office is not suitable for lecturing. Website : Website is for your grades, attendances and required lab-files. Check it regularly.
3
What are we going to do? Selected book questions will be solved
4 Quizes 6 Coding Assignments All assignments are going to be in lab. Every lab material (quiz or assignment) worths 3 points. There will be 10 materials. 3 x 10 = 30 points total.
4
Java - Coding assignments are going to be in Java language.
- In Java, it is very important to keep in mind the following points.
5
Java Case Sensitivity − Java is case sensitive, which means identifier Hello and hello would have different meaning in Java. Class Names − For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. Example: class MyFirstJavaClass public static void main(String args[]) − Java program processing starts from the main() method which is a mandatory part of every Java program.
6
Java Program File Name − Name of the program file should exactly match the class name. When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match, your program will not compile). Example: Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java'
7
Creating an Object In Java, the new keyword is used to create new objects. There are three steps when creating an object from a class − Declaration − A variable declaration with a variable name with an object type. Instantiation − The 'new' keyword is used to create the object. Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object.
8
Creating an Object Output:
9
Accessing Instance Variables and Methods
Instance variables and methods are accessed via created objects. Output:
10
Source File Declaration Rules
There can be only one public class per source file. The public class name should be the name of the source file as well which should be appended by .java at the end. For example: the class name is public class Employee{} then the source file should be as Employee.java. If the class is defined inside a package, then the package statement should be the first statement in the source file. If import statements are present, then they must be written between the package statement and the class declaration. If there are no package statements, then the import statement should be the first line in the source file.
11
Variable Types Following are valid examples of variable declaration and initialization in Java There are three kinds of variables in Java − Local variables Instance variables Class/Static variables
12
Loop Control A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages
13
while loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. Example: Output:
14
for loop A for loop is a repetition control structure that allows you to efficiently write a loop that needs to be executed a specific number of times. Example: Output:
15
do…while loop A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time. Example: Output:
16
Desicion Making Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
17
if…else.. statement If the condition is true, then the if block of code will be executed, otherwise else block of code will be executed. Example: Output:
18
switch statement A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case. Example: Output:
19
Loop Control Statements
Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. break statement Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch. continue statement Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
20
Logarithm Let’s also refresh our memory about logarithms:
The idea of logarithms is to reverse the operation of exponentiation, that is, raising a number to a power: 23 = 8 It follows that the logarithm of 8 with respect to base 2 is 3 log28 = 3 In computer science (complexity analysis), binary logarithm is used. Common logarithm -> logx = log10x Binary logarithm -> logx = log2x
21
Series Easiest formulas to remember are:
22
Cheating Following actions will be considered as cheating:
Submiting same or very similar lab material (quiz/codework) with another student. «We have prepared this together!» is not an excuse. You need to prepare your assignments alone. «My friend has submitted my work without my knowledge» is not an excuse. Your work is in your responsibility. Copying all/some of the work from the internet. Of course you can get help but copying the core parts from an external source is cheating. Cheating is strictly forbidden. Submissions that includes any of the conditions above will be graded as 0 and related professors will be informed.
23
Recitation Hours Recitation Hours for your questions about the lecture will be announced soon. You can ask your course assistant anything about the course within these hours. Please me and specify the topic or the question you need to ask before coming. Of course you can also just drop by but in that case, the process might be slower.
24
That is all for this week
Have a nice semester!
25
References https://www.tutorialspoint.com/java/
M. A. Weiss, Data Structures and Algorithm Analysis in Java, 3/e, Pearson, 2012
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.