Basic Java Chapter 1

  • Uploaded by: zyrus-mojica-6477
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Basic Java Chapter 1 as PDF for free.

More details

  • Words: 687
  • Pages: 10
Object-Oriented Programming Language

 Object-oriented programming is an extension of procedural programming.  When writing object-oriented programs, it involves both creating objects and creating applications that use those objects.  Object-oriented programming or approach is a new approach to develop software, which can be widely used in business application.  With this approach, data and the program (or procedure) can be packaged into a single unit called an object. An object is an item that can contain both data, which are known as attributes or variables, and procedures, which contains activities that read or manipulate the data.

Object-Oriented Programming Principle A program developed in an object-oriented approach is based on the three basic concepts, which are encapsulation, inheritance, and polymorphism.

Encapsulation is a mechanism that binds together attributes and methods into a single object, and keeps both safe from interference or misuse, that is, the details of the object are encapsulated or hidden, from the user. The user knows that the method can be requested but does now know how the specifics of how the method is performed. This can be called information hiding. Inheritance An object maybe part of a large category of objects called a class. Every object in a class shares similar methods and attributes as the original objects. The higher-level class is called “superclass” the lower level class is called “subclass”. This concept of low levels inheriting attributes and methods of a superclass is called inheritance. Polymorphism

Benefits of Object-oriented Programming

 Java removes several features considered unsafe and also frees memory. Hence, it cuts down on the chances of making mistakes in the program.  A major benefit of object-oriented approach is the ability to reuse the defined objects and modify existing objects. The object-oriented approach to program development saves programming time.  Java’s adaptability is also a benefit as it is able to fit in different environment.  The advantage of object-oriented approach is reliability as it is able to operate correctly under all conditions.

Introduction to Java Programming Java programming language is an object-oriented language that is used both for general-purpose business programs and interactive World Wide Web (WWW)based Internet programs developed by Sun Microsystems. The first version of Java was introduced in 1995 and the language was then called “Oak”. The language is modeled after the C++ programming language and it has eliminated some of the most difficult features to understand in C++. Java can be used for developing applets, which resides in www servers downloaded by a browser to a client’s system, and run by the browser. Java is platform independent

Resources to create a Java Program

 a text editor .e.g notepad, wordpad, context, edit etc.  Java Development Kit, which includes the executable files needed for compiling and executing the program etc.  Other Java Development Tools e.g Borland JBuilder

Structure of a Java Program //import packages public class classname{ //instance variable access specifier data type variable1; access specifier data type variable2; …………………….. //methods access specifier data type methodname(parameter list) { //function body 1} Access specifier data type methodname2(parameter list) { //function body 2 } }

First application Access specifier

public class HelloWorld

class defined a new class created Direct access

{

public static void main( String[] args ) {

function

Does not return a value

//this function outputs Hello World System.out.println( “Hello World” ); } ← End of main } ← End of class

a single comment displays the string Hello World

Access Specifier

An access specifier defines the circumstances under which a class or class members in programs can be accessed.

Examples of Access specifiers public private protected default

Programming Exercises State and explain the concepts of Object-Oriented Programming. List the resources need to write a Java program Explain what is access specifier State any 2 access specifiers and explain the difference between the two types of access specifiers Write a simple program that displays the following Main Menu 1. Data Entry 2. Display 3. Exit Enter a choice: The output statement, System.out.println(); is always used to display output. Given that System is a class, what kind of an object does out refer to?

Related Documents

Basic Java Chapter 1
June 2020 2
Basic Java Chapter 3
June 2020 4
Basic Java Chapter 2
June 2020 3
Basic Java Chapter 4
June 2020 5
Java Basic Book 1
October 2019 11
Basic Java
November 2019 17