Basic Syntax อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 2.

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

INHERITANCE BASICS Reusability is achieved by INHERITANCE
CS 211 Inheritance AAA.
Intro to OOP with Java, C. Thomas Wu Inheritance and Polymorphism
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Object Oriented Programming: Java Edition By: Samuel Robinson.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
The Java Programming Language
Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
JAVA BASICS Prepared by The Smartpath Information Systems
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
Introduction to programming in the Java programming language.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
CSC 142 Computer Science II Zhen Jiang West Chester University
1 Interfaces and Abstract Classes Chapter Objectives You will be able to: Write Interface definitions and class definitions that implement them.
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
1 Abstract Classes and Interfaces. 2 The abstract Modifier  The abstract class –Cannot be instantiated –Should be extended and implemented in subclasses.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Interfaces and Inner Classes
Access Modifiers Control which classes use a feature Only class-level variables may be controlled by access modifiers Modifiers 1. public 2. protected.
Java Basic Syntax. Object - Objects have states and behaviors. –Example: A dog has states-color, name, breed as well as behaviors -wagging, barking, eating.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Programming in java Packages Access Protection Importing packages Java program structure Interfaces Why interface Defining interface Accessing impln thru.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
OOP Basics Classes & Methods (c) IDMS/SQL News
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
BY:- TOPS Technologies
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Programming in Java: lecture 7
2.7 Inheritance Types of inheritance
Inheritance and Polymorphism
Lecture 2: Data Types, Variables, Operators, and Expressions
University of Central Florida COP 3330 Object Oriented Programming
CS230 Tutorial Week 3.
Interface.
Java Programming Language
Inner Classes 29-Nov-18.
Interfaces.
Inheritance Inheritance is a fundamental Object Oriented concept
elementary programming
Chapter 14 Abstract Classes and Interfaces
Inner Classes 1-May-19.
Chapter 11 Inheritance and Encapsulation and Polymorphism
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Basic Syntax อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 2

Basic Syntax: Case Sensitivity - Java is case sensitive, which means identifier Helloand hello would have different meaning in Java. MyFirstJavaClass Class Names - For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. Example : class MyFirstJavaClass

Basic Syntax: myMethodName Method Names - All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. Example : public void myMethodName()

Basic Syntax: Program File Name - Name of the program file should exactly match the class name. When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match your program will not compile). Example: MyFirstJavaProgram Assume 'MyFirstJavaProgram' is the class name. MyFirstJavaProgram.java Then the file should be saved as 'MyFirstJavaProgram.java'

Basic Syntax: public static void main(String args[]) - Java program processing starts from the main() method which is a mandatory part of every Java program.

Java Identifiers: All Java components require names. Names used for classes, variables and methods are called identifiers. In Java, there are several points to remember about identifiers. They are as follows: All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). After the first character identifiers can have any combination of characters.

Java Identifiers: A key word cannot be used as an identifier. Most importantly identifiers are case sensitive. Examples of legal identifiers: age, $salary, _value, __1_value Examples of illegal identifiers: 123abc, -salary

Java Modifiers: Like other languages, it is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers: Access Modifiers: default, public, protected, private Non-access Modifiers: final, abstract, static

Java Modifiers: Access Modifiers Access Modifiers: default, public, protected, private Example : public public class Employee(){} private private double salary; protected protected String name ;

Java Modifiers: Non-access Modifiers Non-access Modifiers: final, abstract, static Example : abstract public abstract void setName(){} final public final class TestFinal(){} static public static void main(String[] args){}

Java Variables: We would see following type of variables in Java: Local Variables

Java Variables: We would see following type of variables in Java: Class Variables (Static Variables)

Java Variables: We would see following type of variables in Java: Instance Variables (Non-static variables)

Java Arrays: Arrays are objects that store multiple variables of the same type. However, an array itself is an object on the heap. We will look into how to declare, construct and initialize in the upcoming chapters. score [0][1] [2][3] [4]

Java Enums: Enums were introduced in java 5.0. Enums restrict a variable to have one of only a few predefined values. The values in this enumerated list are called enums. With the use of enums it is possible to reduce the number of bugs in your code.

Java Enums: Example

Java Keywords:

Comments in Java Java supports single-line and multi-line comments very similar to c and c++. All characters available inside any comment are ignored by Java compiler.

Inheritance: In Java, classes can be derived from classes. Basically if you need to create a new class and here is already a class that has some of the code you require, then it is possible to derive your new class from the already existing code. This concept allows you to reuse the fields and methods of the existing class without having to rewrite the code in a new class. In this scenario the existing class is called the superclass and the derived class is called the subclass.

Inheritance:

Interfaces: In Java language, an interface can be defined as a contract between objects on how to communicate with each other. Interfaces play a vital role when it comes to the concept of inheritance. An interface defines the methods, a deriving class(subclass) should use. But the implementation of the methods is totally up to the subclass.

Interfaces:

Q&AQ&A The End