Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java

What is Imperative Programmering in JAVA?

I have got black out and forgot what's Imperative Pogramming in JAVA. Can you give me a good example? :smile: :pray:

2 Answers

I want to preface this by saying if you are just beginning to learn about programming it isn't important to know about imperative programming for right now.

Does that means that there is a class that it has one method that do lots of works?

It means it has statements which tell it step by step how to do the task you want it to do.

Imperative programming refers to the "type" (paradigm) of the language. In this context, imperative means we write programming statements for "how" to do it. For example, I want to calculate the total cost for buying things at the store. How do i do that? We'll 1st step is to do this, 2nd step is to do that, then etc...

public static void main(String args[]){
  // 1st step is to calculate total price of all items.
  // 2nd step is to multiple by sales tax percentage.
  // 3rd step is to add sales tax to subtotal.
  // 4th step is the return total.
}

Java is imperative, but it is also object-oriented, but it is also functional. In more advanced lessons you might learn about how Java also has other functional (paradigms) by using "lambdas".

Examples of other programming "types" (paradigms): Haskell is functional Ruby is partly functional Python is partly functional Javascript is partly functional

More information/reading:

https://en.wikipedia.org/wiki/Comparison_of_programming_paradigms

http://cs.lmu.edu/~ray/notes/paradigms/

https://en.wikipedia.org/wiki/Imperative_programming

Thank you so much.. That's what I wanted to hear. :pray:

This blog article might help you (with some examples) http://blog.jooq.org/2015/09/17/comparing-imperative-and-functional-algorithms-in-java-8/

I also like this post from msdn (just explanations) https://msdn.microsoft.com/library/bb669144(v=vs.100).aspx

thanks but it's kinda blur information. Does that means that there is a class that it has one method that do lots of works?