You are on page 1of 8

Application setup

➔ open a Blank template


↳ Name: Hello_world
↳ language: Java
↳ Minimum API level: API_ 19
➔ Build: progress
➔ Project:➔ Project(structure of like an your system) for
mainactivity.java ➔ app ➔ sources ➔ main ➔ java
↳ the project view is exact hierarchy.
➔ Android view:
↳ App ➔ java ➔ package ➔ main
↳ res ➔ mitmap ➔ icon for android app
↳ manifest file ➔ manifest folder. (features)
➔ // Todo
➔ View ➔ Tool window ➔ profiler.
➔ Pixel 29

Simple app

• Insert the text field through


Text field ➔ Plain Text ➔ Drag it to the field
• set the position
• similarly add Button
• Give id and text(give as hint)
Task

Create a app that will show your first name, Last Name, Email after typing these information and
click on the button in the screen (As in the figure shown below).
Java code:
Variables and Arithmetic operations
➔ for java We need IDE
➔ Video: Android Studio doesn’t support plain java code any more what to do Now!
➔ Another IDE: Eclips, Intellij IDEA install it
➔ Open Intellij IDEA
↳ Create new process
↳ select java path to JDK
↳ Uncheck Project template Game
↳ Project Name: Hello world Right click res → new package →
org.mycode.helloworld
↳ Right click package Java Class Hellow
↳ pvsm : Public Static void main
↳ sout :System.out.print
↳ Right click curly brace - Run
↳ //Todo

Variable
➔ int, long, double, float
➔ Character: chat(‘\u :for Unicode), string: It is class in java others are data type
➔ Boolean

Operators
➔ +, -, *, /, %
➔ + can also use to add strings(Concatenate).

Relational Operator and Loop


➔ A++, a--
➔ >, <, ==, !=, >=, <= } comparison op
➔ ||, &&

◦ if(condition) {
Statements;
}
◦ if( condition){
Statement Block 1;
}
else{
Statement Block2;
}
◦ if-else if
➔ Switch (variable) {
Case1:Statement1; break;
Case2:Statement2; break;
………………………….
………………………….
default:default Statement; break;
}
Loops

◦ for (initialization; condition, updation){


Statement block:
}
◦ while(condition) {
Statement block;
updation;
}
◦ Continue: go to next Iteration doesn’t run remaining current iteration(drop a iteration)
◦ do{
Statement Block;
Updation;
}while (condition)
➔ Scanner scanner = new Scanner(System.in);
➔ int ans = Scanner.nextInt(); //read a integer from user input
➔ String name = Scanner next(); -string
➔ Random random= new Random();
➔ int num = random.nextInt();
inside brace give Domain. eg: bound: 20(this will give a random number between 0 –
20)

Task Game

• Show a welcome message


• concept, generate a random number and ask user to guess number, continue until you get the
number
• asking - after 5 time of guessing show Game over
• Ask user name and say hello
• Ask if we should Start
• After user’s positive response - generate random number and ask for user guess
• If right Guess show congratulation message and Quit the Game
• It not ask again
• As a hint, beside the first time, every time that you are asking for a number tell the user to
guess higher on lower
• if user fail 5 times show game over and quit
Simple Arrays

➔ Syntax 1:
Sting [] student = new String[]; //inside the square bracket size.
➔ Student [1] = "meisam" // inserting value
➔ String start from 0
➔ Syntax 2:
String[] employees = {"meisam" ,"Tom","Sarah"};
➔ int[] number = {1,2,3};
➔ numbers length – give the size of string (string length)
➔ for Comparing string we use
finddata.equals(data[i])
➔ Program to find number of a person from datas.

You might also like