명령형 프로그래밍은 기본 상태를 조작 할 수있는 명령문을 순차적으로 실행합니다.
자바의 일부 명령형 프로그래밍 :
Customer customer = null;
customer.setFirstName("Foo"); // the customer variable is still null at this point
customer = new Customer(); // too late!
선언적 프로그래밍이 없습니다 : 당신은 위의 순서 밖으로을 할 경우, 그것은 널 포인터 예외가 발생할 것이라고
Customer customer = null;
// first create a customer and have the variable reference it
customer = new Customer();
// the state of the customer variable has changed
// set the id on whatever object is *currently* being referenced by the variable
customer.setId(1);
// the state of the Customer object has changed
customer.setFirstName("Bob");
customer.setLastName("McBob");
주
주 또는 질서, 단지 선언.여기
은 간단한 예입니다 -이 XML 조각이 선언으로 간주 될 수 :
<NewCustomers>
<Customer>
<Id>1</Id>
<FirstName>Bob</FirstName>
<LastName>McBob</LastName>
</Customer>
</NewCustomers>
그것은 고객 객체가 내장 취득 방법에 대해 얘기하지 않는, 그냥 부품을 선언합니다. 위의 해석 및 실행 방법은 프로그래밍 환경에 달려 있습니다.