Download presentation
Presentation is loading. Please wait.
Published byAngel Cain Modified over 9 years ago
1
STARTUP DIVKOM DAY 2 IPUNG HAVIDZ WIDJAJA / 18112023
2
PROGRAMMING Welcome to day 2 startup divkom 2014 Today we will learn about programming We will focus on java programming
3
WHY JAVA? There are several reasons why we only focus on java programming : 1. most of programming method now focus on object oriented programming (OOP) 2. Most of Divkom’s project in programming is about developing android program 3. Java will be the foundational structure of all Android app/game development that we will cover (at least in the predictable future)
4
“WHAT THE….WHAT IS OOP?” A method of programming based on a hierarchy of classes, and well-defined and cooperating objects. KEY POINTS : State and Behavior Imagine an object. This can be anything, such as a dog, a bag, a bottle, a car, or any other conceivable (or sometimes inconceivable!) THING. Think about what each dog, or each bag, or each bottle, or each car has in common. They can DO things, and they can also have special quirks to them. Dogs bark, chase cats, scratch themselves, and sleep. They can be timid, quiet, loud, excitable, of any number of colors, big, small. Cars can move, can stop, can contain passengers, can go fast, or slow. Object oriented programming is a way to describe what a thing IS and what it can DO.
5
“SO, WHY DO WE USE OOP?” The process of designing and programming objects seems very cumbersome, why bother? It’s difficult to see from such a small example, but for larger projects, OOP techniques allow a great deal of flexibility. OOP will make your work EASIER!
6
“THEN, HOW DO WE OOP?”
7
JOB TO DO 1. prepare your android developer tools (ADT) Bundle eclipse 2. file new java project (give a proper name on your project] 3. expand your project. On src, right click and choose new Classes 4. name your class file. For example : HelloWorld
8
Result :
9
ABOUT JAVA SYNTAX A. Variables in java Example : integer, Boolean, float, string, char, etc… Variables may be a global/local variables (what’s the difference?] Global : You can use it in any method/class on your java project Local : you can only use it in specific method/class
10
MORE ABOUT VARIABLES….. 1. Instance variable Declared without ‘static’ example : int number Has unique values depending on each instance that they belong to 2. Class variable Declared with ‘static’ example : static int number = 10 There will be a single copy of this variable
11
LET’S TRY THIS! Result :
12
ANALYZING THE SYNTAX…. 1. the first result will be 11 because total is the value of class/global variable ‘eight’ is added to local variable ‘number’, which means 8+3 = 11. 2. the second result will be 16 because total is the value of class/global variable ‘eight’ s added to class/global variable ‘number’, which means 8+8 = 16.
13
B. Basic operation There are several basic math operations on java : + : addition - : Substraction / : Division * : Multiplication % : mod operation (returns the value of remainder]
14
LET’S TRY THIS! (2) Result :
15
C. Increment and Decrement Another math operation in java is increment and decrement : 1. increment : increase the value of a variable with a specific value 2. decrement : decrease the value of a variable with a specific value For example in java syntax counter++ (adds one to counter variable], counter+=3 [adds 3 to counter variable] If there is an exact value before increment/decrement, the previous value will be added/substracted.
16
MORE ABOUT INCREMENT/DECREMENT There are two types of increment/decrement in java syntax : 1. Pre-increment/decrement : the value is added/substracted first before being executed 2.Post-increment/decrement : The value is executed first before being added/substracted
17
LET’S TRY THIS! [3] Result:
18
D. conditional (if-else] In java, there is also if-else statement, like other programming languages. It is about comparison between two/more variables Operator used : == equals to != doesn’t equal to >= more than equal <= less than equal > more than < less than && logical operator ‘and’ || logical operator ‘or’
19
LET’S TRY THIS! [4] Result :
20
D. switch method It’s like if-else statement, but more general Assign an output depends on statement
21
Result :
22
E. looping techniques There are several methods to do looping techs : 1. while-do 2. do-while 3.for
23
MORE ABOUT LOOPING Result : RESULT :
24
Result :
25
F. randomization For several programs, we need randomization (for example, about number which will come from a rolled dice] Declaration
26
There will be an error before executing (OMG Hello! Why???] The answer is : you need to import a library How to import a library CTRL+SHIFT+O
28
PRINTF/SCANF Remember about printf/scanf on C programming language? In java, there are several ways to express those operation We use ‘system.out.println(“ “) ‘ to print some text on monitor, as we have used before We use ‘scanner.input = new scanner(system.in)’ to scan the input from keyboard Of course we need to import a library use CTRL+SHIFT+O This method is used for a string input, so the data type must be string How about integer input? See the next slide
29
Result :
30
TIPS AND TRICK You see that your syntax is not good enough! (read : not tidy ) Use CTRL+SHIFT+F to make your syntax looks beautiful if you want to type your syntax faster, try CTRL+SPACE
31
SUMMARY You have known what oop is You have known why we use oop and java You have known about some basic java languages You have known about some basic math operations You have known about increment/decrement You have know about variables You have known about conditional (if-else), switch-case You have known about looping techniques You have known about randomization You have known about printing and scanning Several tips and tricks given
32
ANY QUESTION?
33
HOMEWORKS! “omg hello why homeworks??” Practice makes perfect Your homeworks (individually, choose one only )
34
YOUR HOMEWORKS 1. ‘Equal Game!’ Create a simple equal game that is played by 2 players (You and Computer). This game is adopted from ‘Cepe’ Game in Indonesia, but much different. How this work? The specification below will explain all of this : First, a number shown from a random process. For example, the first number shown is 4. It is the initial total. You will be the first player to draw a card also from a random process. It is represented as number. You will be given a decision whether you want to add/substract your number to/from the first number shown. Now the total depends on your decision. Computer will draw a card from a random process (represented as number too). The opponent will add/substract depends on total. In this case, if total <= 45, computer will always add the number. Now, the total is changed (added/substracted by computer’s choice) If the total is 50 after you add your number, you win. If the total is 50 after opponent adds his number, you lose. The total may be less/more than 50 If the total is negative, the game ends immediately.
36
2. Too hard? You can submit your own PROGRAM! The specification is : you need to use all of the basic syntax in Java you have learnt today. The program must at least use 2 procedures/function to be called in main program Create the program effectively and efficiently! Submit your program to : E-mail : StartupDivkom2014@hotmail.com dengan subject : Tugas2_Nama_NIM Deadline : Saturday, November 8 2014 (11.59 PM) File to be sent : java format file. (xxx.java) or the whole package you’ve made!
37
THANK YOU FOR YOUR ATTENTION!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.