LECTURE 2 (Gaya College of Engineering)

Similar documents
INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Selected Questions from by Nageshwara Rao

An overview of Java, Data types and variables

Administration. Classes. Objects Part II. Agenda. Review: Object References. Object Aliases. CS 99 Summer 2000 Michael Clarkson Lecture 7

COMP 110/L Lecture 7. Kyle Dewey

Kickstart Intro to Java Part I

Methods. Every Java application must have a main method.

CS 231 Data Structures and Algorithms, Fall 2016

Character Stream : It provides a convenient means for handling input and output of characters.

Getting started with Java

PROGRAMMING FUNDAMENTALS

Simple Java Programs. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment

Java: Comment Text. Introduction. Concepts

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

CP122 CS I. Iteration

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

COMP-202. Objects, Part III. COMP Objects Part III, 2013 Jörg Kienzle and others

13 th Windsor Regional Secondary School Computer Programming Competition

Activity 4: Methods. Content Learning Objectives. Process Skill Goals

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

BM214E Object Oriented Programming Lecture 8

Chapter 1 Introduction to Computers, Programs, and Java

COMP 202. More on OO. CONTENTS: static revisited this reference class dependencies method parameters variable scope method overloading

Programming Language Concepts: Lecture 2

Java Basic Programming Constructs

B.V. Patel Institute of BMC & IT, UTU 2014

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Static, Final & Memory Management

Java Tutorial. Saarland University. Ashkan Taslimi. Tutorial 3 September 6, 2011

Lecture 05: Methods. AITI Nigeria Summer 2012 University of Lagos.

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

1. Download the JDK 6, from

CS 335 Lecture 02 Java Programming

Creating Classes and Objects

Chapter 1 Introduction to Computers, Programs, and Java

CS Week 2. Jim Williams, PhD

CS 11 java track: lecture 1

Java Bytecode (binary file)

Lecture 6 Introduction to Objects and Classes

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

COMP15111: Introduction to Architecture

Introduction to Java

Methods and Data (Savitch, Chapter 5)

Class Libraries and Packages

Full file at

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

Computational Expression

( &% class MyClass { }

Chapter 4 Defining Classes I

Introduction to Java

THE CONCEPT OF OBJECT

Programming Language Concepts: Lecture 1

Lesson 01 Introduction

How to define your own classes that implement abstractions. How to pass information to methods and how methods return values.

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

COE318 Lecture Notes Week 3 (Week of Sept 17, 2012)

COMP 202. More on OO. CONTENTS: static revisited this reference class dependencies method parameters variable scope method overloading

CS111: PROGRAMMING LANGUAGE II

CHAPTER 7 OBJECTS AND CLASSES

Nested Loops. A loop can be nested inside another loop.

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Software Concepts. 2-8 Explain the process of translating and executing a Java program. How might the World Wide Web be involved?

Welcome to the Primitives and Expressions Lab!

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

Objects and Classes -- Introduction

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

Java Memory Management

1 Shyam sir JAVA Notes

STRUCTURING OF PROGRAM

Full file at

1.00 Tutorial 3. Methods, Classes Arrays & ArrayLists. September 26 & 27, 2005

Computer Programming, I. Laboratory Manual. Final Exam Solution

CS-140 Fall Binghamton University. Methods. Sect. 3.3, 8.2. There s a method in my madness.

Chapter 8 Objects and Classes Dr. Essam Halim Date: Page 1

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

Lecture 5: Methods CS2301

Lecture Set 4: More About Methods and More About Operators

Object-Oriented Programming Concepts

COE318 Lecture Notes Week 4 (Sept 26, 2011)

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!

Methods. Eng. Mohammed Abdualal

Programming. Syntax and Semantics

Class, Variable, Constructor, Object, Method Questions

Defining Classes and Methods

Chapter 5: Methods. by Tony Gaddis. Starting Out with Java: From Control Structures through Objects. Fourth Edition

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

Lec 7. for loops and methods

Chapter 1 Introduction to Java

Creating a Program in JCreator. JCreator is then used to create our program. But the first step is to create a new file.

Lecture 02, Fall 2018 Friday September 7

SDKs - Eclipse. SENG 403, Tutorial 2

Introduction to Java (All the Basic Stuff)

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

Transcription:

LECTURE 2 (Gaya College of Engineering) 1) CHARACTERISTICS OF OBJECTS: Object is an instance of a class. So, it is an active entity. Objects have three basic characteristics. They are- State: An object contains attributes or features. These attributes or features can be represented as the instance variables of an object. State can be defined as the values assigned to the attributes of an object. class Test int a; int b; void func_print() System.out.println( We are in the print function ); public static void main( String[ ] args) Test t = new Test(); t.a = 10; t.b = 20; System.out.println( The fisrt value : + t.a) System.out.println( The second value: + t.b) In the above program the object "t" of the class "Test have variables assigned to the values a = 10 and b = 20. The object ( or instance ) with these two values is called one state of the object. When we change the values of "a" and "b" then that would be another state of the object "t". Dhruba Jyoti Kalita Page 1

Identity: When an object is created in object oriented environment then unique identification number gets associated with the object which is called as Identity of the object. By using this Identity JVM can reference the object that it wants to access. In Garbage Collection Mechanism in java the unused objects in memory can be referred using the identity of the objects. Behavior: The processes by which objects acts to change its state to accomplish certain task is called as behavior of an object. In general the methods invoked by the object in an Object Oriented Environment is called as Behavior of that object. class Bank. float Calculate_Interest( float amount) float interest; float rate = 10; float time_period = 12 ; interest = (amount * rate* time_period) /100 return interest; public static void main(string[] args) Bank b = new Bank(); Dhruba Jyoti Kalita Page 2

float I; I = b. Calculate_Interest(10,00000); System.out.println( The interest is : +I) In the above java program the method Calculate_Interest( float amount) is the behavior of the object. 2) AN EXAMPLE OF A JAVA CODE : class Test public static void main(string[] args) String str = Gaya Engineering College ; System.out.println(str); The above code is a very basic code of java. The following are the points to be known to write a java program- Everything we do in java we do inside a class. ( Since java is a purely object oriented language) The execution of a java program starts from the main method. public It is an access specifier which makes the main method visible to the external sources. static- When static keyword is used in front of a method in java then that method can be accessed without creating object of the class to which it belongs. void void is a primitive data type. When we use this in front of a method then that function is not going to return anything. main main is the name of the function. Strings[] args This is argument list. When we send some arguments from the command line console to the program that is going to be consumed inside this array of arguments of type String. Following is the example which shows the use of this class Test public static void main(string[] args) Dhruba Jyoti Kalita Page 3

System.out.println( The first argument is : + args[0]) System.out.println( The second argument is : + args[1]) It is to be noted that when we send some arguments from the command line console it is going to be consumed in string format. Now if we execute the above program and pass some arguments to the program it will print those arguments. For example- // Assuming that the above program has been saved as test.java javac test.java java test gce gaya For the above execution it is going to pringt- gce gaya In the above code snippet by - String str = Gaya Engineering College ; We are assigning a value Gaya Engineering College to the variable str of type String. This is a static way of assigning a value to a java program. There are many other ways of assigning values in java dynamically during run time which we will learn in the next section. System.out.println(str); System is a class. out is an object. println() is a method Note: In the above out is an object of the class java.io.printstream. This out is an attribute of the class System and println() is a method of the class java.io.printstream. In the following the interpretation has been shown. Dhruba Jyoti Kalita Page 4

------- To be continued Dhruba Jyoti Kalita Page 5

Dhruba Jyoti Kalita Page 6