JAVA

June 19, 2013

Alexandru Burghelea, aburghelea@rosedu.org

Overview

  1. What is Java
  2. "HELLO, World!"
  3. Programming styles
  4. Fitting in
  5. Instance vs Class
  6. Access control
  7. Clarifications
  8. Code

What is Java

"Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, realiable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!"  
by java.com

More about JAVA

First Program 

Do not write code before you set up your environment

package osss;

/**
 * @author aburghelea
 * @since 6/8/13 - 12:41 PM
 */
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

LETS DO IT

Type it

and

Don't know how to run it eh?

I'll show you!

Programing Paradigms


  1. Imperative
  2. Procedural
  3. Functional
  4. Object Oriented

Imperative


  • the state is in global variables
  • direct assignment
  • list of commands to be executed in order
  • the philosophy is : "Apply rules in this order"
  • Ex:
    • C
    • C++
    • JAVA
    • Python

ProcedURAL


  • derived from structured programming (style of imperative programmign)
  • local variables
  • goto statements (not really)
  • modularization
  • Ex:
    • C
    • C++
    • Lisp
    • NOT Java (why do you thing that).

OBJECT ORIENTED

  • Objects
  • Methods
  • Global variable ???
  • Message passing
  • Data abstraction
  • Inheritance
  • Etc
  • Ex:
    • C++
    • C#
    • JAVA

Functional


  • NO state
  • NO mutable data
  • Lambda caculus
  • Threats computation as the evaluation of mathematical functions
  • Ex:
    • Haskell
    • Groovy
    • Scala

I thank Groovy, Radu thanks Scala.

Fitting in

Java is object-oriented. What does that mean? Unlike languages, such as FORTRAN, which focus on giving the computer imperative "Do this/Do that" commands, object-oriented languages focus on data. Of course, object-oriented programs still tell the computer what to do. They start, however, by organizing the data, and the commands come later.
by dummies.com

ReaLLY FITTING IN

  1. It has classes (remember Hello, World ?)
  2. Everything is a Object
  3. Objects communicate by sending messages 
  4. Inheritance at it's best
  5. Works with abstraction
  6. Knows polymorphism
  7. Does encapsulation


Rememer the last four, they are the major principles of OOP

Class vs Instance

  1. There is no JAVA program where code exists outside of: 
    class Name {
    }
  2. A class is a blueprint for an instance.
  • class = blueprint for a house 
  • instance = specific house
  • The class is "the code"
  • The instance is the runtime representation of a class
  • IT'S A DELICATE SUBJECT, LET'S DISCUSS ABOUT IT
  • Everything is an object

    1. What's an object in real life?
    2. What's an object in software?
    3. What is Object in JAVA?



    • State
    • Behavior

    Inheritance

    • Reuse exiting code
    • Super class (parent)
    • Sub class (child)
    • Keywords: "this", "super"

    Abstraction

    • Expose an interface
    • Hide implementation
    • Ex: A you want to use a list. You want to add, remove, iterate elements. Is it really important how the list is implemented?

    Things you can't really explain in slides

    • this
    • super
    • constructor
    • static vs instance

    Polymorphism

    • Poly = many: 
      • polygon = many-sided, polystyrene = many styrenes (a), polyglot = many languages, and so on.
    • Morph = change or form:
      •  morphology = study of biological form, Morpheus = the Greek god of dreams able to take any form.

    Polymorphism in Java

    • Behave in different ways based on the context
    • Reuse existing code
    • Method overloading
    • Method overriding
    • NO operator overloading

    Encapsulation

    • Bundle data and methods together (as long as they are related)
    • Do (for the love of God) alter the state (variables/properties) directly from the outside.

    Access control

    Visibility for each access level
    • public: class, package, subclass, world
    • protected: class, package, subclass
    • no modifier: class, package
    • private: class

    LET'S TRY IT


    JAVA

    By iceman

    JAVA

    Java presentation for Rosedu Open Source Summer School

    • 1,608