SlideShare a Scribd company logo
1 of 14
Download to read offline
Java course - IAG0040




              Java Basics,
             Program Flow


Anton Keks                           2011
Java type system
 ●
     static type checking         ●
                                      provides (benefits)
     –   by compiler, type            –   safety
         declarations required             ●
                                               many bugs are type
 ●
     strongly typed                            errors
     –   runtime checking             –   documentation
     –   automatic conversions        –   abstraction
         allowed only when not             ●   high-level thinking
         loosing information
                                      –   optimization
 ●   memory-safe                          (performance)
     –   array bounds checking,
         no pointer arithmetic
Java course – IAG0040                                          Lecture 2
Anton Keks                                                       Slide 2
Objects and Classes
 ●
     Classes introduce new types into a program
 ●
     First appeared in Simula-67 to define 'classes of
     objects'
 ●
     In OOP, Objects are instances of Classes
 ●
     All objects of the same class share
           –   same properties:
                        ●   fields hold internal state
           –   same behavior, dependent on the state:
                        ●
                            methods used for communication with objects

Java course – IAG0040                                             Lecture 2
Anton Keks                                                          Slide 3
References
 ●   You manipulate objects with references
     –   Like remote control of a TV is a reference to the TV
 ●
     Objects are stored on the heap, independently
     –   String s;      // is a reference to nothing
     –   s = “hello”; // now s points to a newly created
                      // String object on the heap
 ●
     You must create all the objects before using them
     –   s = new Date();
 ●   There are many other built-in types (classes), like
     Integer, Date, Currency, BigDecimal, etc, and making
     your own types is the point of OOP
Java course – IAG0040                                     Lecture 2
Anton Keks                                                  Slide 4
Variables and Fields
 ●
     Local variables
     –   inside of methods
     –   final variables can't change their values
 ●
     Class members (fields)
     –   inside of classes, outside of methods
 ●
     Global variables
     –   don't exist in Java
     –   can be simulated with static class members
 ●
     Constants are static final fields
Java course – IAG0040                                 Lecture 2
Anton Keks                                              Slide 5
Primitive types
 ●
     Only primitives are not objects in Java
     –   But, there are wrapper classes. Unlike in C, formats and
         sizes are standardized and are always the same.
     Primitive Size          Min       Max        Wrapper Default
     boolean 1 bit? false          true          Boolean false
     char        16 bit Unicode 0 216-1 (UTF-16) Character 'u0000'
     byte        8 bit   -128      127           Byte      (byte)0
     short       16 bit -215       215-1         Short     (short)0
     int         32 bit -231       231-1         Integer   0
     long        64 bit -263       263-1         Long      0L
     float       32 bit IEEE 754 IEEE 754 Float            0.0f
     double      64 bit IEEE 754 IEEE 754 Double           0.0d
     void        -       -         -             Void      -
Java course – IAG0040                                          Lecture 2
Anton Keks                                                       Slide 6
High-precision numbers
 ●
     BigInteger and BigDecimal
     –   these are classes, not primitives
     –   immutable
     –   cannot be used with operators, operations are
         methods
     –   slower, but long and precise
 ●   BigInteger – arbitrary long integers
 ●   BigDecimal – arbitrary precision fixed point
     numbers
Java course – IAG0040                                Lecture 2
Anton Keks                                             Slide 7
Fields (Members)
 ●
     A field (or member) is a class variable, holds its state
 ●
     Field names are in “lowerCamelCase”
 ●
     Constant names are in UPPER_CASE
 ●
     Initialized either automatically or manually
 ●   class MyClass {
        boolean isEmpty;                            // a field
        int count;                                  // a second field
         static String foo = “bar”;                 // a static field
         static final double E = Math.E;            // a constant
         static {
            foo = “fooBar”;                         // static block
         }
     }
