Java_Presentation_Day_1

Views:
 
Category: Entertainment
     
 

Presentation Description

No description available.

Comments

Presentation Transcript

Course Outline – Day 1 : 

Course Outline – Day 1 Getting Started with Java SE                    What is Java? Compiling and Interpreting Applications The JDK Directory Structure A First Java Program          Object-Oriented Programming           Classes and Objects Abstract Classes Encapsulation Access Modifiers Inheritance Polymorphism

Course Outline – Day 1 : 

Course Outline – Day 1 Methods Calling/Defining Methods Method Parameters                Data Types and Variables Primitive Datatypes Arrays                Operators and Expressions

Getting Started With Java : 

Getting Started With Java What is Java Developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995 Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is general-purpose, class-based, and object-oriented.

Getting Started With Java : 

Getting Started With Java What is Java It is intended to let application developers "write once, run anywhere". Java is currently one of the most popular programming languages in use, and is widely used from application software to web application

Getting Started With Java : 

Getting Started With Java Compiling and Interpreting Applications When you develop a Java application, you develop one or more classes. Source code files have the Java extension. The Java compiler translates Java source code into a platform-independent format known as Java bytecodes. Files that contain Java bytecodes have the class extension.

Getting Started With Java : 

Getting Started With Java Compiling and Interpreting Applications The Java interpreter executes Java bytecodes. Java interpreters exist for all major operating systems, Java bytecodes can be run on most platforms. A Java interpreter is an implementation of a Java virtual machine (JVM). Most modern web browsers are Java enabled. This lets applets run within these browsers.

Getting Started With Java : 

Getting Started With Java The JDK Directory Structure

Getting Started With Java : 

