How is Java an 'imperative' programming language and not a 'declarative' one?

15.2k Views Asked by At

Specially in comparison to C/C++ (which are declarative), how is Java imperative?

3

There are 3 best solutions below

1
On

C/C++ is imperative too.

Edit: Imperative is do this, then do that, then do the next thing and so on. Declarative is, this are the rules, now what's the answer to this question. Google, you'll find plenty of info.

1
On

You are confusing the concepts, C and C++ are not declarative languages. Refer to Declarative Programming and Imperative Programming. Basically, with declarative languages (e.g. Prolog), you specifiy what you want to accomplish, without specifying how to accomplish it, which contrasts with imperative languages.

0
On

For future readers, although both Java and C/C++ are usually written imperatively, Both languages support writing in a more declarative way for example by applying functional principles.

In the past years it has been more and more prominent and is encouraged by many influential software engineers such as Uncle Bob to go to a more functional (and thus declarative) approach.

In Java this was made much more easy with Java 8 that introduced Lambda, Streams etc.

I read this book about functional programming in Java and found it useful: https://pragprog.com/book/vsjava8/functional-programming-in-java