Java course – IAG0040                                           Lecture 2
Anton Keks                                                        Slide 8
Methods
 ●
     A method is a class function, used to execute
     an operation on a class (aka send a message)
 ●   class MyClass {
        int count;                          // a field
        void doStuff(int count, short b) { // a method
           this.count = count * b;          // method body
        }
        int getCount() {              // second method,
           return count;              // returning a value
        }
     }
 ●   Methods can be overloaded
 ●   Parameters are passed as references
 ●   Local variables are enforced to be manually initialized
Java course – IAG0040                                          Lecture 2
Anton Keks                                                       Slide 9
Accessing fields and methods
 ●
     Java uses a dot '.' as an accessor operator
     –   MyClass myObject = new MyClass();
         myObject.isEmpty = true;            // field access
     –   myObject.setCount(5);               // method call
     –   int j = new MyClass().getCount();   // also allowed

 ●   Static fields and methods are accessed
     through the class itself, not instance variables
     –   int i = Integer.MAX_VALUE;

 ●
     “Deep” access is possible
     –   System.out.println(“Hello!”);


Java course – IAG0040                                   Lecture 2
Anton Keks                                               Slide 10
Access Modifiers and Visibility
 ●
     Several access modifiers are in use (keywords):
     –   private – accessible only in the same class
     –   default, no keyword (package local) – accessible only
         in the same package
     –   protected – accessible in the same package and
         subclasses
     –   public – accessible from anywhere
 ●   public class HelloWorld {         //   public class
        int a;                         //   package local field
        private int b;                 //   private field
        protected void doStuff() {}    //   protected method
        private HelloWorld() {}        //   private constructor
     }
Java course – IAG0040                                      Lecture 2
Anton Keks                                                  Slide 11
Encapsulation
 ●
     Use the most restrictive access modifiers as
     possible
 ●   Classes 'hide' implementations and internal
     details from their users
           –   This allows changing of internals any times
                without breaking any usages
           –   The less internals exposed, the easier is to
                change them
 ●
     Public/accessible interface must be obvious to
     use; don't do anything unexpected!
Java course – IAG0040                                     Lecture 2
Anton Keks                                                 Slide 12
Operators
 ●   Arithmetical: + - * / %
 ●   Bitwise: ~ & | ^ << >> >>>
 ●   Boolean: ! & | ^
 ●   Relational: < > <= >= == !=
 ●   Conditional: && || ^^ ternary: ? :
 ●   Assignment: = += -= *= /= %= <<= >>= &= |= ^=
 ●   String concatenation: +
 ●   Unary: + - ++ -- ! ~ (cast)
 ●   Type comparision: instanceof
Java course – IAG0040                        Lecture 2
Anton Keks                                    Slide 13
Naming convention
 ●
     Packages: lower case, reversed domain name as prefix
      –   net.azib.hello, java.util, com.sun.internal
 ●   Classes: camel case, should contain a noun
      –   String, ArrayList, System, VeryAngryDogWithTeeth
 ●   Interfaces: camel case, often adjectives
      –   Collection, List, Comparable, Iterable
 ●   Variables and fields: lower camel case, often include the class name
      –   isEmpty, count, i, veryLongArrayList
 ●   Methods: lower camel case, contain verbs
      –   doStuff, processRequest, length, getLength
 ●   Constants: underscore ('_') separated upper case
      –   Math.PI, MAX_VALUE, NAME_PREFIX
 ●
     Names should be obvious and descriptive!!!
      –   System.currentTimeMillis(), s.substring(0, 3), s.toCharArray()
Java course – IAG0040                                                       Lecture 2
Anton Keks                                                                   Slide 14

More Related Content

What's hot

Java Course 13: JDBC & Logging
Java Course 13: JDBC & LoggingJava Course 13: JDBC & Logging
Java Course 13: JDBC & LoggingAnton Keks
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
Core Java Certification
Core Java CertificationCore Java Certification
Core Java CertificationVskills
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Kernel Training
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaSanjeev Tripathi
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For SyntaxPravinYalameli
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7Deniz Oguz
 
An Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeAn Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeOmar Bashir
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Sagar Verma
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaAjay Sharma
 
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIsCS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIsKwangshin Oh
 

What's hot (20)

Java Course 13: JDBC & Logging
Java Course 13: JDBC & LoggingJava Course 13: JDBC & Logging
Java Course 13: JDBC & Logging
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Core Java Certification
Core Java CertificationCore Java Certification
Core Java Certification
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
Core java
Core java Core java
Core java
 
Core java
Core javaCore java
Core java
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
An Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeAn Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and Runtime
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Presentation to java
Presentation  to  javaPresentation  to  java
Presentation to java
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java features
Java featuresJava features
Java features
 
Java training in delhi
Java training in delhiJava training in delhi
Java training in delhi
 
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIsCS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
 

Viewers also liked

Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2Raghu nath
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the BasicsJussi Pohjolainen
 
Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of javavinay arora
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for DesignersR. Sosa
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handlingpinkpreet_kaur
 
Core java Basics
Core java BasicsCore java Basics
Core java BasicsRAMU KOLLI
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basicsmhtspvtltd
 
Java basics part 1
Java basics part 1Java basics part 1
Java basics part 1Kevin Rowan
 
Basics of java programming language
Basics of java programming languageBasics of java programming language
Basics of java programming languagemasud33bd
 
02 java basics
02 java basics02 java basics
02 java basicsbsnl007
 

Viewers also liked (20)

PALASH SL GUPTA
PALASH SL GUPTAPALASH SL GUPTA
PALASH SL GUPTA
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the Basics
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of java
 
Java basics
Java basicsJava basics
Java basics
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
2. Basics of Java
2. Basics of Java2. Basics of Java
2. Basics of Java
 
Java basics
Java basicsJava basics
Java basics
 
Core java Basics
Core java BasicsCore java Basics
Core java Basics
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basics
 
OOPs in Java
OOPs in JavaOOPs in Java
OOPs in Java
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java basics part 1
Java basics part 1Java basics part 1
Java basics part 1
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Ppt on java basics
Ppt on java basicsPpt on java basics
Ppt on java basics
 
Basics of java programming language
Basics of java programming languageBasics of java programming language
Basics of java programming language
 
02 java basics
02 java basics02 java basics
02 java basics
 

Similar to Java Course 2: Basics

Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to javaSadhanaParameswaran
 
Java Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyJava Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyAnton Keks
 
Java Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUIJava Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUIAnton Keks
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in javaElizabeth alexander
 
Programming with Threads in Java
Programming with Threads in JavaProgramming with Threads in Java
Programming with Threads in Javakoji lin
 
First fare 2011 frc-java-introduction
First fare 2011 frc-java-introductionFirst fare 2011 frc-java-introduction
First fare 2011 frc-java-introductionOregon FIRST Robotics
 
What's new in Scala and the Scala IDE for Eclipse for 2.8.0
What's new in Scala and the Scala IDE for Eclipse for 2.8.0What's new in Scala and the Scala IDE for Eclipse for 2.8.0
What's new in Scala and the Scala IDE for Eclipse for 2.8.0Miles Sabin
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.pptKhizar40
 
Java tutorials
Java tutorialsJava tutorials
Java tutorialssaryu2011
 
Understanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolUnderstanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolGabor Paller
 
Java Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionJava Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionAnton Keks
 
Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfKALAISELVI P
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design PatternsAnton Keks
 

Similar to Java Course 2: Basics (20)

Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
 
Java Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyJava Course 10: Threads and Concurrency
Java Course 10: Threads and Concurrency
 
Java Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUIJava Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUI
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
Programming with Threads in Java
Programming with Threads in JavaProgramming with Threads in Java
Programming with Threads in 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
Core javaCore java
Core java
 
