SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Outline
  Why Java ?
  Classes and methods
  Data types
  Arrays
  Control statements
  Oops concept
  Abstract class
  Interface
  Run Java Program in eclipse
  Hello Word Android App
Procedural vs. Object Oriented


Functional/procedural programming:
program is a list of instructions to the computer

Object-oriented programming
program is composed of a collection objects that
communicate with each other
JVM
• JVM stands for

     Java Virtual Machine

• Unlike other languages, Java “executables” are executed on a
  CPU that does not exist.
Platform Dependent

myprog.c                                 myprog.exe
                              gcc          machine code
  C source code

                                           OS/Hardware



                  Platform Independent

myprog.java                               myprog.class
                              javac           bytecode
 Java source code

                                                JVM

                                            OS/Hardware
Class
 • A template that describes the kinds of state and behavior that
   objects of its type support.
 • object is an instance of class
 • class groups similar objects
   • same (structure of) attributes
   • same services
 • object holds values of its class’s attributes
Objects
• At runtime, when the Java Virtual Machine (JVM) encounters
  the new keyword,

• it will use the appropriate class to make an object which is an
  instance of that class.

• That object will have its own state, and access to all of
 the behaviors defined by its class.
Encapsulation
• Separation between internal state of the object and its external
  aspects

• How ?
  • control access to members of the class
  • interface “type”
What does it buy us ?
• Modularity
  • source code for an object can be written and maintained
    independently of the source code for other objects
  • easier maintainance and reuse
• Information hiding
  • other objects can ignore implementation details
  • security (object has control over its internal state)
• but
  • shared data need special design patterns (e.g., DB)
  • performance overhead
Primitive types

•   int     4 bytes
•   short   2 bytes
•   long    8 bytes
                         Behaviors is
                         exactly as in
•   byte    1 byte
                         C++
•   float   4 bytes
•   double 8 bytes
•   char    Unicode encoding (2 bytes)   Note:
                                         Primitive type
•   boolean {true,false}                 always begin
                                         with lower-case
Primitive types - cont.

• Constants
  37     integer
  37.2   float
  42F    float
  0754   integer (octal)
  0xfe   integer (hexadecimal)
Wrappers

       Java provides Objects which wrap
       primitive types and supply methods.
Example:

           Integer n = new Integer(“4”);
           int m = n.intValue();
Hello World
Hello.java
class Hello {
      public static void main(String[] args) {
            System.out.println(“Hello World !!!”);
      }
}



C:javac Hello.java   ( compilation creates Hello.class )

C:java Hello              (Execution on the local JVM)
Arrays
arrays are objects that store multiple variables of the same type,
or variables that are all subclasses of the same type



Declaring an Array of Primitives

int[] key;    // Square brackets before name (recommended)
int key []; // Square brackets after name
 (legal but less// readable)

Declaring an Array of Object References
Thread[] threads; // Recommended
Thread threads []; // Legal but less readable
Arrays - Multidimensional
  • In C++

        Animal arr[2][2]

  Is:

• In Java
Animal[][] arr=
   new Animal[2][2]



         What is the type of
         the object here ?
Flow control
   Basically, it is exactly like c/c++.

                           do/while
                      int i=5;
                                                 switch
  if/else             do {                char
If(x==4) {              // act1           c=IN.getChar();
  // act1               i--;              switch(c) {
} else {              } while(i!=0);        case ‘a’:
  // act2                                   case ‘b’:
}                              for             // act1
                                               break;
                int j;
                                            default:
                for(int i=0;i<=9;i++)
                                               // act2
                {
                                          }
                  j+=i;
                }
Access Control
• public member (function/data)
  • Can be called/modified from outside.
• protected
  • Can be called/modified from derived classes
• private
  • Can be called/modified only from the current class
• default ( if no access modifier stated )
  • Usually referred to as “Friendly”.
  • Can be called/modified/instantiated from the same package.
Inheritance   class Base {
                  Base(){}
                  Base(int i) {}
                  protected void foo() {…}
              }
    Base
              class Derived extends Base {
                  Derived() {}
                  protected void foo() {…}
                  Derived(int i) {
                    super(i);
   Derived           …
                    super.foo();
                  }
              }
