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

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

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 { }