What's new in Scala and the Scala IDE for Eclipse for 2.8.0
What's new in Scala and the Scala IDE for Eclipse for 2.8.0What's new in Scala and the Scala IDE for Eclipse for 2.8.0
What's new in Scala and the Scala IDE for Eclipse for 2.8.0
 
Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
 
java basic .pdf
java basic .pdfjava basic .pdf
java basic .pdf
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Understanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolUnderstanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer tool
 
Java Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionJava Course 9: Networking and Reflection
Java Course 9: Networking and Reflection
 
inheritance
inheritanceinheritance
inheritance
 
Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdf
 
core_java.ppt
core_java.pptcore_java.ppt
core_java.ppt
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
 

More from Anton Keks

Being a professional software tester
Being a professional software testerBeing a professional software tester
Being a professional software testerAnton Keks
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsAnton Keks
 
Choose a pattern for a problem
Choose a pattern for a problemChoose a pattern for a problem
Choose a pattern for a problemAnton Keks
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure JavaAnton Keks
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database RefactoringAnton Keks
 
Scrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineerScrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineerAnton Keks
 
Being a Professional Software Developer
Being a Professional Software DeveloperBeing a Professional Software Developer
Being a Professional Software DeveloperAnton Keks
 

More from Anton Keks (7)

Being a professional software tester
Being a professional software testerBeing a professional software tester
Being a professional software tester
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
 
Choose a pattern for a problem
Choose a pattern for a problemChoose a pattern for a problem
Choose a pattern for a problem
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure Java
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database Refactoring
 
Scrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineerScrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineer
 
Being a Professional Software Developer
Being a Professional Software DeveloperBeing a Professional Software Developer
Being a Professional Software Developer
 

Recently uploaded

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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
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
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
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
 

Recently uploaded (20)

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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
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!
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
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
 