Inheritance cont..

 Class hierarchy
 package book;
 import cert.*; // Import all classes in the cert package
 class Goo {
 public static void main(String[] args) {
 Sludge o = new Sludge();
 o.testIt();
 }}
 Now look at the second file:
 package cert;
 public class Sludge {
 public void testIt() { System.out.println("sludge"); }
 •}
Inheritance cont..
package certification;
public class OtherClass {
void testIt() { // No modifier means method has default
// access
System.out.println("OtherClass");
}
}
In another source code file you have the following:
package certfcation;
import certification.OtherClass;
class AccessClass {
static public void main(String[] args) {
OtherClass o = new OtherClass();
o.testIt();
}
}
Polymorphism
• Inheritance creates an “is a” relation:
For example, if B inherits from A, than we say that “B is also an A”.
   Implications are:
class PlayerPiece extends GameShape implements Animatable {
public void movePiece() {
System.out.println("moving game piece");
}
public void animate() {
System.out.println("animating...");
}
// more code}
Abstract
• abstract member function, means that the function
  does not have an implementation.
• abstract class, is class that can not be instantiated.
AbstractTest.java:6: class AbstractTest is an abstract class.
It can't be instantiated.
        new AbstractTest();
        ^
1 error

NOTE:
An abstract class is not required to have an abstract method in it.
But any class that has an abstract method in it or that does
not provide an implementation for any abstract methods declared
in its superclasses must be declared as an abstract class.

                                                  Example
Abstract - Example
package java.lang;
public abstract class Shape {
       public abstract void draw();
       public void move(int x, int y) {
         setColor(BackGroundColor);
         draw();
         setCenter(x,y);
         setColor(ForeGroundColor);
         draw();
       }
}


package java.lang;
public class Circle extends Shape {
       public void draw() {
        // draw the circle ...
      }
}
Interface
Interfaces are useful for the following:
• Capturing similarities among unrelated classes without
  artificially forcing a class relationship.
• Declaring methods that one or more classes are expected to
  implement.
• Revealing an object's programming interface without revealing
  its class.
Interface
When to use an interface ?
    interface methods are abstract, they cannot be
     marked final,

■ An interface can extend one or more other interfaces.

■ An interface cannot extend anything but another
interface.

■ An interface cannot implement another interface or class

■ An interface must be declared with the keyword
interface
public abstract interface Rollable { }

Weitere ähnliche Inhalte

Was ist angesagt?

Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Conceptsmdfkhan625
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Sagar Verma
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Sagar Verma
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
 
Getting started with the JNI
Getting started with the JNIGetting started with the JNI
Getting started with the JNIKirill Kounik
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPTkishu0005
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Javabackdoor
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object ReferencesTareq Hasan
 

Was ist angesagt? (19)

Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Java Programming - 05 access control in java
Java Programming - 05 access control in javaJava Programming - 05 access control in java
Java Programming - 05 access control in java
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
About Python
About PythonAbout Python
About Python
 
Getting started with the JNI
Getting started with the JNIGetting started with the JNI
Getting started with the JNI
 
Java2
Java2Java2
Java2
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
CLASS & OBJECT IN JAVA
CLASS & OBJECT  IN JAVACLASS & OBJECT  IN JAVA
CLASS & OBJECT IN JAVA
 
Object oriented programming in python
Object oriented programming in pythonObject oriented programming in python
Object oriented programming in python
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Basic java for Android Developer
Basic java for Android DeveloperBasic java for Android Developer
Basic java for Android Developer
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 

Andere mochten auch

Easy java installation &amp; practice
Easy java installation &amp; practiceEasy java installation &amp; practice
Easy java installation &amp; practiceNooria Esmaelzade
 
Chapter 9 Interface
Chapter 9 InterfaceChapter 9 Interface
Chapter 9 InterfaceOUM SAOKOSAL
 
Java oops and fundamentals
Java oops and fundamentalsJava oops and fundamentals
Java oops and fundamentalsjavaease
 
Learn java
Learn javaLearn java
Learn javaPalahuja
 
Java object oriented programming - OOPS
Java object oriented programming - OOPSJava object oriented programming - OOPS
Java object oriented programming - OOPSrithustutorials
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS ConceptBoopathi K
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsRaja Sekhar
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Liju Thomas
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).pptAlok Kumar
 

