ARITHMETIC Operators
FLOATING POINT ARITHMETIC
Why answer is not more accurate ? double values are more accurate
Why it is called floating point?
c = ( 5.0 / 9 ) * (f - 32) gives actual result.
SHORT HAAND OPERATORS
FLOATING POINT ARITHMETIC
Why answer is not more accurate ? double values are more accurate
Why it is called floating point?
c = ( 5.0 / 9 ) * (f - 32) gives actual result.
SHORT HAAND OPERATORS
CHARACTER DATA TYPES
Java uses 16 bit char representation represents any possible character in the world is UNICODE character which also includes ASCII characters. it is represented by \u0000 to \uFFFF.
-------------------------------------------------------
public class NewUnicode {
Java uses 16 bit char representation represents any possible character in the world is UNICODE character which also includes ASCII characters. it is represented by \u0000 to \uFFFF.
-------------------------------------------------------
public class NewUnicode {
/**S K Nayak
* @param args
*/
public static void main(String[] args) {
// TODO unicode character testing
System.out.println("\u03b1 \u03b2 \u03b3 \u0b05 \u0b06");
//unicode char for A
System.out.println( (byte)('A'));
}
* @param args
*/
public static void main(String[] args) {
// TODO unicode character testing
System.out.println("\u03b1 \u03b2 \u03b3 \u0b05 \u0b06");
//unicode char for A
System.out.println( (byte)('A'));
}
}
α β γ ଅ ଆ
65
________________________________________________________check output _______________
α β γ ଅ ଆ
65
________________________________________________________check output _______________
*****************************
////////////////Lect - 5 Monday 08 August 2016 09:26:41 PM IST
=====================================================================
////////////////Lect - 5 Monday 08 August 2016 09:26:41 PM IST
=====================================================================
SHORTHAND OPERATORS
INCREMENT OPERATORS
ESCAPE SEQUENCES
STRING TYPES - String is not exactly a datatype, rather a predefined class. But we use it like reference type and use like datatype. + is used for concatenation .
-------------------------------------------------
public class Concat {
INCREMENT OPERATORS
ESCAPE SEQUENCES
STRING TYPES - String is not exactly a datatype, rather a predefined class. But we use it like reference type and use like datatype. + is used for concatenation .
-------------------------------------------------
public class Concat {
/**
* @param args
*/
public static void main(String[] args) {
// TODO concat
int a = 10;
int b = 20;
System.out.println(a+b);
System.out.println(a +""+ b );
String s = "Hallo";
System.out.println(s);
* @param args
*/
public static void main(String[] args) {
// TODO concat
int a = 10;
int b = 20;
System.out.println(a+b);
System.out.println(a +""+ b );
String s = "Hallo";
System.out.println(s);
}
}
30
1020
Hallo
-------------------------------------------------------
How to write in 2 lines of string in program
30
1020
Hallo
-------------------------------------------------------
How to write in 2 lines of string in program
LOGICAL OPERATORS
RELATIONAL OPERATORS
ASSIGNMENT OPERATOR
CONDITIONAL OPERATOR
RELATIONAL OPERATORS
ASSIGNMENT OPERATOR
CONDITIONAL OPERATOR
CONDITIONAL STATEMENTS - if...else
LOOPS
for loop is used when no of loops are known, while used when no of loops are not known, do- while used when statement to be used first.
LOOPS
for loop is used when no of loops are known, while used when no of loops are not known, do- while used when statement to be used first.
EXPLAIN THE JAVA PROGRAM
Every java application contains at least one class. it should contain main() method.
----------------------------------------------------
Program-1 Find largest number using simple if;
Program-2 Check even/ odd
Program-3 Check Prime
Program-4 Fahrenheit to Celsius
SINE series x - x^3/3! + x^5/5! - x^7/7! + ...
Every java application contains at least one class. it should contain main() method.
----------------------------------------------------
Program-1 Find largest number using simple if;
Program-2 Check even/ odd
Program-3 Check Prime
Program-4 Fahrenheit to Celsius
SINE series x - x^3/3! + x^5/5! - x^7/7! + ...
--------------------------xxxxxxxxxxxxxxxxxxxxxxxxxxxxx-------------------------
Lecture note Tuesday 09 August 2016 10:01:27 PM IST
##################################################################
Introduction to Array
_____________________
Array is provided to store fixed size sequential collection of data of same type.
Declaration
datatype[] arrayname; arrayname is reference variable.
example int[] a;
It does not allocate any space for array. It only creates a storage location for the reference to array name.
You can create an array using arrayname = new datatype[size];
##################################################################
Introduction to Array
_____________________
Array is provided to store fixed size sequential collection of data of same type.
Declaration
datatype[] arrayname; arrayname is reference variable.
example int[] a;
It does not allocate any space for array. It only creates a storage location for the reference to array name.
You can create an array using arrayname = new datatype[size];
for ex int[] a;
a = new int[100];
It means that it crates an array and assigns the reference to the variable arrayname.
a = new int[100];
It means that it crates an array and assigns the reference to the variable arrayname.
Also we can write - int[] marks = new int[60];
Array can be INITIALIZED AS FOLLOWS
int[] a = { 10, 20, 30, 40, 50, 60 };
Here new operator is not required.
int[] a = { 10, 20, 30, 40, 50, 60 };
Here new operator is not required.
---------------------------------------------------------
public class OccurenceLetters {
/**
* @param args
*/
public static void main(String[] args) {
// TODO SMALLEST INDEX OF LARGEST ELEMENT IN AN AAARY
int[] a = { 10, 20, 70, 40, 50, 60, 70,10, 25, 63 };
int max = a[0];
int index = 0;
for (int i = 1; i < 10; i++)
{
if ( a[i] > max)
{
max = a[i];
index = i;
}
}
System.out.println("Value is "+index);
* @param args
*/
public static void main(String[] args) {
// TODO SMALLEST INDEX OF LARGEST ELEMENT IN AN AAARY
int[] a = { 10, 20, 70, 40, 50, 60, 70,10, 25, 63 };
int max = a[0];
int index = 0;
for (int i = 1; i < 10; i++)
{
if ( a[i] > max)
{
max = a[i];
index = i;
}
}
System.out.println("Value is "+index);
}
}
Value is 2
=======================================================================
=======================================================================
Lecture Note Sunday 28 August 2016 09:49:40 PM IST
=======================================================================
INPUT USING Scanner s = new Scanner( System.in);
String x = s.next() ---- string
similarly s.nextByte(), s.nextShort() , s.nextInt();
Value is 2
=======================================================================
=======================================================================
Lecture Note Sunday 28 August 2016 09:49:40 PM IST
=======================================================================
INPUT USING Scanner s = new Scanner( System.in);
String x = s.next() ---- string
similarly s.nextByte(), s.nextShort() , s.nextInt();
OBJECT ORIENTED PROGRAMMING
Problem viewed as a set of objects and interaction between objects.
OBJECT is real world entity, Object occupies space. Object has identity that is state and behaviour. Example student, bankac, customer etc. So object consists of STATE/ DATA FIELD/INSTANCE VARIABLES AND BEHAVIOUR /METHODS. So data and methods are closely associated with each other.We say a circle is characterised by radius and method like area() and perimeter().
CLASS : Set of objects. A class is a blueprint which defines what will be the object's data and methods. A class does not occupy space. A class declares essential data and methods that will be shared among all objects.
So an object also called instance of a class. Ex customer is a class and Mr Roy is an object.
Problem viewed as a set of objects and interaction between objects.
OBJECT is real world entity, Object occupies space. Object has identity that is state and behaviour. Example student, bankac, customer etc. So object consists of STATE/ DATA FIELD/INSTANCE VARIABLES AND BEHAVIOUR /METHODS. So data and methods are closely associated with each other.We say a circle is characterised by radius and method like area() and perimeter().
CLASS : Set of objects. A class is a blueprint which defines what will be the object's data and methods. A class does not occupy space. A class declares essential data and methods that will be shared among all objects.
So an object also called instance of a class. Ex customer is a class and Mr Roy is an object.
OBJECT ORIENTED CONCEPTS
ENCAPSULATION : Details of class is hidden and user does not know. For ex We can create a circle object and compute area without knowing how area is calculated in detail.
ABSTRACTION : Separation of class implementation from use of a class. we can build a computer system by knowing how the components interact with each other.
CLASS
OBJECT
INHERITANCE
POLYMORPHISM
Reference variables
Objects can be accessed by using reference variables. Circle mycircle; mycircle =new Circle();you can combine also.
Object reference variable and objects are different. More correctly mycircle is a variable that contains reference to Circle object. Array name is actually an object.
CLASS
OBJECT
INHERITANCE
POLYMORPHISM
Reference variables
Objects can be accessed by using reference variables. Circle mycircle; mycircle =new Circle();you can combine also.
Object reference variable and objects are different. More correctly mycircle is a variable that contains reference to Circle object. Array name is actually an object.
DIAGRAM for circle class
Circle -------------class name
________________________
radius:double -------------Data fields
________________________
getArea() -------------Methods / constructors
Circle()
_______________________
Circle -------------class name
________________________
radius:double -------------Data fields
________________________
getArea() -------------Methods / constructors
Circle()
_______________________
Object diagram
circle1:Circle
______________
radius = 10
______________
circle1:Circle
______________
radius = 10
______________
A class contains declaration for INSTANCE VARIABLES and definition for methods.ACCESS OBJECT's data and methods by dot , called object member access operator.
For Ex circle1.radius = 10; PROVIDED radius is public.
Then you can declare methods. Create objects of the class and access the members and methods by using dot operator.
PROGRAM
public class Circle {
double radius;
double getArea(){
return radius * radius * Math.PI;
}
For Ex circle1.radius = 10; PROVIDED radius is public.
Then you can declare methods. Create objects of the class and access the members and methods by using dot operator.
PROGRAM
public class Circle {
double radius;
double getArea(){
return radius * radius * Math.PI;
}
public static void main(String[] args) {
// TODO Area of circle object
Circle myCircle = new Circle();
myCircle.radius = 10.1;
double area = myCircle.getArea();
System.out.println("Area = " +area);
}
// TODO Area of circle object
Circle myCircle = new Circle();
myCircle.radius = 10.1;
double area = myCircle.getArea();
System.out.println("Area = " +area);
}
}
Area = 320.4738665926948
Area = 320.4738665926948
======================================================
======================================================
======================================================
Wednesday 14 September 2016 07:51:13 AM IST
Lecture note
As we discussed above how to use instance variables and instance methods.
However we can use normal methods like use main method, then other methods called normal methods. We can define main method , other methods and call the methods within main method. Since any java program resides within a class, methods must be static. Like main method as main is called by the operating system without the help of an object. similarly a STATIC METHOD can be called without the help of an object, that means inside main directly referring by the method name.So STATIC methods can be called directly WITHIN THE SAME CLASS.
So you can use instance variable, methods or normal methods as when required.
Lecture note
As we discussed above how to use instance variables and instance methods.
However we can use normal methods like use main method, then other methods called normal methods. We can define main method , other methods and call the methods within main method. Since any java program resides within a class, methods must be static. Like main method as main is called by the operating system without the help of an object. similarly a STATIC METHOD can be called without the help of an object, that means inside main directly referring by the method name.So STATIC methods can be called directly WITHIN THE SAME CLASS.
So you can use instance variable, methods or normal methods as when required.
public class SimpleMethod {
/**
* @param args
*/
public static void main(String[] args) {
// TODO use simple mehtods
double r = 10.5;
double area = getArea(r);
System.out.println(area);
* @param args
*/
public static void main(String[] args) {
// TODO use simple mehtods
double r = 10.5;
double area = getArea(r);
System.out.println(area);
}
static double getArea(double radius){
return radius*radius*Math.PI;
}
static double getArea(double radius){
return radius*radius*Math.PI;
}
}
346.3605900582747
346.3605900582747
PROGRAM - - Write a program get larger of x and y in a class where x and y are private instance variables of that class
public class PrivateDemo {
public class PrivateDemo {
/**
* Find larger of two private members of a class
*/
private int x;
private int y;
public static void main(String[] args) {
// TODO make data private
PrivateDemo p = new PrivateDemo();
p.getValue(10, 99);
p.larger();
}
void getValue(int a,int b) {
x = a;
y = b;
}
void larger(){
if( x>y )
System.out.println(x);
else
System.out.println(y);
}
}
* Find larger of two private members of a class
*/
private int x;
private int y;
public static void main(String[] args) {
// TODO make data private
PrivateDemo p = new PrivateDemo();
p.getValue(10, 99);
p.larger();
}
void getValue(int a,int b) {
x = a;
y = b;
}
void larger(){
if( x>y )
System.out.println(x);
else
System.out.println(y);
}
}
99
S K Nayak
Ph . 9938103308
Ph . 9938103308
No comments:
Post a Comment