Java Course 2: Basics

  • 1. Java course - IAG0040 Java Basics, Program Flow Anton Keks 2011
  • 2. Java type system ● static type checking ● provides (benefits) – by compiler, type – safety declarations required ● many bugs are type ● strongly typed errors – runtime checking – documentation – automatic conversions – abstraction allowed only when not ● high-level thinking loosing information – optimization ● memory-safe (performance) – array bounds checking, no pointer arithmetic Java course – IAG0040 Lecture 2 Anton Keks Slide 2
  • 3. Objects and Classes ● Classes introduce new types into a program ● First appeared in Simula-67 to define 'classes of objects' ● In OOP, Objects are instances of Classes ● All objects of the same class share – same properties: ● fields hold internal state – same behavior, dependent on the state: ● methods used for communication with objects Java course – IAG0040 Lecture 2 Anton Keks Slide 3
  • 4. References ● You manipulate objects with references – Like remote control of a TV is a reference to the TV ● Objects are stored on the heap, independently – String s; // is a reference to nothing – s = “hello”; // now s points to a newly created // String object on the heap ● You must create all the objects before using them – s = new Date(); ● There are many other built-in types (classes), like Integer, Date, Currency, BigDecimal, etc, and making your own types is the point of OOP Java course – IAG0040 Lecture 2 Anton Keks Slide 4
  • 5. Variables and Fields ● Local variables – inside of methods – final variables can't change their values ● Class members (fields) – inside of classes, outside of methods ● Global variables – don't exist in Java – can be simulated with static class members ● Constants are static final fields Java course – IAG0040 Lecture 2 Anton Keks Slide 5
  • 6. Primitive types ● Only primitives are not objects in Java – But, there are wrapper classes. Unlike in C, formats and sizes are standardized and are always the same. Primitive Size Min Max Wrapper Default boolean 1 bit? false true Boolean false char 16 bit Unicode 0 216-1 (UTF-16) Character 'u0000' byte 8 bit -128 127 Byte (byte)0 short 16 bit -215 215-1 Short (short)0 int 32 bit -231 231-1 Integer 0 long 64 bit -263 263-1 Long 0L float 32 bit IEEE 754 IEEE 754 Float 0.0f double 64 bit IEEE 754 IEEE 754 Double 0.0d void - - - Void - Java course – IAG0040 Lecture 2 Anton Keks Slide 6
  • 7. High-precision numbers ● BigInteger and BigDecimal – these are classes, not primitives – immutable – cannot be used with operators, operations are methods – slower, but long and precise ● BigInteger – arbitrary long integers ● BigDecimal – arbitrary precision fixed point numbers Java course – IAG0040 Lecture 2 Anton Keks Slide 7
  • 8. Fields (Members) ● A field (or member) is a class variable, holds its state ● Field names are in “lowerCamelCase” ● Constant names are in UPPER_CASE ● Initialized either automatically or manually ● class MyClass { boolean isEmpty; // a field int count; // a second field static String foo = “bar”; // a static field static final double E = Math.E; // a constant static { foo = “fooBar”; // static block } } Java course – IAG0040 Lecture 2 Anton Keks Slide 8
  • 9. Methods ● A method is a class function, used to execute an operation on a class (aka send a message) ● class MyClass { int count; // a field void doStuff(int count, short b) { // a method this.count = count * b; // method body } int getCount() { // second method, return count; // returning a value } } ● Methods can be overloaded ● Parameters are passed as references ● Local variables are enforced to be manually initialized Java course – IAG0040 Lecture 2 Anton Keks Slide 9
  • 10. Accessing fields and methods ● Java uses a dot '.' as an accessor operator – MyClass myObject = new MyClass(); myObject.isEmpty = true; // field access – myObject.setCount(5); // method call – int j = new MyClass().getCount(); // also allowed ● Static fields and methods are accessed through the class itself, not instance variables – int i = Integer.MAX_VALUE; ● “Deep” access is possible – System.out.println(“Hello!”); Java course – IAG0040 Lecture 2 Anton Keks Slide 10
  • 11. Access Modifiers and Visibility ● Several access modifiers are in use (keywords): – private – accessible only in the same class – default, no keyword (package local) – accessible only in the same package – protected – accessible in the same package and subclasses – public – accessible from anywhere ● public class HelloWorld { // public class int a; // package local field private int b; // private field protected void doStuff() {} // protected method private HelloWorld() {} // private constructor } Java course – IAG0040 Lecture 2 Anton Keks Slide 11
  • 12. Encapsulation ● Use the most restrictive access modifiers as possible ● Classes 'hide' implementations and internal details from their users – This allows changing of internals any times without breaking any usages – The less internals exposed, the easier is to change them ● Public/accessible interface must be obvious to use; don't do anything unexpected! Java course – IAG0040 Lecture 2 Anton Keks Slide 12
  • 13. Operators ● Arithmetical: + - * / % ● Bitwise: ~ & | ^ << >> >>> ● Boolean: ! & | ^ ● Relational: < > <= >= == != ● Conditional: && || ^^ ternary: ? : ● Assignment: = += -= *= /= %= <<= >>= &= |= ^= ● String concatenation: + ● Unary: + - ++ -- ! ~ (cast) ● Type comparision: instanceof Java course – IAG0040 Lecture 2 Anton Keks Slide 13
  • 14. Naming convention ● Packages: lower case, reversed domain name as prefix – net.azib.hello, java.util, com.sun.internal ● Classes: camel case, should contain a noun – String, ArrayList, System, VeryAngryDogWithTeeth ● Interfaces: camel case, often adjectives – Collection, List, Comparable, Iterable ● Variables and fields: lower camel case, often include the class name – isEmpty, count, i, veryLongArrayList ● Methods: lower camel case, contain verbs – doStuff, processRequest, length, getLength ● Constants: underscore ('_') separated upper case – Math.PI, MAX_VALUE, NAME_PREFIX ● Names should be obvious and descriptive!!! – System.currentTimeMillis(), s.substring(0, 3), s.toCharArray() Java course – IAG0040 Lecture 2 Anton Keks Slide 14