Andere mochten auch (19)

Oops in java
Oops in javaOops in java
Oops in java
 
Easy java installation &amp; practice
Easy java installation &amp; practiceEasy java installation &amp; practice
Easy java installation &amp; practice
 
Vandana_Fresher
Vandana_FresherVandana_Fresher
Vandana_Fresher
 
Chapter 9 Interface
Chapter 9 InterfaceChapter 9 Interface
Chapter 9 Interface
 
javaopps concepts
javaopps conceptsjavaopps concepts
javaopps concepts
 
Java oops and fundamentals
Java oops and fundamentalsJava oops and fundamentals
Java oops and fundamentals
 
Learn java
Learn javaLearn java
Learn java
 
Java object oriented programming - OOPS
Java object oriented programming - OOPSJava object oriented programming - OOPS
Java object oriented programming - OOPS
 
Oops Concept Java
Oops Concept JavaOops Concept Java
Oops Concept Java
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Java Basic Oops Concept
Java Basic Oops ConceptJava Basic Oops Concept
Java Basic Oops Concept
 
OOPs in Java
OOPs in JavaOOPs in Java
OOPs in Java
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++
 
Oop java
Oop javaOop java
Oop java
 
C++ classes
C++ classesC++ classes
C++ classes
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 

Ähnlich wie core java

Ähnlich wie core java (20)

JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
 
Module 1.pptx
Module 1.pptxModule 1.pptx
Module 1.pptx
 
Cse java
Cse javaCse java
Cse java
 
Core_java_ppt.ppt
Core_java_ppt.pptCore_java_ppt.ppt
Core_java_ppt.ppt
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
CSharp presentation and software developement
CSharp presentation and software developementCSharp presentation and software developement
CSharp presentation and software developement
 
ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
Presentation to java
Presentation  to  javaPresentation  to  java
Presentation to java
 
Java
Java Java
Java
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
 
Intro to Java for C++ Developers
Intro to Java for C++ DevelopersIntro to Java for C++ Developers
Intro to Java for C++ Developers
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoM
 
Java
JavaJava
Java
 
Core java
Core javaCore java
Core java
 
First fare 2011 frc-java-introduction
First fare 2011 frc-java-introductionFirst fare 2011 frc-java-introduction
First fare 2011 frc-java-introduction
 
Core java concepts
Core java conceptsCore java concepts
Core java concepts
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 

