Docsity

Java Programming: Data Types, Objects, and Classes, Essays (university) of Java Programming

Partial preview of the text

Download Java Programming: Data Types, Objects, and Classes and more Essays (university) Java Programming in PDF only on Docsity!

Advanced

Programming

BITS Pilani Techniques Raghavan P

Piani| Dubai| Goa | Hyderabad

Session 1

BITS Pilani

Outline – Contact Session 1

  • (^) Introduce the Eclipse IDE

Run the first Java Program Introduce the basic debugging e.g. step into, step through, watching variables

  • (^) Significance of a Class

Main function inside a class Keywords associated with main function - public, static, void Differentiate Class and Object Creating class and creating objects Adding members to the class - variables and methods Running a simple program with a class and objects Introduction to concepts of Encapsulation and Abstraction Access Modifiers - private, public, static 2 2

Features of Java

  • (^) Familiar, Simple, Small
  • (^) Compiled and Interpreted
  • (^) Platform-Independent and Portable
  • (^) Object-Oriented
  • (^) Robust and Secure
  • (^) Distributed
  • (^) Multithreaded and Interactive
  • (^) High Performance

Bytecodes

Compiled Languages

Text Editor Compiler linker

Programmer

Source Code

.c file

Object Code

.o file

Notepad, emacs,vi

gcc

Executabl e Code

a.out file

Bytecodes

  • (^) Bytecode is the code

generated after the Java programs are compiled. This is the intermediate representations of Java programs. Bytecode is NOT executable code like “.exe” but this is java propriety intermediate code. Bytecode

Platform Independence

  • (^) Java Compiler - Java source code (file with extension

.java) to bytecode (file with extension .class)

  • (^) Bytecode - an intermediate form, closer to machine

representation

  • (^) A interpreter (virtual machine) on any target

platform interprets the bytecode.

  • (^) Porting the java system to any new platform

involves writing an interpreter.

  • (^) The interpreter will figure out what the equivalent

machine dependent code to run

Java Virtual Machine - JVM

The Java Virtual Machine

Class loader

Execution engine

Host operating system

Program Class files

The Java API’s class files

Native methods invocation

The Bytecode :

  • (^) Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system which is called the Java Virtual Machine(JVM).

Java Virtual Machine(JVM ):

  • (^) JVM is an interpreter for bytecode.
  • (^) JVM needs to be implemented for each

platform.

  • (^) Although the details of the JVM will differ from

platform to platform, all interpret the same java bytecode.

Two Paradigms

Process-Oriented model

  • (^) What is happening
  • (^) Characterizes a program as a series of linear steps(that is code)
  • (^) Code acting on data problems appear as programs grow larger and more complex

Object- Oriented programming

  • (^) Who is being affected
  • (^) Organizes a program around its data(Object)
  • (^) Characterized as Data controlling access to code

Encapsulation

  • (^) Encapsulation is the mechanism that binds

together code and the data. It manipulates and keeps both safe from outside interference and misuse (protective wrapper)

  • (^) Access to the code and data inside the wrapper is

tightly controlled through a well-defined interface.

For example in a car shifting gears does not turn on the headlights.

  • (^) Encapsulation is a strategy used as part of abstraction. Encapsulation refers to the state of objects - objects encapsulate their state and hide it from the outside; outside users of the class interact with it through its methods, but cannot access the classes state directly. So the class abstracts away the implementation details related to its state.
  • (^) Abstraction is a more generic term, it can also be achieved by (amongst others) subclassing. For example, the interface List in the standard library is an abstraction for a sequence of items, indexed by their position, concrete examples of a List are an ArrayList or a LinkedList. Code that interacts with a List abstracts over the detail of which kind of a list it is using.
  • (^) Abstraction is often not possible without hiding underlying state by encapsulation - if a class exposes its internal state, it can't change its inner workings, and thus cannot be abstracted.

Polymorphism

  • (^) Polymorphism is a feature that allows one

interface to

be used for a general class of actions. The specific action

is determined by the exact nature of the situation.

  • (^) One interface multiple methods.

Java Program Structure

  • (^) In the Java programming language:
    • (^) A program is made up of one or more

classes

  • (^) A class contains one or more methods
  • (^) A method contains program statements
  • (^) A simple Java application always

contains a method called main() in one of its class.