Getting Started With Java A First Java Program public class HelloWorldApp {      public static void main(String[] args) {          System.out.println("Hello World!"); // Display the string.      } }

Object-Oriented Programming : 

Object-Oriented Programming Classes and Objects A class is a blueprint or prototype from which objects are created Java class objects exhibit the properties and behaviors defined by its class A class can contain fields and methods to describe the behavior of an object Objects are implementation of classes Objects share two characteristics: They all have state and behavior.

Object-Oriented Programming : 

Object-Oriented Programming Interfaces An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements. You cannot instantiate an interface.

Object-Oriented Programming : 

Object-Oriented Programming Interfaces An interface does not contain any constructors. All of the methods in an interface are abstract. An interface cannot contain instance fields. The only fields that can appear in an interface must be declared both static and final. An interface is not extended by a class; it is implemented by a class. An interface can extend multiple interfaces.

Object-Oriented Programming : 

Object-Oriented Programming Abstract Class used to declare common characteristics of subclasses An abstract class cannot be instantiated Abstract classes are declared with the abstract keyword Abstract classes are used to provide a template or design for concrete subclasses down the inheritance tree An abstract class can include methods that contain no implementation (Called abstract methods) If a class has any abstract methods, whether declared or inherited, the entire class must be declared abstract

Object-Oriented Programming : 

Object-Oriented Programming abstract class Shape { public String color; public Shape() { } public void setColor(String c) { color = c; } public String getColor() { return color; } abstract public double area(); }

Object-Oriented Programming : 

Object-Oriented Programming public class Point extends Shape { static int x, y; public Point() { x = 0; y = 0; } public double area() { return 0; } public double perimeter() { return 0; } public static void print() { System.out.println("point: " + x + "," + y); } public static void main(String args[]) { Point p = new Point(); p.print(); } }

Object-Oriented Programming : 

Object-Oriented Programming Packages Packages are used in Java in-order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier etc. A Package can be defined as a grouping of related types(classes, interfaces, enumerations and annotations ) providing access protection and name space management. Some of the existing packages in Java are:: java.lang - bundles the fundamental classes java.io - classes for input , output functions are bundled in this package

Object-Oriented Programming : 

Object-Oriented Programming Encapsulation Encapsulation provides the basis for hiding information from unwanted outside access Encapsulation is achieved by declaring variables as Private in a class- this gives access to data to only member functions of the class Protected keyword which gives the derived classes the access to the member variables of the base class- a variable declared as Protected can at most be accessed by the derived classes of the class

Object-Oriented Programming : 

Object-Oriented Programming Access Modifiers Java provides a number of access modifiers to help you set the level of access you want for classes as well as the fields, methods and constructors in your classes Private Fields, methods or constructors declared private are strictly controlled, which means they cannot be accesses by anywhere outside the enclosing class. A standard design strategy is to make all fields private and provide public getter methods for them. Protected It cannot be used for fields and methods within an interface. Fields, methods and constructors declared protected in a superclass can be accessed only by subclasses in other packages. Classes in the same package can also access protected fields, methods and constructors as well, even if they are not a subclass of the protected member’s class.

Object-Oriented Programming : 

Object-Oriented Programming Default Java provides a default specifier which is used when no access modifier is present. Any class, field, method or constructor that has no declared access modifier is accessible only by classes in the same package. The default modifier is not used for fields and methods within an interface. Public Fields, methods and constructors declared public (least restrictive) within a public class are visible to any class in the Java program, whether these classes are in the same package or in another package.

Object-Oriented Programming : 

Object-Oriented Programming Inheritance Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality Example: public class Employee { public String name; public String employeeId; } public class Manager extends Employee { }

Object-Oriented Programming : 

Object-Oriented Programming Polymorphism Wan entity behaves differently depending upon the context its being used. capability of an action or method to do different things based on the object that it is acting upon. Allows to define one interface and have multiple implementation

Object-Oriented Programming : 

Object-Oriented Programming Example: class Animal { void whoAmI() {System.out.println("I am a generic Animal.");}} class Dog extends Animal {void whoAmI() {System.out.println("I am a Dog.");}} class Cow extends Animal {void whoAmI() {System.out.println("I am a Cow.");}} class Snake extends Animal {void whoAmI() {System.out.println("I am a Snake.");}}

Object-Oriented Programming : 

Object-Oriented Programming class RuntimePolymorphismDemo {public static void main(String[] args) {Animal ref1 = new Animal();Animal ref2 = new Dog();Animal ref3 = new Cow();Animal ref4 = new Snake();ref1.whoAmI();ref2.whoAmI();ref3.whoAmI();ref4.whoAmI();}}

Methods : 

Methods Calling/Defining Methods Public MyClass { Public String getMyMethod(){ Return “Hello”; } Public static void main(String str[]){ MyClass _myclass = new MyClass(); _myClass.getMyMethod(); } }

Methods : 

Methods Method Parameters Public MyClass { Public String getMyMethod(String value){ Return “Hello”+value; } Public static void main(String str[]){ MyClass _myclass = new MyClass(); _myClass.getMyMethod(value); } }

Datatypes and Variables : 

Datatypes and Variables Primitive Datatypes Java represents different types of basic data and what operations the data types can undergo. Eight keywords specify the eight kinds of basic data, which are referred to as primitives. These are

Datatypes and Variables : 

Datatypes and Variables

Datatypes and Variables : 

Datatypes and Variables Arrays  int intArray = new int[10];  String stringArray = new String[10]; char data[] = {'a', 'b', 'c'}; intArray[0] = 1; stringArray[0] = “Hello World”;

Datatypes and Variables : 

Datatypes and Variables Rules of defining variables No spaces in variable names No special symbols in variable names such as !@#%^&* Variable names can only contain letters, numbers, and the underscore ( _ ) symbol Variable names can not start with numbers, only letters or the underscore ( _ ) symbol (but variable names can contain numbers)

Operators and Expressions : 

Operators and Expressions Simple Assignment Operators

Operators and Expressions : 

Operators and Expressions Arithmetic Operators

Operators and Expressions : 

Operators and Expressions Unary Operators

Operators and Expressions : 

Operators and Expressions Equality and Relational operators

Operators and Expressions : 

Operators and Expressions Conditional Operators

Operators and Expressions : 

Operators and Expressions Conditional Operators

Operators and Expressions : 

Operators and Expressions Expressions (x*x + y*y > 25) && (x > 0)

Questions ????

authorStream Live Help