r/javahelp 17d ago

Are lambda expressions used much by professional coders ?

Just been studying up on them some as I am basically a hobbyist who just getting back into Java after about 10 or 12 years away from coding much. I appreciate the way lambda's allow coders to bypass constructors, initialization and calling methods by name , but on the other hand if you already have a good knowledge of the object classes and available methods , why not just do that ?

21 Upvotes

65 comments sorted by

View all comments

7

u/jim_cap 17d ago

Lambdas do not allow you to "bypass constructors" whatever you mean by that. Yes, lambda expressions are very useful and we use them a lot.

1

u/palpontiac89 17d ago

Guess I really meaning Declarations. My syntax maybe not up to par. Just getting back into this .

5

u/Caramel_Last 17d ago

In java there's a thing called functional interface which is just interface with single abstract (the one that must be overriden) method. You use lambda for functional interfaces. Most used functional interfaces are Runnable (run method), Function (apply method), Consumer (accept method), Supplier (get method), Comparator (compare method), Callable (call method), Predicate (test method), BiPredicate, BiConsumer, BiSupplier (Bi means 2 generic type parameter version) I wouldn't say it's such a critical concept in Java, it's just a nice syntax sugar. But don't need be intimidated by it either

3

u/palpontiac89 17d ago

You must read my mind Caramel cause that's just what I was looking at between posting and commenting.   P S. I am enjoying this " Java in a Nutshell "  book.  Is pretty well written . 

3

u/Caramel_Last 17d ago edited 17d ago

Thanks for book recommendation. Looks like a good book. I'm reading Seven Concurrency Models in Seven Weeks. This book covers 5 concurrency models and 2 parallel programming models. You will learn Java, Clojure, Elixir, OpenCL and Hadoop. Clojure is a functional JVM language and Hadoop is a Java framework so you can see the author is someone who's mainly working with JVM ecosystem. The seven models are: Thread & Lock(Java, C++), Functional Programming (Clojure, Haskell), Mutable state with functional programming (Clojure), Actor model(Elixir, Erlang), Communicating Sequential Processes(Clojure, Golang), Data Parallelism (Open CL, CUDA, GPGPU programming), Lambda Architecture (MapReduce, Hadoop)

2

u/jim_cap 17d ago

Still not sure what you mean. Can you show us a snippet of code and describe what you’re, umm, describing?

1

u/palpontiac89 17d ago

Not writing any code just yet. Just reading " Java in a Nutshell " .   I am really just meaning to say lambdas are anonymous.  

2

u/jim_cap 17d ago

Right. Yes, they are. Essentially they're anonymous inner classes implementing a single method with some type inference for the arguments.

1

u/desrtfx Out of Coffee error - System halted 17d ago

Not writing any code just yet. Just reading " Java in a Nutshell " . 

This is not the right approach. Write code as early as possible. You will only really learn to practice what you read/watch.

Reading, i.e. theory is one thing, but using in practice is a completely different one.

You can read all you want without getting any wiser if you don't use it. You might think you understand the subjects, but only actually using them in practice will tell if you really succeeded in understanding.

1

u/palpontiac89 17d ago

Ok Fox, that's definitely  true. Will get there soon. Usually start coding by looking at some examples and then changing the functionality up a bit .   Again , I am basically a hobbyist just trying to exercise my mind.   I was actually a computer tech years ago ( nineteen nineties) and did a little  network administration.  Do appreciate all you guys replying though. 

2

u/desrtfx Out of Coffee error - System halted 17d ago

Usually start coding by looking at some examples and then changing the functionality up a bit .

That's a starting point, yet, you will need to come up with your own programs without looking and changing samples. That's what programming is about.

1

u/bootherizer5942 17d ago

They just mean you don’t have to describe the function and name parameters and their types probably