This document discusses an introduction to object oriented programming presented by Bikash Choudhury. It covers why OOP was developed, including making code reusable and preventing unwanted access. It also discusses the history and development of Java, including how it addressed issues with C++ being machine dependent. Finally, it provides instructions on how to write, compile, and run a basic Java program, and defines key Java terms like JDK, JRE, and JVM.
The document provides information about a laboratory manual for an Object Oriented Programming course with Java. It includes the vision and mission statements of the institution and computer science departments. It then details the course objectives, outcomes, system requirements and introduces topics that will be covered like installing Java Development Kit and an introduction to object oriented programming concepts. It provides an example program to find the roots of a quadratic equation to demonstrate Java fundamentals.
This document introduces CETPA as a missing link to help bridge the gap between engineering graduates and jobs in the technology sector. It provides an overview of CETPA's training programs in computer programming concepts, data structures, web technology, and projects. The document also discusses the Java programming language and its versions, and explains concepts like generations of programming languages, Java virtual machines, and Java application programming interfaces.
This document discusses Java programming and provides an overview of Java technology. It explains that Java is an object-oriented programming language and platform that is architecture neutral, portable, distributed, and robust. The document then discusses Java versions like J2SE, J2EE, and J2ME. It also covers topics like Java applications development using an IDE like NetBeans and running Java programs on Windows and Linux systems.
The document provides an introduction to Java and object-oriented programming concepts. It discusses how computer programs are based on algorithms and step-by-step instructions. It then explains procedural programming versus object-oriented programming, with examples like C++ and Java listed as OOP languages. The basics of classes, objects, encapsulation, inheritance, and polymorphism are defined as core OOP concepts. Finally, it provides an overview of the Java programming language and environment.
This document provides an introduction to object-oriented programming (OOP) and Java. It begins by explaining the differences between structured and object-oriented programming paradigms. Structured programming uses procedures that operate on separate data, while OOP focuses on creating objects that combine data and procedures. The document then discusses some disadvantages of structured programming and introduces key concepts of OOP like objects, classes, encapsulation, and inheritance. It provides examples of these concepts in Java and describes the Java programming environment, including the Java Development Kit and standard library. It also explains how to write, compile, and run a simple "Hello World" Java program.
The document discusses and compares two popular ActionScript frameworks: PureMVC and Robotlegs. It provides an overview of why frameworks are used, describes some common design patterns implemented in frameworks, and highlights key features and strengths/weaknesses of PureMVC and Robotlegs.
Java was developed in 1991 by Sun Microsystems as part of the Green project. A team member named James Gosling grew dissatisfied with C++ and created a new language called Oak, which was later renamed to Java in 1995 by Sun Microsystems. Java is an object-oriented language that is platform independent, robust, reliable, secure, and has features like compilation to bytecode, dynamic binding, and multithreading.
This document provides an overview of the Programming in Java (CSE4308) course. The course modules cover Java programming fundamentals, data types, control statements, classes and methods, inheritance, packages, interfaces, exception handling, multithreading, input/output, and GUI programming with JavaFX. The course objectives are to understand object-oriented programming concepts in Java like classes, objects, abstraction, encapsulation, inheritance, and polymorphism, and to create packages and GUI applications. The textbook for the course is also listed.
The document provides information about a laboratory manual for an Object Oriented Programming course with Java. It includes the vision and mission statements of the institution and computer science departments. It then details the course objectives, outcomes, system requirements and introduces topics that will be covered like installing Java Development Kit and an introduction to object oriented programming concepts. It provides an example program to find the roots of a quadratic equation to demonstrate Java fundamentals.
This document introduces CETPA as a missing link to help bridge the gap between engineering graduates and jobs in the technology sector. It provides an overview of CETPA's training programs in computer programming concepts, data structures, web technology, and projects. The document also discusses the Java programming language and its versions, and explains concepts like generations of programming languages, Java virtual machines, and Java application programming interfaces.
This document discusses Java programming and provides an overview of Java technology. It explains that Java is an object-oriented programming language and platform that is architecture neutral, portable, distributed, and robust. The document then discusses Java versions like J2SE, J2EE, and J2ME. It also covers topics like Java applications development using an IDE like NetBeans and running Java programs on Windows and Linux systems.
The document provides an introduction to Java and object-oriented programming concepts. It discusses how computer programs are based on algorithms and step-by-step instructions. It then explains procedural programming versus object-oriented programming, with examples like C++ and Java listed as OOP languages. The basics of classes, objects, encapsulation, inheritance, and polymorphism are defined as core OOP concepts. Finally, it provides an overview of the Java programming language and environment.
This document provides an introduction to object-oriented programming (OOP) and Java. It begins by explaining the differences between structured and object-oriented programming paradigms. Structured programming uses procedures that operate on separate data, while OOP focuses on creating objects that combine data and procedures. The document then discusses some disadvantages of structured programming and introduces key concepts of OOP like objects, classes, encapsulation, and inheritance. It provides examples of these concepts in Java and describes the Java programming environment, including the Java Development Kit and standard library. It also explains how to write, compile, and run a simple "Hello World" Java program.
The document discusses and compares two popular ActionScript frameworks: PureMVC and Robotlegs. It provides an overview of why frameworks are used, describes some common design patterns implemented in frameworks, and highlights key features and strengths/weaknesses of PureMVC and Robotlegs.
Java was developed in 1991 by Sun Microsystems as part of the Green project. A team member named James Gosling grew dissatisfied with C++ and created a new language called Oak, which was later renamed to Java in 1995 by Sun Microsystems. Java is an object-oriented language that is platform independent, robust, reliable, secure, and has features like compilation to bytecode, dynamic binding, and multithreading.
This document provides an overview of the Programming in Java (CSE4308) course. The course modules cover Java programming fundamentals, data types, control statements, classes and methods, inheritance, packages, interfaces, exception handling, multithreading, input/output, and GUI programming with JavaFX. The course objectives are to understand object-oriented programming concepts in Java like classes, objects, abstraction, encapsulation, inheritance, and polymorphism, and to create packages and GUI applications. The textbook for the course is also listed.
This document is a Master's thesis submitted to the Czech Technical University in Prague that examines the Java EE 7 Batch API and develops a graphical editor for configuring batch job structures in Java EE 7. The thesis provides an overview of the Java EE 7 Batch API, analyzes existing batch configuration tools, designs a graphical editor that extends the JBoss Tools project, implements the editor, and evaluates it through demonstrations, usability testing, and integration into JBoss Tools.
Software development has shifted focus from efficiency to productivity, reusability, and user-friendliness. Object-oriented programming (OOP) models objects that contain data and methods. Key OOP concepts include inheritance, where subclasses extend and modify superclass features. An integrated development environment (IDE) combines tools like editors, compilers, linkers, and debuggers. Java uses a hybrid approach of compiling to bytecode, then interpreting for platform independence. Console applications use text input/output. Graphical user interface (GUI) applications use menus and buttons. Applets run in web browsers.
The document provides an overview of a presentation on core Java concepts including details about the Encapsulate Logics institute where the presentation will take place, background on Java founder James Gosling, definitions and characteristics of Java, and versions of the Java Development Kit. Key aspects of object-oriented programming such as encapsulation, inheritance, and polymorphism are also explained. The presentation aims to impart programming skills and practical concepts of Java to students.
The Yahoo UI (YUI) Library is well known for its excellent documentation. One of its secrets is YUI Doc, a Python application used at build time to generate API documentation for JavaScript code.
But is YUI Doc really better than JS Doc Toolkit -- an elder application, written in JavaScript, that also generates API documentation. When should you choose one over the other? Which is the better choice for your project?
Vibrant Technologies is headquarted in Mumbai,India.We are the best Java training provider in Navi Mumbai who provides Live Projects to students.We provide Corporate Training also.We are Best Java classes in Mumbai according to our students and corporators
The document discusses the Android Native Development Kit (NDK). It provides tools to embed native C/C++ code and package it into an Android application. The NDK allows using native code for tasks like games that require high performance. It works with the Java Native Interface (JNI) to interface between native code and Java code.
The document discusses procedural programming versus object-oriented programming and provides examples using Java. It defines procedural programming as dividing a program into subprocedures that perform specific tasks, with most data shared globally. Object-oriented programming is defined as partitioning memory for both data and functions using objects. The document then outlines key concepts of OOP like objects, classes, encapsulation, and polymorphism. It provides history on the development of Java and its advantages over C++ as a simpler, safer, and more robust language.
Introduction to Behavior Driven Development Robin O'Brien
This document provides an introduction to Behaviour Driven Development (BDD). It discusses that BDD aims to bridge communication gaps between developers and clients by using examples written in a common language. It also provides a practical example of setting up BDD with JBehave and Java in IntelliJ IDEA, including creating a story file, steps class, and linking class. The document demonstrates how BDD allows describing desired system behaviors in a way that is understandable to both technical and non-technical stakeholders.
Java Is A Programming Dialect And Registering Stage EssayLiz Sims
Java is a programming language and runtime environment that is widely used. It allows applications to be written once and run on any device, from laptops to servers to mobile phones. Java code is compiled to bytecode that can run on any Java Virtual Machine, regardless of computer architecture. Java is commonly used for web applications and has millions of developers. Integrated Development Environments are software applications that help programmers develop code. They provide features like code editing, debugging, and project management tailored for specific programming languages. Android is an open source platform that makes developing mobile applications easy. This document discusses advantages and disadvantages of using the Android platform for developing a mobile application to automate business processes for a fitness center.
The document describes a Java programming assignment that involves designing and implementing a student record keeping system. It includes:
1) An introduction to Java and how it has become a popular programming language due to its flexibility across desktop and server environments.
2) Details on designing classes like Person, Player, and Goalkeeper to represent different types of students as part of the record keeping system.
3) Implementation of the design in Java, including defining relationships between objects, implementing behaviors and error handling, and using an integrated development environment.
4) Testing and documenting the Java solution, including creating user and technical documentation.
Here are some recommendations based on the feedback:
- Improve commenting throughout the code to better explain the logic and flow. This will help future programmers understand and maintain the code more easily.
- Add stronger validation checks for input data types. The program currently allows some incorrect data type inputs without errors. Tightening these checks will make the program more robust.
- Consider adding more test cases to the test plan that validate edge cases like incorrect data types, empty/null values, large amounts of data etc. This will help identify additional bugs or areas for improvement.
- Refactor code for readability where possible. For example, long methods could be broken into smaller private methods with descriptive names. This will make the
The document provides an introduction to programming in Java, including:
1. Installing the Java Development Kit (JDK) is necessary to both compile and run Java applications on a variety of operating systems.
2. Two methods for starting to program in Java are presented: using the shell to run Java code manually, or using the Eclipse integrated development environment.
3. Key Java concepts like classes, objects, inheritance, abstraction, and encapsulation are defined to help new programmers understand object-oriented programming principles in Java.
The document provides an introduction to programming in Java, including:
1. Installing the Java Development Kit (JDK) is necessary to both compile and run Java applications on a variety of operating systems.
2. Two methods for starting to program in Java are presented: using the shell to run Java code manually, or using the Eclipse integrated development environment.
3. Key Java concepts like classes, objects, inheritance, abstraction, and encapsulation are defined to help new programmers understand object-oriented programming principles in Java.
This document describes a Java to C compiler (J2CC) that was designed to reduce the time complexity of Java programs by compiling them into C code. The compiler combines the robustness of Java with the speed of C. It analyzes and compares Java and C in terms of execution time and memory usage, showing Java is slower. The architectural design of J2CC includes lexical analysis, syntax analysis using a LALR parser, semantic analysis, and target C code generation. Tools like JLex are used for lexical analysis and CUP is used for parsing. The goal is to eliminate the Java virtual machine and compile optimized C code for embedded systems.
Java is an object-oriented programming language that is platform independent. It was created in 1995 by Sun Microsystems with James Gosling as the lead developer. Java programs are first compiled into bytecode, which can run on any Java Virtual Machine (JVM) regardless of computer hardware or operating system. This allows Java programs to run on any platform that supports Java without being recompiled.
Vibrant Technologies is headquarted in Mumbai,India.We are the best Java training provider in Navi Mumbai who provides Live Projects to students.We provide Corporate Training also.We are Best Java classes in Mumbai according to our students and corporators
Global Earthquake Monitor. This project based on Java Project. It is real time working project. This project used OOPs concept.
World earthquake shown in map with magnitude, date, time, length, affected area.
This document describes a student project titled "Car Showroom System". It includes an introduction to the project, which aims to facilitate transactions through an electronic medium for a car showroom. It also includes sections on preliminary design, form layouts, database design, implementation, and more. The document provides information on the tools and technologies used, including Java, Swing, and SQL.
The document provides an analysis of Shuzworld's workflow, costs, and staffing at its Shanghai production facility. It recommends streamlining the 8-step work boot production process into a 5-workstation assembly line to improve efficiency. It justifies this recommendation using assembly line data and balancing tools. It also recommends using a learning curve analysis to determine pricing for a new sandal product line that maximizes profit margins. Finally, it recommends an assignment method for scheduling operators to maximize production while minimizing costs based on each operator's job costs.
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page pmgdscunsri
Figma is a cloud-based design tool widely used by designers for prototyping, UI/UX design, and real-time collaboration. With features such as precision pen tools, grid system, and reusable components, Figma makes it easy for teams to work together on design projects. Its flexibility and accessibility make Figma a top choice in the digital age.
This document is a Master's thesis submitted to the Czech Technical University in Prague that examines the Java EE 7 Batch API and develops a graphical editor for configuring batch job structures in Java EE 7. The thesis provides an overview of the Java EE 7 Batch API, analyzes existing batch configuration tools, designs a graphical editor that extends the JBoss Tools project, implements the editor, and evaluates it through demonstrations, usability testing, and integration into JBoss Tools.
Software development has shifted focus from efficiency to productivity, reusability, and user-friendliness. Object-oriented programming (OOP) models objects that contain data and methods. Key OOP concepts include inheritance, where subclasses extend and modify superclass features. An integrated development environment (IDE) combines tools like editors, compilers, linkers, and debuggers. Java uses a hybrid approach of compiling to bytecode, then interpreting for platform independence. Console applications use text input/output. Graphical user interface (GUI) applications use menus and buttons. Applets run in web browsers.
The document provides an overview of a presentation on core Java concepts including details about the Encapsulate Logics institute where the presentation will take place, background on Java founder James Gosling, definitions and characteristics of Java, and versions of the Java Development Kit. Key aspects of object-oriented programming such as encapsulation, inheritance, and polymorphism are also explained. The presentation aims to impart programming skills and practical concepts of Java to students.
The Yahoo UI (YUI) Library is well known for its excellent documentation. One of its secrets is YUI Doc, a Python application used at build time to generate API documentation for JavaScript code.
But is YUI Doc really better than JS Doc Toolkit -- an elder application, written in JavaScript, that also generates API documentation. When should you choose one over the other? Which is the better choice for your project?
Vibrant Technologies is headquarted in Mumbai,India.We are the best Java training provider in Navi Mumbai who provides Live Projects to students.We provide Corporate Training also.We are Best Java classes in Mumbai according to our students and corporators
The document discusses the Android Native Development Kit (NDK). It provides tools to embed native C/C++ code and package it into an Android application. The NDK allows using native code for tasks like games that require high performance. It works with the Java Native Interface (JNI) to interface between native code and Java code.
The document discusses procedural programming versus object-oriented programming and provides examples using Java. It defines procedural programming as dividing a program into subprocedures that perform specific tasks, with most data shared globally. Object-oriented programming is defined as partitioning memory for both data and functions using objects. The document then outlines key concepts of OOP like objects, classes, encapsulation, and polymorphism. It provides history on the development of Java and its advantages over C++ as a simpler, safer, and more robust language.
Introduction to Behavior Driven Development Robin O'Brien
This document provides an introduction to Behaviour Driven Development (BDD). It discusses that BDD aims to bridge communication gaps between developers and clients by using examples written in a common language. It also provides a practical example of setting up BDD with JBehave and Java in IntelliJ IDEA, including creating a story file, steps class, and linking class. The document demonstrates how BDD allows describing desired system behaviors in a way that is understandable to both technical and non-technical stakeholders.
Java Is A Programming Dialect And Registering Stage EssayLiz Sims
Java is a programming language and runtime environment that is widely used. It allows applications to be written once and run on any device, from laptops to servers to mobile phones. Java code is compiled to bytecode that can run on any Java Virtual Machine, regardless of computer architecture. Java is commonly used for web applications and has millions of developers. Integrated Development Environments are software applications that help programmers develop code. They provide features like code editing, debugging, and project management tailored for specific programming languages. Android is an open source platform that makes developing mobile applications easy. This document discusses advantages and disadvantages of using the Android platform for developing a mobile application to automate business processes for a fitness center.
The document describes a Java programming assignment that involves designing and implementing a student record keeping system. It includes:
1) An introduction to Java and how it has become a popular programming language due to its flexibility across desktop and server environments.
2) Details on designing classes like Person, Player, and Goalkeeper to represent different types of students as part of the record keeping system.
3) Implementation of the design in Java, including defining relationships between objects, implementing behaviors and error handling, and using an integrated development environment.
4) Testing and documenting the Java solution, including creating user and technical documentation.
Here are some recommendations based on the feedback:
- Improve commenting throughout the code to better explain the logic and flow. This will help future programmers understand and maintain the code more easily.
- Add stronger validation checks for input data types. The program currently allows some incorrect data type inputs without errors. Tightening these checks will make the program more robust.
- Consider adding more test cases to the test plan that validate edge cases like incorrect data types, empty/null values, large amounts of data etc. This will help identify additional bugs or areas for improvement.
- Refactor code for readability where possible. For example, long methods could be broken into smaller private methods with descriptive names. This will make the
The document provides an introduction to programming in Java, including:
1. Installing the Java Development Kit (JDK) is necessary to both compile and run Java applications on a variety of operating systems.
2. Two methods for starting to program in Java are presented: using the shell to run Java code manually, or using the Eclipse integrated development environment.
3. Key Java concepts like classes, objects, inheritance, abstraction, and encapsulation are defined to help new programmers understand object-oriented programming principles in Java.
The document provides an introduction to programming in Java, including:
1. Installing the Java Development Kit (JDK) is necessary to both compile and run Java applications on a variety of operating systems.
2. Two methods for starting to program in Java are presented: using the shell to run Java code manually, or using the Eclipse integrated development environment.
3. Key Java concepts like classes, objects, inheritance, abstraction, and encapsulation are defined to help new programmers understand object-oriented programming principles in Java.
This document describes a Java to C compiler (J2CC) that was designed to reduce the time complexity of Java programs by compiling them into C code. The compiler combines the robustness of Java with the speed of C. It analyzes and compares Java and C in terms of execution time and memory usage, showing Java is slower. The architectural design of J2CC includes lexical analysis, syntax analysis using a LALR parser, semantic analysis, and target C code generation. Tools like JLex are used for lexical analysis and CUP is used for parsing. The goal is to eliminate the Java virtual machine and compile optimized C code for embedded systems.
Java is an object-oriented programming language that is platform independent. It was created in 1995 by Sun Microsystems with James Gosling as the lead developer. Java programs are first compiled into bytecode, which can run on any Java Virtual Machine (JVM) regardless of computer hardware or operating system. This allows Java programs to run on any platform that supports Java without being recompiled.
Vibrant Technologies is headquarted in Mumbai,India.We are the best Java training provider in Navi Mumbai who provides Live Projects to students.We provide Corporate Training also.We are Best Java classes in Mumbai according to our students and corporators
Global Earthquake Monitor. This project based on Java Project. It is real time working project. This project used OOPs concept.
World earthquake shown in map with magnitude, date, time, length, affected area.
This document describes a student project titled "Car Showroom System". It includes an introduction to the project, which aims to facilitate transactions through an electronic medium for a car showroom. It also includes sections on preliminary design, form layouts, database design, implementation, and more. The document provides information on the tools and technologies used, including Java, Swing, and SQL.
The document provides an analysis of Shuzworld's workflow, costs, and staffing at its Shanghai production facility. It recommends streamlining the 8-step work boot production process into a 5-workstation assembly line to improve efficiency. It justifies this recommendation using assembly line data and balancing tools. It also recommends using a learning curve analysis to determine pricing for a new sandal product line that maximizes profit margins. Finally, it recommends an assignment method for scheduling operators to maximize production while minimizing costs based on each operator's job costs.
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page pmgdscunsri
Figma is a cloud-based design tool widely used by designers for prototyping, UI/UX design, and real-time collaboration. With features such as precision pen tools, grid system, and reusable components, Figma makes it easy for teams to work together on design projects. Its flexibility and accessibility make Figma a top choice in the digital age.
ARENA - Young adults in the workplace (Knight Moves).pdfKnight Moves
Presentations of Bavo Raeymaekers (Project lead youth unemployment at the City of Antwerp), Suzan Martens (Service designer at Knight Moves) and Adriaan De Keersmaeker (Community manager at Talk to C)
during the 'Arena • Young adults in the workplace' conference hosted by Knight Moves.
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANEFebless Hernane
CapCut is an easy-to-use video editing app perfect for beginners. To start, download and open CapCut on your phone. Tap "New Project" and select the videos or photos you want to edit. You can trim clips by dragging the edges, add text by tapping "Text," and include music by selecting "Audio." Enhance your video with filters and effects from the "Effects" menu. When you're happy with your video, tap the export button to save and share it. CapCut makes video editing simple and fun for everyone!
Discovering the Best Indian Architects A Spotlight on Design Forum Internatio...Designforuminternational
India’s architectural landscape is a vibrant tapestry that weaves together the country's rich cultural heritage and its modern aspirations. From majestic historical structures to cutting-edge contemporary designs, the work of Indian architects is celebrated worldwide. Among the many firms shaping this dynamic field, Design Forum International stands out as a leader in innovative and sustainable architecture. This blog explores some of the best Indian architects, highlighting their contributions and showcasing the most famous architects in India.
Explore the essential graphic design tools and software that can elevate your creative projects. Discover industry favorites and innovative solutions for stunning design results.
Virtual Tour Application Powerpoint for museum of edinburgh
opps.pptx
1. Object Oriented Programming (PCC-
CS503)
Bikash Choudhury
Assistant Professor
Department of Computer Science & Engineering
Ramkrishna Mahato Government Engineering College
Purulia
September 28, 2021
Bikash Choudhury (RKMGECP) OOPS September 28,2021 1/68
2. Content
s
1 Why Object Oriented Programming
Why Object-Oriented
programming? Why Java?
Literature of Java
2 Entire Execution Process in Java
How to Write and Execute Java
Program Input and Output in Java
Strings
Introduction to
OOPS Methods
Bikash Choudhury (RKMGECP) OOPS September 28,2021 2/68
3. Why Object-Oriented
Programming?
Object
1. Philosophically an object is anything that really exists in the world
and can be distinguished from others. Everything that we see
physically like, every human being, a book, a dog, a tree etc. are
the example of object.
2. In computer science, an object can be a variable, a data
structure, a function, or a method, and as such, is a value in
memory referenced by an identifier.
3. In the class-based and object-oriented programming paradigms,
object refers to a particular instance of a class, where the object
can be a combination of variables, functions, and data
structures.
4. In the relational model of database management, an object can be
a table or column, or an association between data and a database
entity (such as relating a person’s age to a specific person) [...
wiki]
Bikash Choudhury (RKMGECP) OOPS September 28,2021 3/68
4. What is Object Oriented
Programming?
Object Oriented Programming
1.Object Oriented programming (OOP) is a programming paradigm
that relies on the concept of classes and objects. It is used to
structure a software program into simple, reusable pieces of code
blueprints (usually called classes) which are used to create
individual instances of objects.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 4/68
5. Why Object-Oriented
Programming?
1.OOP makes code organized, reusable and easy to maintain. It
follows the DRY (Dont Repeat Yourself) principle used by many
programmers to make efficient programs.
2.OOP also prevents unwanted access to data, or exposing
proprietary code through encapsulation and abstraction.
3.So how do programmers create Object Oriented programs? Well
the short answer is by making classes, and creating objects from
the classes. Classes form the blueprint for how data & behaviors
are structured.
4.Most programming languages are a mix of different ways of
writing computer programs. For example, Python allows for
computer programs to be written both in object-oriented
programming and in procedural programming. There are many
programming languages that allow you to write computer
programs in object-oriented programming. Some of these
programming languages are: C++, Java, Ruby, Perl, Emarald,
Sapphire, PHP, Python, etc. [...wiki]
Bikash Choudhury (RKMGECP) OOPS September 28,2021 5/68
6. Why
Java?
P e n t i u m P r o c e s s o r
W i n d o w s O / S
C e l e r o n P r o c e s s o r
U b u n t u O / S
S p a r k P r o c e s s o r
M a c O / S
1 . I n s t r u c t i o n ( a d d a , b )
2 . E x t e n s i o n ( T e s t . e x e )
1 . I n s t r u c t i o n ( a a d d b )
2 . E x t e n s i o n ( T es t . o u t )
Figure:Difficulties in M/C Dependent
Program
1 CC + + is not suitable for developing software forInternet.
2 What to do?
Bikash Choudhury (RKMGECP) OOPS September 28,2021 6/68
7. Why
Java?
S a m p l e . o u t /
S a m p l e . e x e
( M a c h i n e C o d e )
O u t p u t
S a m p l e . c l a s s
( B y t e C o d e )
M a c h i n e C o d e
( J V M )
S a m p l e . j a v a
( S o u r c e C o d e )
C o m p i l e r
S a m p l e . c
C o m p i l e r
E x e c u t e
O u t p u t
C o m p i l e r o f J V M
E x e c u t e
Figure:Difficulties in M/C Dependent
Program
Bikash Choudhury (RKMGECP) OOPS September 28,2021 7/68
8. Why
Java?
S a m p l e . o u t /
S a m p l e . e x e
( M a c h i n e C o d e )
O u t p u t
S a m p l e . c l a s s
( B y t e C o d e )
S a m p l e . j a v a
( S o u r c e C o d e )
C o m p i l e r
S a m p l e . c
C o m p i l e r
E x e c u t e
O u t p u t
C o m p i l e r o f J V M
M a c h i n e C o d e
( J V M )
E x e c u t e
M / C I n d e p e n d e n t
M / C D e p e n d e n t
Figure:Difficulties in M/C Dependent
Program
Bikash Choudhury (RKMGECP) OOPS September 28,2021 8/68
9. Literature of
Java
In 1990, Sun Microsystems Inc.(US) has conceived a project to
develop s/w consumer electronic devices that could be controlled
bya remote. This project was called Stealth Project but later its
name was changed toGreen Project.
In 1991, Bill Joy, James Gosling and their team has several
discussions regarding the project. Gosling thought CC + + could
be used to develop the project.
As CC + + is m/c dependent, Gosling starts to develop new
language for the aforesaid project. This language initially
calledOak. Later it was changed toJAVA.
Why the name JAVA?
In 1994,WebRunnera Java based web browser was developed
later renamed it asHotJava.
HotJava was the first browser, having the capabilities of
executing applets(programs designed to run dynamically in
internet).
Bikash Choudhury (RKMGECP) OOPS September 28,2021 9/68
10. Literature of
Java
Sun formally announcedJavaandHotJavaatSun
Worldconference in 1995. Later, Netscape, Microsoft
announced that they would support Java in their web
browser.
On January 23rd 1996,JDK 1.0version was released.
Now, more than 9 million developers use java and more than 4
billion electronics devices, including mobile phones and TVs, run
on Java.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 10/68
12. How to Write and Execute Java
Program
1 First installJREandJDK. Check whether JRE and JDK
installed properly or not!
Next, open any text editor, write the code and save the file
with ‘.java’extension.
Next, to compile the code, open the terminal and enter to the
folder where recently created ‘.java’ file reside. Next, writejavac
filename.java.
After compilation, compiler generates‘.class’file.
To run the ‘.class’ file write in the terminaljava ‘filename.class’.
2
3
4
5
Bikash Choudhury (RKMGECP) OOPS September 28,2021 12/68
13. JRE and JDK Installation
Procedure
1.open terminal and enter the below
command
Figure:Check JRE and JDK are installed or
not!
Bikash Choudhury (RKMGECP) OOPS September 28,2021 13/68
14. JRE and JDK Installation
Procedure
2.open terminal and enter the below
command
Figure:Install
JRE
Bikash Choudhury (RKMGECP) OOPS September 28,2021 14/68
15. JRE and JDK Installation
Procedure
3.open terminal and enter the below
command
Figure:Install
JRE
Bikash Choudhury (RKMGECP) OOPS September 28,2021 15/68
16. JRE and JDK Installation
Procedure
4.open terminal and enter the below
command
Figure:Install
JRE
Bikash Choudhury (RKMGECP) OOPS September 28,2021 16/68
17. JRE and JDK Installation
Procedure
5.open terminal and enter the below command to install the
JDK
Figure:Install
JDK
Bikash Choudhury (RKMGECP) OOPS September 28,2021 17/68
18. JRE and JDK Installation
Procedure
6.open terminal and enter the below
command
Figure:Install
JDK
Bikash Choudhury (RKMGECP) OOPS September 28,2021 18/68
19. How to Write and Execute Java
Program
1 First installJREandJDK. Check whether JRE and JDK
installed properly or not!
Next, open any text editor, write the code and save the file
with ‘.java’extension.
Next, to compile the code, open the terminal and enter to the
folder where recently created ‘.java’ file reside. Next, writejavac
filename.java.
After compilation, compiler generates‘.class’file.
To run the ‘.class’ file write in the terminaljava ‘filename.class’.
2
3
4
5
Bikash Choudhury (RKMGECP) OOPS September 28,2021 19/68
20. How to Write Java
Program
1 There are three types of comments available in Java.‘Single
line’, ‘multi-line’and‘Java-documentation’.
Single line //This is the single line
comment Multi-line /∗ This is multi-line
comments ∗/
Java-documentation / ∗∗ it provides description of every feature
in Java Program ∗/
This (Java-documentation) description is helpful in the creation
of a ‘.html’ file called API (Application Program Interface)
document. write
Please go through the first program (Hellop.java)in the
Assignment and execute it.
2
3
4
5
6
Bikash Choudhury (RKMGECP) OOPS September 28,2021 20/68
21. How to Write Java
Program
Impor
t 1
2
3
4
5
In CC + + we use‘# include < stdio.h >’.
What happens when we include the header
file?
Similar but more efficient mechanism is available in Java
called ‘import’. import java.lang.System;
Java Library → Packages → Classes → Methods
Please go through the first program (Hello.java)in the
Assignment1.0 and and execute it.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 21/68
22. Assignme
nt
Assignme
nt1
2
3
4
5
6
7
8
9
10
What is the difference between an executable file and a ‘.class’
file? Why ‘.class’ file is called Byte code?
Why Java is suitable for Internet?
Why pointers are eliminated from Java?
What is the difference between a function and a
method? Is Java a purely object oriented language or
not? Justify.
Which part of the JVM will allocate the memory for a Java
program? Explain JDK,JRE,JVM and JIT.
Difference between include and
import. Difference between C++ and
Java.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 22/68
25. JVM
JVM
1
2
3
4
5
First,‘.Java’program is compiled and converted
to‘.class’(Byte Code) by the Compiler of JDK/Java.
Second,‘.class’file is given to the JVM/JRE for the execution. In
JVM there is a module called‘Class Loader Sub System’which
performsa)loads ‘.class’ in to memoryb)Verifies all the byte code
instructions are proper or not? if suspicious instructions found
then rejects the execution. Otherwise allocates the necessary
memory to execute the program.
Method Area:stores class code, code of the variables and code of
the methods in the Java program.
Heap Area:here objects are created.
Java Stacks:Here java methods are executed. Especially
stores all the data and results used by the method.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 25/68
26. JVM
JVM
1 PC Register:contain memory address of the instructions of
the methods.
2 Native method stacks:native methods ( CC + +) are executed
on
3
4
5
6
native method stacks.
Native method interface:To execute native method, native method
libraries are required. These header files are located and
connected to JVM by a program called Native Method Interface.
Execution Engine:containsinterpreterandJIT(Just in Time)
compiler. Both are responsible for converting Byte code to
machine code so that processor can understand and execute
accordingly.
Both interpreter and JIT compiler works simultaneously to
convert Byte code to m/c code.
Why both are needed and how both works simultaneously?
Bikash Choudhury (RKMGECP) OOPS September 28,2021 26/68
27. JVM
1 Consider a sample byte
code
1. print a = 1;
2. print b = 2;
3. for(i = 0;i < 10;i ++) {print a};
Interpreter starts execution from line1 it converts print a = 1;
into machine code and gives it to microprocessor. Assume
interpreter takes2 nanoseconds to do the aforesaid. Next,
processor takes it execute it and displayed the value of a = 1.
Again interpreter comes back to the memory and read the second
instruction print b = 2;. Interpreter takes another2 nanoseconds to
do the aforesaid. Next, processor takes it execute it and displayed
the value of b = 2.
2
3
Bikash Choudhury (RKMGECP) OOPS September 28,2021 27/68
28. JVM
1 Next, interpreter comes back to the memory and read the
third
instruction which is a looping statement {print a};. This should
be
done10times and this is known to the interpreter. So, first time it
converts the instruction to m/c code and gives it to the processor
and comes back to the memory for that it takes another2
nanoseconds.
Similarly10times the interpreter read the instruction and gives to
the
2
processor. So, total it takes10 ∗ 2 = 20 nanoseconds to read the
third instruction and gives it to the processor. Moreover, It is not
efficient with respect to time. This is the only reason JVM does
not allocate 3rd instruction to the interpreter instead it allocates
to the JIT compiler.
3 JIT compiler reads the print a; instruction and converts that into
m/c code. For this it takes2 nanoseconds. Next, JIT compiler
allots a block of memory and pushes this m/c code instruction into
that memory. For this it takes another2 nanoseconds. So, JIT
takes total of4 nanoseconds.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 28/68
29. JVM
1 Now processor will fetch the instructions from the memory
and execute it 10times.
2 Observe that JIT compiler takes only4 nanoseconds to execute
the
3rd instruction, where as interpreter takes10 ∗ 2 = 20
nanoseconds for the same instruction. Hence, the JIT compiler
increases the speed of the execution.
3 Remember, first two instructions will not be allotted to the JIT
compiler by the JVM. (Interpreter takes2 nanoseconds to
convert byte code to m/c code whereas JIT takes4
nanoseconds).
After loading the‘.class’code into the class loader JVM identifies
which code is to be left to the interpreter and which one to the
JIT compiler so that the performance is better. The blocks of
code allocated fro the JIT compiler also called‘ hotspotsj.
4
Bikash Choudhury (RKMGECP) OOPS September 28,2021 29/68
30. Class and
Object
Properties:Variable
Actions: methods ()
Class: Dog
1. name
2. height
3. colour
4. age
1.running
2.barking
3.eating
1. Tom
2. 1 foot
3. brown
4. 5 years
Properties:Variable
Actions: methods ()
1. run ()
2. bark ()
3. eat ()
Object: Tom
Figure:Class and
Object
Bikash Choudhury (RKMGECP) OOPS September 28,2021 30/68
31. My First
Program
First Program
1.import java.lang.System; // java library—Package—Class–
Methods 2.import java.lang.String;
3.//import java.lang.*;
4.class Hello
5.{
6. public static void main(String
args[]) 7. {
8. System.out.print(”Hello
PGEC”); 9. }
10.}
Bikash Choudhury (RKMGECP) OOPS September 28,2021 31/68
32. My First
Program
1.public:Access specifier. If we do not made main() as public
then JVM does not allow to execute it.
2.static:methods which can be called and executed without
creating the objects.
3.void:return type of the main method().
4.main():is a method also starting point of the program. it accepts
a group of strings.
5.String args[]:string type array. args[] is the name of array and it is
of String type.
6.System: class name.print() belongs to PrintStream class. We
should call the print() by creating an object to PrintStream class.
But, as it is not possible to create an object of the PrintStream
class i.e., we use alternative approach.
7.out:static variable in System class (When we call ‘out’ internally
an object of PrintStream class is created).
8.print():used to display messages on the monitor.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 32/68
33. Create a
Class
Class
1.class Person {
2.statements; // any no. of variables and methods we can
create 3.}
Object
1.class-name new-object-name = new class-name();
2. Hello Suman =new Person(); // Suman object is created
Bikash Choudhury (RKMGECP) OOPS September 28,2021 33/68
36. Input and Output in
Java
1 A stream is required to accept input from the keyboard.
Stream represents flow of data from one place to another. Like a
water pipe carries water from one place to another, similarly
Stream carries data from one place to another (from keyboard to
memory or from memory to file or printer).
Different types of Stream:a) Input Stream:which receives or
read data coming from some another place.b) Output
Stream:which send or write data to some other place.
All streams (input or output) are represented in’java.io’.
System.in: represents InputStream object, which by default
represents standard input device, i.e., keyboard.
System.out: represents InputStream object, which by
default represents standard output device, i.e., monitor.
System.err: represents InputStream object, which by
default represents monitor.
Difference betweenSystem.outandSystem.err?
2
3
4
5
6
7
8
Bikash Choudhury (RKMGECP) OOPS September 28,2021 36/68
37. Input in
Java
1 java.io.Console(Please open program Cmd.java from
Assignment1.5.) java.io.BufferedReader
java.util.Scanner
2
3
Bikash Choudhury (RKMGECP) OOPS September 28,2021 37/68
38. Input through
System.in
1 Keyboard (System.in) → input stream (InputStreamReader) →
input
stream (BufferedReader).
To accept data from keyboard (i.e., System.in) we need to connect
it to an input stream (InputStreamReader) as some input stream
is needed to read data. Connect the keyboard to an input stream
object and converts byte-oriented stream to character-oriented
stream.
InputStreamReader obj = new InputStreamReader(System.in);
To read data properly coming from InputStreamReader, we need
another stream called BufferedReader or BufferedReader class
can be used to read data line by line by readLine() method.
BufferedReader br = new BufferedReader(obj);
BufferedReader br= new BufferedReader(new
InputStreamReader(System.in)); // alternate
approach
2
3
4
5
6
7
Bikash Choudhury (RKMGECP) OOPS September 28,2021 38/68
39. Java BufferedReader class
methods
1 read(): used for reading a single character.
markSupported(): used to test the input stream support for the
mark and reset method.
readLine(): used for reading a line of text.
ready(): used to test whether the input stream is ready to be
read. skip(): used for skipping the characters.
reset(): reposition the stream at a position the mark method was
last called on this input stream.
mark(): is used for marking the present position in astream.
close(): closes the input stream and releases any of the
system resources associated with the stream.
2
3
4
5
6
7
8
Bikash Choudhury (RKMGECP) OOPS September 28,2021 39/68
40. Input through java.util.Scanner
Class
We can use Scanner class of java.util package to read input from the
keyboard or a text file. When the Scanner class receives input, it
breaks it into several pieces, called tokens. These token can be
retrieve from the Scanner object using the following methods:
1 nextLine(): used to read Strings from user.
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. nextLong(): Reads a long value from the
user. nextShort(): Reads a short value from the
user.
Please open program Scan.java from
Assignment1.5.
2
3
4
5
6
7
8
9
Bikash Choudhury (RKMGECP) OOPS September 28,2021 40/68
41. Output through
System.out.printf()
To format and display the output printf() is available in PrintStream
class. This class works similar to printf() in c. We use
System.out.printf().
1 %s: string
%c: character
%d : decimalinteger
%f : float number
%o: octal number
%b, %B: boolean value
%x, %X: hexadecimal number
%e,%E : number in scientific notation
%n: new line character
Please open program Out.java from
Assignment1.5.
2
3
4
5
6
7
8
9
10
Bikash Choudhury (RKMGECP) OOPS September 28,2021 41/68
42. String
s
1 String represents a group of characters. Most of the data transmits
in internet is in the form of groups of characters. Such group of
characters are called Strings.
In CC + + languages, a String represents an array of characters,
2
where the last character 0 (called null character) represents the
end
of the Strings.
But this is not valid in java.In java String is an object of String
class. It is not an character array. In java we have character array
also, but Strings are treated differently because of their extensive
use in internet.
Is String is a datatype or class?String is a class in ‘java.lang’
package. But in java all classes are considered as data types.
So we can consider String as a data type also.
Can we call a class a datatype?Yes, a class also called a user
defined datatype.
3
4
5
Bikash Choudhury (RKMGECP) OOPS September 28,2021 42/68
43. Creating
Strings
There arethreedifferent ways to create string in
java.
1 We can create a String just by assigning a group of charters
to a String type variable.
String s; // Declare String type variable .
s=“RKMGEC”; // Assign a group of characters to it.
String s = ”RKMGEC” // Alternate
String s = new String(”RKMGEC”);
2
3 char arr[ ]={ ’R’,’K’,’M’,’G’,’E’,’C’};
String s = new String(arr);
String s = new String(arr,3,2); // Alternate: Starting from 3rd
character, a total 2 characters are copied in s.
Please open program StrCls1.java from Assignment1.6.
4
Bikash Choudhury (RKMGECP) OOPS September 28,2021 43/68
44. Methods in
Strings
1 hashCode():Returns the hash code of a string
charAt():Returns the character at the specified index (position)
concat():Appends a string to the end of another string
contains():Checks whether a string contains a sequence of
characters
contentEquals():Checks whether a string contains the exact same
sequence of characters of the specified CharSequence or
StringBuffer
endsWith():Checks whether a string ends with the
specified character(s)
equals():Compares two strings. Returns true if the strings are
equal, and false if not
equalsIgnoreCase():Compares two strings, ignoring
case considerations
format():Returns a formatted string using the specified
2
3
4
5
6
7
8
9
Bikash Choudhury (RKMGECP) OOPS September 28,2021 44/68
45. Methods in
Strings
1 getChars():Copies characters from a string to an array of chars
indexOf():Returns the position of the first found occurrence
of specified characters in a string
isEmpty():Checks whether a string is empty or
not length():Returns the length of a specified
string split():Splits a string into an array of
substrings
startsWith():Checks whether a string starts with specified
characters
substring():Extracts the characters from a string, beginning at a
specified start position, and through the specified number of
character
toLowerCase():Converts a string to lower case
letters toUpperCase():Converts a string to upper
2
3
4
5
6
7
8
9
10
Bikash Choudhury (RKMGECP) OOPS September 28,2021 45/68
46. String
Comparison
The relational operators like >,>=,<,<=,==,! = can not be used to
compare to strings.equals() and compareTo()methods are used to
compare the Strings.
1 When an object is created to the JVM it returns the memory
address of the object as a hexadecimal code (Object reference).
Every object will have unique object reference number.
String s1 = ”RKMGEC”
When JVM execute the above statement, it creates an object on
heap and stores “RKMGEC” in it. A reference number (‘2e45b3’)
is allotted for this object.
String s2 = new String(”RKMGEC”);
JVM creates another object and allot different reference
number (‘3b34c2’).
Please open program StrCls2.java & StrCls2.java from
Assignment1.6.
2
3
4
Bikash Choudhury (RKMGECP) OOPS September 28,2021 46/68
49. Immutability of
String
Immutable
Objects are broadly divided into -
a) Mutable (Contents can be modified) and
b)Immutable (contents can not be modified) objects. In java String
class objects are immutable.
String s1 = ”Computer”; String s2 = ”Science”;
s1=s1+s2; // ComputerScience (Please open program StrCls4.java
from
Assignment1.6.)
Bikash Choudhury (RKMGECP) OOPS September 28,2021 49/68
50. String Buffer &
Builder
1 To overcome the immutability issues in String we
useStringBuffer andStringBuilderclass.
Please open program StrCls5.java from Assignment1.6.
The main difference betweenStringBufferandStringBuilderis that
the StringBuffer class is by default synchronized and
StringBuilder is not.
When a programmer wants to use several threads she/he should
use StringBufferclass as it gives reliable results. If only one
thread is used,StringBuilderis preferred, as it improves the
execution.
2
3
4
Bikash Choudhury (RKMGECP) OOPS September 28,2021 50/68
52. Class/Objec
t
1 An object is anything thatreally exists in the world and can be
distinguished from others. E.g., a car, a table, a chair, a
person. A Class is amodel or blueprintfor creating objects.
[Please open program Cao0.java from Assignment2.0].
2
P r o p e r t i e s : V a r i a b l e
A c t i o n s : m e t h o d s ( )
1 . n a m e
2 . h e i g h t
3 . c o l o u r
4 . a g e
1 . r u n n i n g
2 . b a r k i n g
3 . e a t i n g
1 . T o m
2 . 1 f o o t
3 . b r o w n
4 . 5 y e a r s
P r o p e r t i e s : V a r i a b l e
A c t i o n s : m e t h o d s ( )
1 . r u n ( )
2 . b a r k ( )
3 . e a t ( )
C l a s s : D o g O b j e c t : T o m
Bikash Choudhury (RKMGECP) OOPS September 28,2021 52/68
53. Encapsulation and
Abstraction
Encapsulatio
n 1
2
Encapsulation is a mechanism where the data (variables) and
the code (methods) that act on the data will bind together.
Class consist of variables and methods tightly. Class is an
example for Encapsulation.
Abstractio
n 1
2
There may be a lot of data, a class contains and the user does
not need the entire data. The user requires only some part of
the available data. In this case, we can hide the unnecessary
data from the user and expose only that data that is of interest
to the user. This is called abstraction.
A car driver should know how to drive the car and does not require
to know how the engine is designed. [Please open program
Cao0.java from Assignment2.0]
Bikash Choudhury (RKMGECP) OOPS September 28,2021 53/68
54. Inheritance and
Polymorphism
Inheritanc
e 1
2
It creates new classes from existing classes,so that new
classes will acquire all the features of the existing classes is
called Inheritance.
Parents producing the children and children inhering the
qualities of the parents. [Please open program Cao0.java from
Assignment2.0]
Polymorphis
m1
2
The word ’Ploymorphism’ came from two Greek
words’poly’meaning ’many’and’morphos’meaning’forms’. Thus,
polymorphism
represents the ability to assume several different forms.
In programming, we can use a single variable to refer to objects
of different types and thus, using that variable we can call the
methods of different objects. [Please open program Cao0.java
from Assignment2.0]
Bikash Choudhury (RKMGECP) OOPS September 28,2021 54/68
55. Hash
Code
Hash
Code
1
2
Hash Code is a unique identification number allotted to the objects
by the JVM. This hash code number also called the reference
number which is created based on the location of the object in
memory, andis unique for all objects, excepts for String objects.
Please open program ’Cao1.java’ from Assignment2.0
Bikash Choudhury (RKMGECP) OOPS September 28,2021 55/68
56. Hash
Code
p t r t o h e a p p t r t o s p e c i a l s t r u c t u r e
i n s t a n c e v a r i a b l e 1
i n s t a n c e v a r i a b l e 2
i n s t a n c e v a r i a b l e 3
. . .
C o d e o f M e t h o d 1 ( )
H e a p M e m o r y
A l l S t a t i c V a r i a b l e s
M e t h o d A r e a
p t r t o s t a t i c v a r i b a l e s
p t r t o m e t h o d 1 ( )
p t r t o m e t h o d 2 ( )
...
S p e c i a l S t r u c t u r e
C o d e o f M e t h o d 2 ( )
O b j e c t R e f e r e n c e
Figure:Hash
Code
Bikash Choudhury (RKMGECP) OOPS September 28,2021 56/68
57. Hash
Code
6 0 3 7 4 2 8 1 4
. . .
N a m e :
A g e :
...
...
v o i d t a l k ( )
H e a p M e m o r y
M e t h o d A r e a
A b h i k
Figure:Hash Code of
Abhik
Bikash Choudhury (RKMGECP) OOPS September 28,2021 57/68
58. Access
Specifier/Modifier
Access Specifier
Is a keyword that specifies how to access the members
(variables,methods) of a class or class itself.
1
2
3
4
Private:’private’ members of a class are not accessible from
anywhere outside the class. They are accessible only within the
class by the methods of that class.
Public:The access level of a public modifier is everywhere. It can
be accessed from within the class, outside the class, within the
package and outside the package.
Protected:The access level of a protected modifier is within the
package and outside the package through child class. If we do not
make the child class, it cannot be accessed from outside the
package.
Default:The access level of a default modifier is only within the
package. It cannot be accessed from outside the package. If we
do not specify any access level, it will be the default.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 58/68
60. Constructo
r
Constructor
Constructor is a mechanism to initialize instance
variables.
1
2
3
4
5
6
Constructor’s name and class name should be same.
Constructor’s name should end with a pair of simple braces.
If a constructor does not have any parameters, it is called
Default constructor.
If a constructor has one or more parameters, it is called
Parameterized constructor.
A Constructor does not return any value, not even void.
A Constructor is automatically called and executed at the time
of creating an object.
While creating an object, if no parameter is passed to the object,
the default constructor is called and executed. If some values are
passed to the object then parameterized constructor is called.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 60/68
61. Method
s
Methods
Represents a group of statements that perform a task
(calculation, processing of data or generating a report).
returndatatype methodname(parameter1,
parameter2,...) A method can not return more than
one value.
Method without parameters and without return type.
(P1) Method without parameters but with return type.
(P2) Method with two parameters and return type. (P3)
Instance method(): Methods which act on the instance variables
of the class. To call the instance methods, we should use the
form: objectname.methodname();
Bikash Choudhury (RKMGECP) OOPS September 28,2021 61/68
62. Static
Methods
Static Methods
Methods which do not act upon the instance variables of a class.
Static methods are declared as ’static’.
To call the static methods, we need not require to create object.
We can call a static method as: Classname.methodname();
JVM first execute the instance methods and then only it creates
the objects. Since the objects are not available at the time of
calling the static methods, the instance variables are also not
available.
Static method can access static variables. Static variables are
also declared as static. (P4,P5,P6)
Bikash Choudhury (RKMGECP) OOPS September 28,2021 62/68
63. Static
Methods
Difference between Instance variable and Static variable
An instance variable is a variable whose separate copy is
available to each object. A class/static variable is a variable
whose single copy in memory is shared by all objects. (P7,P8)
Instance variables are created in the objects on heap memory.
Class variables are stored on method area.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 63/68
64. Static
Block
Static Block
is a block of statements declared as
’static’. static {
statements;
}
1
2
3
JVM executes a static block on a highest priority basis.
JVM first execute the static block then it looks for the main () in the
program. (Prog.M9.java)
Can we write a program without main()? (Prog. M10.java)
Bikash Choudhury (RKMGECP) OOPS September 28,2021 64/68
65. Static
Block
Static Block
is a block of statements declared as
’static’. static {
statements;
}
1
2
3
4
5
JVM executes a static block on a highest priority basis.
JVM first execute the static block then it looks for the main () in the
program. (Prog.M9.java)
Can we write a program without main()? (Prog. M10.java)
Yes. We can cheat the JVM before execution of main() method
we can terminate the program. (Prog. M11.java)
Moreover, it works until Java 1.6 version. Java 1.7 and newer
versions dont allow this because JVM checks the presence of the
main method before initializing the class.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 64/68
66. Local
Variables
Local Variable
Local variable is a variable that is declared as locally inside a
method or constructor and is available only within that method or
a constructor.
Local variable can not be accessed outside the method or
constructor. (Prog. M15.java)
Sometimes a local variable has the same name as that of an
instance variable. This leads to problems regarding their
accessibility. (Prog. This1.java)
How to refer to the instance variable?
Bikash Choudhury (RKMGECP) OOPS September 28,2021 65/68
67. thi
s
this
’this’ is a keyword that refers to the object of the class where it
is used.
’this’ refers to the object of the present class.
All members (instance variable, constructor and methods)
are referenced by ’this’.
When an object is created to a class, a default reference (’this’)
is also created internally to the object.
’this’ can refer to all the things of the present object.
(Prog. This2.java & M16.java)
Bikash Choudhury (RKMGECP) OOPS September 28,2021 66/68
68. Instance
Methods
Instance Methods
Instance methods are methods which act upon the instance variables.
The specialty of instance methods is that they can access not only
instance variables but also static variables directly. There are two
types of instance methods:
Accessor Methods:are the methods that simply access or read
the instance variables. They do not modify the instance
variables.
Mutator Methods:not only access the instance variables but
also modify them. (Prog. This2.java)
Bikash Choudhury (RKMGECP) OOPS September 28,2021 67/68
69. Passing Array and
Objects
Passing Array and Objects
Passing Array (Prog. Method17.java)
Passing Objects (Prog. Method12.java & Method13.java)
Primitive data types, objects, even object references -
everything is passed to methods using ’pass by value’ or ’call
by value’ concept. This means their bit by bit copy is passed to
the methods.
Bikash Choudhury (RKMGECP) OOPS September 28,2021 68/68