IT ComputerProgramming1 Lesson2
IT ComputerProgramming1 Lesson2
Objectives:
Understand Java programming language
Discuss history of Java and Java Development
Understand Variables and Data types
Introduction
Java is a programming language. It is used to develop web
application, desktop application, mobile application and more. This lesson
will discuss how Java develop to use in technology trends.
Activity
1. What application is the most trend in this generation?
2. Any Idea about computer programming?
3. Were you able to create a program?
Analysis
1. Why do you think java is the most programming language now a
days?
2. What process can you create in programming?
Abstraction
a. The Basic Java Application
Java Applications with the Java class and method syntax in hand, we
can design a Java program. Java applications consist of one or more
classes that define data and behavior. Java applications are translated
into a distilled format by a Java compiler. This distilled format is nothing
more than a linear sequence of operation-operand(s) tuples:
What is Java?
Java is a popular programming language, created in 1995, owned
by Oracle, and Java can run 3 billion Devices and more
In Java, every application begins with a class name, and that class
name must have the same filename.
MyFirstProgram.java
class A (
int x= 20; // instance variable
static int y=10; // static variable
void method(){
int z=5; // local variable
}
}
Data Types
A data type can specify the different values and sizes that can be
assigned in the variable. There are two type of data types first is the
primitive and second is the non- primitive data types in java.
Output: 2.50
System.out.println(a); The example of a double data
System.out.println(Num); types
System.out.println(z);
System.out.println(b);
System.out.println(c);
}
Non–Primitive Data Types
Non-primitive Data types are not actually defined by the
programming language but these data types are created by the
programmer.
Non-Primitive Data types it refers to the objects and hence they called
it reference types.
Here are the Example of Non- primitive Data Types
Strings
It refers to an object. String object has methods that are used to
perform certain operations on strings.
These java.lang.String class it is used for creating a String object.
Array
Java in Array are the homogeneous data Structures implemented in
Java as Objects. An array can store one or more values of a specific data
types and provide indexed access store the same. Where a specific element
in an array is accessed by its index.
Classes
These is a blueprint in Java. A blueprint which includes all your data.
A Class contains fields(variables) and methods to describe the behavior of
an object.
Interfaces
Interface is like a class, where an interface can have method and
variables, but the methods declared in interface are by default abstract
(inly method signature, no body).
C. Java Operators
Java Operators
It is used to perform operations on variables and values.
Java divides the operators into the following groups:
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Bitwise Operators
Arithmetic Operators
These operators are used to perform the common mathematical
operations.
Assume that we have a two variable x & y which x =4, y= 2;
C <<= 2
is same as
<<= Left shift AND assignment operator.
C = C <<
2
C >>= 2
is same as
>>= Right shift AND assignment operator.
C = C >>
2
C &= 2 is
&= Bitwise AND assignment operator. same as C
=C&2
Comparison Operators
Comparison operators are used to compare two values.
Let x= 4, y =1;
Operator Example
== x==y
(Equal to) 4==1? The answer is false why?
It returns false because 4 is not equal to 3
!= x!=y
(Not Equal) 4! =1? Answer is true why? It returns true
because 4 in not equal to 1
> x>y
(Greater than) 4>1= True.
True because 4 is greater than 1
< x<y
(Less than) 4<1= False
Because 4 is not less than to 1
>= x>=y
(Greater than or equal x>y
to) 4>1= True.
True because 4 is greater than or equal to
1
<= x<=y
(Less than or equal to) 4<1= False
Because 4 is not less than or equal to 1
Logical Operators
Logical operators are used to determine the logic between variables
or values.
(A | B) will give
Binary OR Operator copies a bit if
| (bitwise or) 61 which is
it exists in either operand.
0011 1101
Methods Description
nextBoolean() Reads a boolean value from the user
nextByte() Reads a byte value from the user
nextDouble() Reads a double value from the user
nextFloat() Reads a float value from the user
nextInt() Reads a int value from the user
nextLine() Reads a String value from the user
nextLong() Reads a long value from the user
nextShort() Reads a short value from the user
Output /Display
Difference between println(), print() and printf()
print() - It prints string inside the quotes.
println() - It prints string inside the quotes similar like print()
method. Then the cursor moves to the beginning of the next line.
printf() - Tt provides string formatting (similar to printf in C/C++
programming).
Example: Display “Hello World” program.
*/
import java.util.Scanner;
class MySecondJavaProgram {
// String input
// Numerical input
}
Application: Analyze the problem below.
Encoding:
1. Create a program that will accept and display your name, age,
address and Contact number.
System.out.println("Hello Love");