Kürzlich hochgeladen

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Kürzlich hochgeladen (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

core java

  • 1. Outline Why Java ? Classes and methods Data types Arrays Control statements Oops concept Abstract class Interface Run Java Program in eclipse Hello Word Android App
  • 2. Procedural vs. Object Oriented Functional/procedural programming: program is a list of instructions to the computer Object-oriented programming program is composed of a collection objects that communicate with each other
  • 3. JVM • JVM stands for Java Virtual Machine • Unlike other languages, Java “executables” are executed on a CPU that does not exist.
  • 4. Platform Dependent myprog.c myprog.exe gcc machine code C source code OS/Hardware Platform Independent myprog.java myprog.class javac bytecode Java source code JVM OS/Hardware
  • 5. Class • A template that describes the kinds of state and behavior that objects of its type support. • object is an instance of class • class groups similar objects • same (structure of) attributes • same services • object holds values of its class’s attributes
  • 6. Objects • At runtime, when the Java Virtual Machine (JVM) encounters the new keyword, • it will use the appropriate class to make an object which is an instance of that class. • That object will have its own state, and access to all of the behaviors defined by its class.
  • 7. Encapsulation • Separation between internal state of the object and its external aspects • How ? • control access to members of the class • interface “type”
  • 8. What does it buy us ? • Modularity • source code for an object can be written and maintained independently of the source code for other objects • easier maintainance and reuse • Information hiding • other objects can ignore implementation details • security (object has control over its internal state) • but • shared data need special design patterns (e.g., DB) • performance overhead
  • 9. Primitive types • int 4 bytes • short 2 bytes • long 8 bytes Behaviors is exactly as in • byte 1 byte C++ • float 4 bytes • double 8 bytes • char Unicode encoding (2 bytes) Note: Primitive type • boolean {true,false} always begin with lower-case
  • 10. Primitive types - cont. • Constants 37 integer 37.2 float 42F float 0754 integer (octal) 0xfe integer (hexadecimal)
  • 11. Wrappers Java provides Objects which wrap primitive types and supply methods. Example: Integer n = new Integer(“4”); int m = n.intValue();
  • 12. Hello World Hello.java class Hello { public static void main(String[] args) { System.out.println(“Hello World !!!”); } } C:javac Hello.java ( compilation creates Hello.class ) C:java Hello (Execution on the local JVM)
  • 13. Arrays arrays are objects that store multiple variables of the same type, or variables that are all subclasses of the same type Declaring an Array of Primitives int[] key; // Square brackets before name (recommended) int key []; // Square brackets after name (legal but less// readable) Declaring an Array of Object References Thread[] threads; // Recommended Thread threads []; // Legal but less readable
  • 14. Arrays - Multidimensional • In C++ Animal arr[2][2] Is: • In Java Animal[][] arr= new Animal[2][2] What is the type of the object here ?
  • 15. Flow control Basically, it is exactly like c/c++. do/while int i=5; switch if/else do { char If(x==4) { // act1 c=IN.getChar(); // act1 i--; switch(c) { } else { } while(i!=0); case ‘a’: // act2 case ‘b’: } for // act1 break; int j; default: for(int i=0;i<=9;i++) // act2 { } j+=i; }
  • 16. Access Control • public member (function/data) • Can be called/modified from outside. • protected • Can be called/modified from derived classes • private • Can be called/modified only from the current class • default ( if no access modifier stated ) • Usually referred to as “Friendly”. • Can be called/modified/instantiated from the same package.
  • 17. Inheritance class Base { Base(){} Base(int i) {} protected void foo() {…} } Base class Derived extends Base { Derived() {} protected void foo() {…} Derived(int i) { super(i); Derived … super.foo(); } }
  • 18. Inheritance cont.. Class hierarchy package book; import cert.*; // Import all classes in the cert package class Goo { public static void main(String[] args) { Sludge o = new Sludge(); o.testIt(); }} Now look at the second file: package cert; public class Sludge { public void testIt() { System.out.println("sludge"); } •}
  • 19. Inheritance cont.. package certification; public class OtherClass { void testIt() { // No modifier means method has default // access System.out.println("OtherClass"); } } In another source code file you have the following: package certfcation; import certification.OtherClass; class AccessClass { static public void main(String[] args) { OtherClass o = new OtherClass(); o.testIt(); } }
  • 20. Polymorphism • Inheritance creates an “is a” relation: For example, if B inherits from A, than we say that “B is also an A”. Implications are: class PlayerPiece extends GameShape implements Animatable { public void movePiece() { System.out.println("moving game piece"); } public void animate() { System.out.println("animating..."); } // more code}
  • 21. Abstract • abstract member function, means that the function does not have an implementation. • abstract class, is class that can not be instantiated. AbstractTest.java:6: class AbstractTest is an abstract class. It can't be instantiated. new AbstractTest(); ^ 1 error NOTE: An abstract class is not required to have an abstract method in it. But any class that has an abstract method in it or that does not provide an implementation for any abstract methods declared in its superclasses must be declared as an abstract class. Example
  • 22. Abstract - Example package java.lang; public abstract class Shape { public abstract void draw(); public void move(int x, int y) { setColor(BackGroundColor); draw(); setCenter(x,y); setColor(ForeGroundColor); draw(); } } package java.lang; public class Circle extends Shape { public void draw() { // draw the circle ... } }
  • 23. Interface Interfaces are useful for the following: • Capturing similarities among unrelated classes without artificially forcing a class relationship. • Declaring methods that one or more classes are expected to implement. • Revealing an object's programming interface without revealing its class.
  • 25. When to use an interface ?  interface methods are abstract, they cannot be marked final, ■ An interface can extend one or more other interfaces. ■ An interface cannot extend anything but another interface. ■ An interface cannot implement another interface or class ■ An interface must be declared with the keyword interface public abstract interface Rollable { }