440 likes | 648 Views
PROGRAMMING IN JAVA. Presented By: Aparchyanta Aneja. CONTENTS. PROGRAMMING LANGUAGE. What is a programming language???. Programming Language is used for communication between a machine and human. Programming Language. Instruction. Output. Machine. Software Developement.
E N D
PROGRAMMING IN JAVA Presented By: AparchyantaAneja
PROGRAMMING LANGUAGE What is a programming language??? Programming Language is used for communication between a machine and human.
Programming Language Instruction Output Machine Software Developement
HISTORY OF JAVA WORA Write Once Run Anywhere Platform Independent Portable
FEATURES OF JAVA PIE : Polymorphism, Inheritance, Encapsulation
.java .class Java Compiler Interpreter/ JVM Write Compile Execute
API are the libraries that we will be using to create java Program. COMPONENTS OF JAVA Takes the instruction, executes it and give the result. Java Application JVM (Java Virtual Machine) API (Application Programming Interface) Java Platform OS
JAVA DEVEPOLMENT KIT C/C++ Java
DOWNLOADING INSTALLING & CONFIGURING JAVA
EXAMPLE OF JAVA
No need of creating the object of the class Program to print Hello World Access Specifier No return value Name of the class class HelloWorld { public static void main(String alpha[]) { System.out.println("Hello World!!!"); } } Keyword Inbuilt Class Array Variable Name Entry point Keywords Final class Method overloaded to print message Output stream
DATATYPE Name Contact Age Email Eat Walk Talk Person
CLASSES & OBJECTS obj • Class is a blue print of an object • Object is an instance (memory) of a class. class Emp{ String name, contact; } class CEmp{ public static void main(String alpha[]) { Empobj=new Emp(); obj.name=“John"; obj.contact=“443-123-4567"; System.out.println(obj.name); System.out.println(obj.contact); } } Name Aman Contact 9023753113 1001 Object Heap Memory Object Reference Fetch the value through heap memory
CONSTRUCTOR • Used to initialize the instance members of class with their respective default values according to the data type. • Name of the constructor should be the same as that of the class • No return value • Does not initialize local variable • Automatically called when the object of the class is created Default Constructor Parameterized Constructor
INHERITANCE Deriving a new class from a given base class. rotate() { } playsound() { } Square rotate() { } playsound() { } Circle rotate() { } playsound() { } Triangle
rotate() playsound() Shape Super Class Sub classes Square Circle Triangle
ENCAPSULATION Protective barrier that prevents the code and data being randomly accessed by other code defined outside the class.
Package 1 Package 2 Public : Protected : Default : Private : Class C1 Class C4 Class C5 Class C2 Class C3 C1, C2, C3, C4, C5 C1, C2, C3, C4 C1, C2, C3 C1
POLYMORPHISM Polymorphism is the ability of an object to take on many forms. Many Forms
INTERFACE & ABSTRACT CLASSES Name Value Int a = 10; C1 obj=new C1(); Type User Defined Inbuilt Concrete Class Abstract Class Interface
Full Implementation of Methods Partial Implementation of Methods It is inherited. No implementation of Methods It is implemented Concrete Class Abstract Class Interface void display() Declaration { } Definition
abstract class Calc{ int add(int a, int b) { return a+b; } abstract int multi(int a, int b); } class Ccal extends Calc{ int multi(int a, int b) { return a*b; } } class CalMain{ psvm(String alpha[]){ Ccalobj=new Ccal(); S.o.p(“Sum:”+obj.add(10,20)); S.o.p(“Sum:”+obj.multi(10,20)); } interface Calc{ int add(int a, int b); int multi(int a, int b); } class Ccal implements Calc{ public int add(int a, int b) { return a+b; } public int multi(int a, int b) { return a*b; } } class CalMain{ psvm(String alpha[]){ Ccalobj=new Ccal(); S.o.p(“Sum:”+obj.add(10,20)); S.o.p(“Sum:”+obj.multi(10,20)); } Interface Abstract Class