Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


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:




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?