Sie sind auf Seite 1von 17

Basic Java Concepts Required for ADF Newbies who are migrating from ORACLE APPS background (like

me).
OOPs and Its Concepts in Java Objects represent some concepts or things and like any other objects in the real Objects in programming language have certain behavior, properties, type, and identity. In OOP based language the principal aim is to find out the objects to manipulate and their relation between each other. OOP offers greater flexibility and compatibility and is popular in developing larger application. Java is a object oriented programming and to understand the functionality of OOP in Java, we first need to understand several fundamentals related to objects. These include class, method, inheritance, encapsulation, abstraction, polymorphism etc. Class - It is the central point of OOP. In Java everything happens within class and it describes a set of objects with common behavior. The class definition describes all the properties, behavior, and identity of objects present within that class. A class is the blueprint from which individual objects are created. In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components The following Bicycle class is one possible implementation of a bicycle: class Bicycle { -- Variable declartions int cadence = 0; int speed = 0; int gear = 1; -- Below are the methods like our procedure/functions in plsql void changeCadence(int newValue) { cadence = newValue; } void changeGear(int newValue) { gear = newValue; } void speedUp(int increment) { speed = speed + increment;

} void applyBrakes(int decrement) { speed = speed - decrement; } void printStates() { System.out.println("cadence:"+cadence+" speed:"+speed+" gear:"+gear); } } /* public static int is a function returning int. public static void is a procedure */ OBJECTS - Objects are key to understanding object-oriented technology. Look around right now and you'll find many examples of real-world objects: your dog, your bicycle. Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of objectoriented programming. class BicycleDemo { public static void main(String[] args) { // Create two different Bicycle objects -- This is the syntax to create a object for any class. Bicycle bike1 = new Bicycle(); Bicycle bike2 = new Bicycle(); // Invoke methods on those objects.we can acees all the methods and variables in the class using the object. bike1.changeCadence(50); bike1.speedUp(10); bike1.changeGear(2); bike1.printStates(); bike2.changeCadence(50); bike2.speedUp(10); bike2.changeGear(2); bike2.changeCadence(40); bike2.speedUp(10); bike2.changeGear(3); bike2.printStates(); } }

Methods - We know that a class can define both attributes and behaviors. Again attributes are defined by variables and behaviors are represented by methods. In other words, methods define the abilities of an object. Inheritance - In object oriented programming classes can inherit some common behavior and state from others. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example, Bicycle now becomes the superclass of MountainBike, RoadBike, and TandemBike. In the Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses: Bicycle /|\ / Road \ Mount Bike \ Bike \ tandem Bike Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio. class MountainBike extends Bicycle { // new fields and methods defining a mountain bike would go here // the MountainBike subclass adds one field public int seatHeight; /* the MountainBike subclass has one constructor.Constructors are similar to methods, but with some important differences. Constructor name is class name. A constructors must have the same name as the class its in. Default constructor. If you don't define a constructor for a class, a default parameterless constructor is automatically created by the compiler. The default constructor calls the default parent constructor (super()) and initializes all instance variables to default value (zero for numeric types, null for object references, and false for booleans). public MountainBike(int startHeight, int startCadence, int startSpeed, int startGear) { super(startCadence, startSpeed, startGear); seatHeight = startHeight; }

// the MountainBike subclass adds one method public void setHeight(int newValue) { seatHeight = newValue; }

} Extends is the key word for inheriting a class. This gives Mountain Bike all the same fields and methods as Bicycle, yet allows its code to focus exclusively on the features that make it unique. Abstraction - The process of abstraction in Java is used to hide certain details and only show the essential features of the object. In other words, it deals with the outside view of an object (interface). Abstraction in Java allows the user to hide non-essential details relevant to user. To explain you this with an example.i will do that with acess specifiers.

Encapsulation: Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding. Encapsulation can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class. Access to the data and code is tightly controlled by an interface. Below is a table showing the effects of access specifies for class members. Y means yes. Blank means No. Specifier class subclass package world private Y protected Y Y Y public Y Y Y Y (none) Y Y /* File name : EncapTest.java */ public class EncapTest{ private String name; private String idNum;

private int age; public int getAge(){ return age; } } Here in the above example Variables/attributes are not accessible but methods are. Polymorphism Polymorphism is the ability of an object to take on many forms.I can have a same method name for many bt changing the calling parameters. Here is example class hai { public void saysomething(int newValue) { s.o.p(Hai);//s.o.p-> system.out.println } } class hai { public void saysomething (int newValue,int oldValue) { s.o.p(Bye);; } } I have same method name in the class. This Is End of OOPS Concepts. collection concepts: We definitely need this for ADF. As the name indicates, collections are a group of objects known as its elements. Basically it is a package of data structures that includes ArrayLists, LinkedLists, HashSets, etc. A collection is simply an object that groups multiple elements into a single unit. It is also called as a container sometimes. It is used to store, retrieve, manipulate, and communicate aggregate data. Typically, it represents data items that form a natural group and allows duplicate elements while others do not. It consists of both ordered and unordered elements. ArrayLists example:

/* Java ArrayList example. This Java ArrayList example describes the basic operations performed on the ArrayList. */ import java.util.ArrayList; import java.util.Iterator; public class ArrayListExample{ public static void main(String args[]){ // constructs a new empty ArrayList ArrayList arrayList = new ArrayList(); /* To specify initial capacity, use following constructor. ArrayList ArrayList = new ArrayList(100); To create ArrayList from Collection use following constructor ArrayList ArrayList = new ArrayList(Collection collection); In this case the initial capacity would be 110% of the size of the collection. */ /* To add value into ArrayList use add() method. Signature of the add() method is, boolean add(Object object) The value would be appended to the list. To insert value into ArrayList at particular index, use void add(int index, Object object) This method will shifts the subsequent elements of the list. To append all elements of the collection to existing list, use boolean addAll(Collection c) To insert all elements of the collection into existing list, use boolean addAll(int index, Collection collection) To replace particular element in the ArrayList, use Object set(int index, Object value)

It returns the previous element present at the specified index. */ arrayList.add(new Integer(1)); //adding value to ArrayList arrayList.add(new Integer(2)); arrayList.add(new Integer(3)); /* IMPORTANT : We CAN NOT add primitives to the ArrayList. We have to wrap it into one of the wrapper classes before adding. */ //get number of keys present in the ArrayList System.out.println("ArrayList contains " + arrayList.size() + " elements."); /* To check whether ArrayList is empty or not, use isEmpty() method. isEmpty() returns true is ArrayList is empty, otherwise false. Finding particular value from the ArrayList: ArrayList's contains() method returns boolean depending upon the presence of the value in given ArrayList. Signature of the containsValue method is, boolean contains(Object value) */ if( arrayList.contains( new Integer(1) ) ){ System.out.println("ArrayList contains 1 as value"); }else{ System.out.println("ArrayList does not contain 1 as value"); } /* Use get method of ArrayList to get value. Signature of the get method is, Object get(int index)

*/ Integer one = (Integer) arrayList.get(0); System.out.println("Value at 0 index is " + one); /* IMPORTANT: get method returns Object, so we need to downcast it. */ /* To search element within the ArrayList, use int indexOf(Object element) it returns the index of first occurrence of the specified element. To find last occurrence of the specified element, use int lastIndexOf(Object element) */ System.out.println("Index of first occurrence of 1 is " + arrayList.indexOf(new Integer(1))); /* To convert ArrayList to object array, use Object[] toArray() method. This method returns an Object array containing all elements of the ArrayList in the correct order. */ System.out.println("Converting ArrayList to Object array"); Object[] elements = arrayList.toArray(); for(int i=0; i < elements.length ; i++) System.out.println(elements[i]); /* To remove particular element from the ArrayList use, Object remove(int index) It returns the element that was removed from the list. To remove multiple elements from the ArrayList use, void removeRange(int fromIndex, int toIndex). It removes elements from the list whose index is between startIndex (inclusive) and toIndex(Exclusive). To remove all elements of the ArrayList use, void clear(). It removes all elements of the ArrayList. */ System.out.println("Is 1 removed from the ArrayList ? " + arrayList.remove(new Integer(1))); } } /* OUTPUT of the above given Java ArrayList Example would be:

ArrayList contains 3 key value pair. ArrayList contains 1 as value Value at 0 index is 1 Index of first occurrence of 1 is 0 Converting ArrayList to Object array 1 2 3 Is 1 removed from the ArrayList ? true */ LinkedList Example: import java.util.*; public class LinkedListExample{ public static void main(String[] args) { System.out.println("Linked List Example!"); LinkedList list = new LinkedList(); int num1 = 11, num2 = 22, num3 = 33, num4 = 44; int size; Iterator iterator; //Adding data in the list list.add(num1); list.add(num2); list.add(num3); list.add(num4); size = list.size(); System.out.print( "Linked list data: "); //Create a iterator iterator = list.iterator(); while (iterator.hasNext()){ System.out.print(iterator.next()+" "); } System.out.println(); //Check list empty or not if (list.isEmpty()){ System.out.println("Linked list is empty"); } else{ System.out.println( "Linked list size: " + size); } System.out.println("Adding data at 1st location: 55"); //Adding first list.addFirst(55); System.out.print("Now the list contain: "); iterator = list.iterator(); while (iterator.hasNext()){ System.out.print(iterator.next()+" "); } System.out.println(); System.out.println("Now the size of list: " + list.size()); System.out.println("Adding data at last location: 66"); //Adding last or append list.addLast(66); System.out.print("Now the list contain: "); iterator = list.iterator(); while (iterator.hasNext()){ System.out.print(iterator.next()+" "); }

System.out.println(); System.out.println("Now the size of list: " + list.size()); System.out.println("Adding data at 3rd location: 55"); //Adding data at 3rd position list.add(2,99); System.out.print("Now the list contain: "); iterator = list.iterator(); while (iterator.hasNext()){ System.out.print(iterator.next()+" "); } System.out.println(); System.out.println("Now the size of list: " + list.size()); //Retrieve first data System.out.println("First data: " + list.getFirst()); //Retrieve lst data System.out.println("Last data: " + list.getLast()); //Retrieve specific data System.out.println("Data at 4th position: " + list.get(3)); //Remove first int first = list.removeFirst(); System.out.println("Data removed from 1st location: " + first); System.out.print("Now the list contain: "); iterator = list.iterator(); //After removing data while (iterator.hasNext()){ System.out.print(iterator.next()+" "); } System.out.println(); System.out.println("Now the size of list: " + list.size()); //Remove last int last = list.removeLast(); System.out.println("Data removed from last location: " + last); System.out.print("Now the list contain: "); iterator = list.iterator(); //After removing data while (iterator.hasNext()){ System.out.print(iterator.next()+" "); } System.out.println(); System.out.println("Now the size of list: " + list.size()); //Remove 2nd data int second = list.remove(1); System.out.println("Data removed from 2nd location: " + second); System.out.print("Now the list contain: "); iterator = list.iterator(); //After removing data

while (iterator.hasNext()){ System.out.print(iterator.next()+" "); } System.out.println(); System.out.println("Now the size of list: " + list.size()); //Remove all list.clear(); if (list.isEmpty()){ System.out.println("Linked list is empty"); } else{ System.out.println( "Linked list size: " + size); } } } HashMap Example.

* Java HashMap example. This Java HashMap example describes the basic operations performed on the HashMap. */ import java.util.HashMap; import java.util.Iterator; public class HashMapExample{ public static void main(String args[]){ // constructs a new empty HashMap with default initial capacity HashMap hashMap = new HashMap(); /* To specify initial capacity, use following constructor HashMap HashMap = new HashMap(100); To create HashMap from map use following constructor HashMap HashMap = new HashMap(Map myMap); */

hashMap.put("One", new Integer(1)); // adding value into HashMap hashMap.put("Two", new Integer(2)); hashMap.put("Three", new Integer(3)); /* IMPORTANT : We CAN NOT add primitives to the HashMap. We have to wrap it into one of the wrapper classes before adding. */ /* To copy all key - value pairs from any Map to HashMap use putAll method. Signature of putAll method is, void putAll(Map m) */ //get number of keys present in the HashMap System.out.println("HashMap contains " + hashMap.size() + " key value pairs."); /* To check whether HashMap is empty or not, use isEmpty() method. isEmpty() returns true is HashMap is empty, otherwise false. /* Finding particular value from the HashMap: HashMap's containsValue method returns boolean depending upon the presence of the value in given HashMap Signature of the containsValue method is, boolean containsValue(Object value) */ if(hashMap.containsValue(new Integer(1))){ System.out.println("HashMap contains 1 as value"); }else{ System.out.println("HashMap does not contain 1 as value"); } /*

Finding particular Key from the HashMap: HashMap's containsKey method returns boolean depending upon the Presence of the key in given HashMap Signature of the method is, boolean containsKey(Object key) */ if( hashMap.containsKey("One") ){ System.out.println("HashMap contains One as key"); }else{ System.out.println("HashMap does not contain One as value"); } /* Use get method of HashMap to get value mapped to particular key. Signature of the get method is, Object get(Object key) */ Integer one = (Integer) hashMap.get("One"); System.out.println("Value mapped with key \"One\" is " + one); /* IMPORTANT: get method returns Object, so we need to downcast it. */ /* To get all keys stored in HashMap use keySet method Signature of the keysSet method is, Set keySet() */ System.out.println("Retrieving all keys from the HashMap"); Iterator iterator = hashMap.keySet().iterator(); while(iterator. hasNext()){ System.out.println(iterator.next()); } /* To get all values stored in HashMap use entrySet() method. Signature of the entrySet() method is, Set entrySet()

*/ System.out.println("Retrieving all values from the HashMap"); iterator = hashMap.entrySet().iterator(); while(iterator. hasNext()){ System.out.println(iterator.next()); } /* To remove particular key - value pair from the HashMap use remove method. Signature of remove method is, Object remove(Object key) This method returns value that was mapped to the given key, otherwise null if mapping not found. */ System.out.println( hashMap.remove("One") + " is removed from the HashMap."); } } /* OUTPUT of the above given Java HashMap Example would be : HashMap contains 3 key value pair. HashMap contains 1 as value HashMap contains One as key Value mapped with key "One" is 1 Retrieving all keys from the HashMap Three Two One Retrieving all values from the HashMap Three=3 Two=2 One=1 1 is removed from the HashMap. */ Hashmap needs Key and the value.

BASICS OF ADF

ADF
Architecture:
MVC Architecture Cleanly Separates UI, Business Logic and Page Navigation

Model layer represents the data values related to current page. View layer contains UI pages used to view or modify the data. Controller layer process the user inputs and determines the page navigation. Business service layer handles data access and encapsulates business logic. The core module in the framework is Oracle ADF Model layer. The Oracle ADF Model layer enables a unified approach to bind any user interface to any business service, without the need to write code. The other modules that make up a Fusion web application technology stack are:

Oracle ADF Business Components, which simplifies building business services. Oracle ADF Faces rich client, which offers a rich library of AJAX-enabled UI components for web applications built with Java Server Faces (JSF). Oracle ADF Controller, which integrates JSF with Oracle ADF Model. The ADF Controller extends the standard JSF Controller by providing additional functionality, such as reusable task flows, that passes control not only between JSF pages, But also between other activities, for instance method calls or other task flows. In Addition to JSF oracle also supports using the Swing, JSF, standard JSF view and MS Excel.

Simple Oracle ADF Architecture

ADF Business Components


When building service oriented java EE applications, you implement your core business logic as one or more business services. These backend services provide clients with a query, insert, update and delete business data as required while enforcing business rules.ADF business components are a prebuilt application objects that accelerate the job of delivering and maintain high performance, rich functional, and database centric services. They provide you with a ready to use implementation of java EE design patterns and best practices. ENTITY OBJECT EO represents row in a data base table. Simplifies DML for you. Encapsulates business logic. you can associate EO with other EO to reflect the relationship in the underlying schema. VIEW OBJECT VO object represents a SQL query and simplifies working with its result .you use SQL language to sort, aggregate, filter data into the shape required by end user. When end user modifies data in the user interface, VO collaborates with EO to consistently validate and save the changes. APPLICATION MODULE AM is transactional component that UI clients use to work with application data. It defines an updatable data model along with top level procedures and functions (called service methods) related to logical unit of work related to an end user task.

ADF Business Components Simplify Data Access and Validation

ADF Model Layer


In the model layer, Oracle ADF Model implements the JSR-227 service abstraction called the data control. Data controls abstract the implementation technology of a Business service by using standard metadata interfaces to describe the services operations and data collections, including information about the properties, methods, and types involved. Using JDeveloper, you can view that information as icons that you can then drag and drop onto a page. At that point, JDeveloper automatically creates the bindings from the page to the services. At runtime, the ADF Model layer reads the information describing your data controls and data bindings from appropriate XML files and implements the two-way connection between your user interface and your business service. Oracle ADF provides out-of-the-box data control implementations for the most common business service technologies. Using JDeveloper and Oracle ADF together provides you with a drag-anddrop data binding experience as you build your user interfaces. Along with support for ADF application modules, ADF Model also provides support for the following service technologies: Enterprise JavaBeans (EJB) session beans and JPA entities JavaBeans Web services XML CSV files

ADF Controller
In the controller layer, where handling page flow of your web application is a key concern, ADF Controller provides an enhanced navigation and state management model on top of JSF.jdeveloper allows you to declaratively create task flows where you can pass control between different types of activities such as pages and methods on managed beans, case statements, or calls to another task flows.

ADF Faces Rich Client


Oracle ADF emphasizes the use of the declarative programming paradigm throughout the development process to allow users to focus on the logic of application creation without having to get into implementation details. At a high level, the declarative development process for a Fusion web application Usually involves the following: creating an application workspace: Using a wizard, JDeveloper automatically adds the libraries and configuration needed for the technologies you select, and structures your application into projects with packages and directories. Modeling the database objects: You can create an offline replica of any database, and use JDeveloper editors and diagrammers to edit definitions and update schemas. Creating use cases: Using the UML modeler, you can create use cases for your application. Designing application control and navigation: You use diagrammers to visually determine the flow of application control and navigation. JDeveloper creates the underlying XML for you. Identifying shared resources: You use a resource library that allows you to view and use imported libraries by simply dragging and dropping them into your application. Creating business components to access data: From your database tables, you create entity objects using wizards or dialogs. From those entity objects, you create the view objects used by the pages in your application. You can implement validation rules and other types of business logic using editors. Implementing the user interface with JSF: JDevelopers Data Controls panel contains a representation of the view objects for your application. Creating a user interface is as simple as dragging an object onto a page and selecting the UI component you want to display the underlying data. For UI components that are not data bound, you use the Component Palette to drag and drop components. JDeveloper creates all the page code for you. Binding UI components to data using the ADF Model layer: When you drag an object from the Data Controls panel, JDeveloper automatically creates the bindings between the page and the data model. Incorporating validation and error handling: Once your application is created you use editors to add additional validation and to define error handling. Securing the application: You use editors to create roles and populate these with test users. You then use a flat file editor to define security policies for these roles and assign them to specific resources in your application. Testing and debugging: JDeveloper includes an integrated application server that allows you to fully test your application without needing to package it up and deploy it. JDeveloper also includes the ADF Declarative Debugger, a tool that allows you to set breakpoints and examine the data. Deploying the application: You use wizards and editors to create and edit deployment descriptors, JAR files, and application server connections.

Das könnte Ihnen auch gefallen