As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I want to learn features of java.util.concurrent libraries (so everything older, or non-java specific is no option for me).
I know basics and theory about concurrency and multithreading, I am not looking for theory.
I am now reading Java Concurrency in Practice. To be honest, I am quite disapointed of examples in this book. They're too short and simple and "dummy" for me. I am looking for some nice Java 5+ concurrency examples and exercies explained.
Is there something like that? I am quite afraid that If I don't use what I learned in JCIP very soon, I am going to forget it pretty much :/
Why not just search on GitHub (here is an example) ?
I have no affiliation, btw. But you can find projects that use "java concurrency" in the description or refer to the library in the code.
Another option is to think of your favourite Java frameworks. e.g. Tomcat or Quartz (though I don't know if they use Java 5 concurrency per se). Such frameworks would be excellent examples because it is real-world stuff.
definitely learn by making an application. for example, you could make your own real time online stock trading system or even an auction system. stuff like that that will thoroughly test your concepts. or you could participate in open source projects which focus on these types of applications..
I don't agree with your opinion of Java Concurrency in Practice, nevertheless, you might also want to look at "The Art of Multiprocessor Programming" by M. Herlihy and N. Shavait.
I recommend both books to understand more about the underlying principles of concurrency; rather than just skim read some code snippets.
Considering we are talking about "Shared state concurrency"
Look at the implementation of these two frameworks:
LMAX Disruptor :
They have very nicely used the concept of cache lines and ring buffers to achieve an extreme level of concurrency. Of course they are relying on atomic classes in concurrent utils plus their own ring buffer based concepts.
Google Guava Concurrent package:
They have decorated the Futures and Executor interfaces to offer real world concurrent event driven primitives. Underlying their framework is a good understanding of java concurrency classes and design patterns.
Shared state concurrency is not the only flavor, you may also like to check what Actor based frameworks e.g. AKKA are doing. This kind of concurrent programming is called message passing concurrency.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
so I have been through all the courses on programming, algorithms, etc. and did a lot of coding and some small projects.
Now, I may start working on a real project, real java SE program with gui and everything, not big, but much more complicated than average school project. My experience says that when I'm having more classes in my project (say 10), it kind of gets difficult to decide from where this constructor should be called, if I should pass this parameter here or create it later and how the whole thing should work together.
can you recommend me some resources on this? Should I go the way of studying the design patterns or how do I get to design apps that have nice architecture?
what is the procedure when developing an app with lots of classes and gui and so on?
thanks a lot
Design patterns usually help in making an application more maintainable and also more flexible. Although which design patterns to use relies essentially on what type of problem you have.
I did go through this book, which provided me with a quick and easy way to grasp what design patterns are and how they work.
Since you are dealing with GUI related applications, my only recommendation would be to try and make your GUI and Logic seperate. This should reduce clutter and should make your code more understandable since each class deals with items related to its layer (GIU or Logic).
Breaking things down also makes your application more flexible and reusable. Cohesion vs Coupling should also be another thing which you should keep in mind.
For design patterns : Head First Design Patterns & Design Patterns: Elements-Reusable-Object-Oriented
For Effective Programming Guidelines : Recommended reading Joshua Bloch's Effective Java
I personally like to thing in a TDD approach and love to read this blog Writing Testable Code by Misko Hevery.
It explains how should we focus on making code loosely coupled and testable.
And lastly keep exploring open source libraries and projects they will keep you up to date with latest trends and coding styles.
Head first Design Patterns or even the original Design patterns book from the Gang of Four (if you are the kind of person who likes more direct theory) for application design and I think it may be useful for you to have some knowledge of enterprise design patterns (Enterprise Integration Patterns from Hohpe and Wolf) will help you to understand how to implement flexible communication even in small SE projects. (Even these systems needs sometimes some kind of interprocess communication).
Additionally, the answers of Narendra and npinti are very good advices as well.
Have fun!
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
As the title states; the way one groups classes in PHP compared to for example Java, is it supposed to be different? I am currently reading O'Reilly's book OOA&D and in the chapters I've learned to use one class for each specific task and not one class for a grouped thing. Recently, I looked upon some code for a calendar, and the class was thousands of lines and had everything inside it that was to be used. However, this feels to me like it's violating the point of having many objects doing one task, but seeing as PHP is web development, is it supposed to be different? E.g. monster-classes.
Answer: use good design principles, even in PHP.
In addition to not creating Monster classes (also known as God-classes or objects) the following patterns are worth mentioning specifically:
Object naming:
Class names should be nouns because they are objects.
Method names should be verbs, because they are actions.
Cohesion. The short-version is basically: methods do one thing and do it well.
Property Visibility: Variables should private unless you've got a dang good reason not to, and in such case, use protected. Almost always you should avoid public.
Use interfaces and abstractions. Almost no one uses interfaces in PHP, but they should. It means that I can write my own implementation details but still hook in with some service that uses the class.
A somewhat outdated article on PHP design patterns that's still worth reading but is hard on the eyes.
Short-version:
If you are ever relying on an array to hold a particular structure it should probably be in a class.
An example from my life: ActiveRecord
What if I want to build a website that does not need any particular Active Record implemenation? At the moment, I'm quite stuck once I choose an implementation because they are all so unique. If they actually implemented an ActiveRecordInterface, I would be able to swap out my actual ActiveRecordEngine if I wanted to change.
I've learned object-oriented programming over 15 years ago and have been using it with C++, Java, Pascal. The PHP at that time was much less powerful than it is now. It took PHP about 10 years to implement Objects properly. They finally work fast, references are passed properly.
Unfortunately, many developers who started with PHP haven't got a grasp on a proper object-oriented design of software. The class is often used like a "library" and everyone speaks about de-coupling and having everything independent, so in many cases classes won't have parent.
There are no solid foundation what everyone could agree on and use. When you turn to the frameworks, some are better and other are worst in terms of the proper OOP. For instance, the proper Code Igniter framework is fast, secure, simple to use, but has very bad OOP design. The main reason is compatibility with PHP4.
For a better-structured frameworks, simply look at the source code of some of their components:
Tabs in Yii: http://code.google.com/p/yii/source/browse/tags/1.1.8/framework/web/widgets/CTabView.php
Tabs in Agile Toolkit:
https://github.com/atk4/atk4/blob/master/lib/View/Tabs/jUItabs.php
Tabs in CakePHP:
http://bakery.cakephp.org/%20articles/view/4caea0e3-ac74-409b-8693-435282f0cb67
My conclusion is that the language in itself is OK, but a lot of badly written code is out there.
It is not supposed to be so. Monser-classes are always "bad" because it is hard to fix bugs / implement new features or maintain your code.
Just because people have written the code and made the source available doesn't mean that it's always going to be good code.
The principles you're used to (small classes that do their one thing well) is a good one. But not every developer follows those principles.
In the PHP world, a lot of people have worked their way up through it from the early days, when everything was in a single procedural monolithic block of code -- and I've seen some horrendous examples of that still in everyday use. Converting one's mindset from that to an OOP structure at all can be a big leap for some people, and even for people who haven't come from that background, a lot of the code examples they would be learning from are, so it's not a surprise to see monster classes.
The short answer is to write code the way you're comfortable with and the way you've been taught. It sounds like you've got better coding practices ingrained into you than most PHP developers out there, so don't feel you have to change just because other people are doing things differently.
Don't know if this answers your question but my experience is that it's quite common for PHP scripts and plugins like the calendar you mention to be constructed in the monster-class kind of way because of PHP's poor support of namespaces and encapsulation. The same goes for Javascript which also tends to have superbig classes in some cases (jQuery for example).
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I just hear and see people saying scala is designed for MultiThread though it's actually for general purpose.
And it claims "The thing is that while you can make classes thread-safe in Java (if you know what you're doing ), Scala makes it easy and natural to do."
And indeed AKKA and Lift is written in scala.(actually java and scala)
But java also did improves in this aspect with the new package of java.util.concurrent.
So why didn't AKKA and Lift born in JAVA?
Maybe you will say scala makes java looks like C. :-)
Anyone can tell more insight or deeper thoughts on this?
I know the fact that it is possible to mix JAVA and scala. Scala is able to call seamlessly into Java code. So what java have,so does scala.
But what scala really improves that java haven't done yet regardless of different grammers?
Only some design like Actors/Agents or something else?
(note Actors/Agents are cannot solve all the problem in MultiThread.)
Or does scala compiler and adopting some functional language grammer really matters or helps more than in java?
I heard some news that scala is going to be able to adopt XText. To be able to leverage XText to write thread logic, not sure if this is true or not.
Scala looks like a mixture of languages and using this approach makes it more extensible to solve problems in this aspect?
UPDATE
Thanks for your excellent answers from different angles. I think they are all very good. No matter what side you are standing.
EDIT
Topic below (in SO one year ago) was asking about the similiar thing. The "constructive" conclusion is quite similiar. But this time ,some new points are coming out probably the way I am asking is a bit different. Just FYI.
Related:
What advantages does Scala have over Java for concurrent programming?
Java Concurrency: CAS vs Locking
Difference in MultiThread aspect between Java and C/C++
Pitfalls/Disadvantages of Functional Programming
Actually I am very interested in some one can answer this question in some brand new angle which could enlighten my mind , provide some idea unknown before.
But it's closed due to not constructiveness. :-)
I am not really an expert in this, but Scala is a (partly at least) a functional programming language while Java is not (it is imperative). One feature of functional programming is that it avoids (in a 'natural' way) side-effects.
Thread-safety on the other hand is pretty much about avoiding side-effects (i.e. different threads modifying same objects/parts of memory/other resources at the same time).
As it is today, I find Scala much worse than Java with respect to working with multiple threads.
The language specification doesn't define some really important things, that you would rely on, to make thread-safe code.
For instance, you should know that final instance fields are very special when working with multiple threads. They are guaranteed to have their initial value visible to all threads after the constructor has completed, even if the object is published with race conditions.
Scala makes no guarantees that a val will be compiled to a final field. It is usually the case, but since the specs don't state it clearly, you cannot take it for granted. Therefore, either you write boilerplate synchronization code that wouldn't exist in Java, or you write code that is not guaranteed thread-safe (and hope for the compiler to continue mapping your vals to final fields).
I'd say it not so much a matter of the actual language, but more about applying principles which ease concurrent programming, e.g. share nothing, message passing, immutable objects, side-effect free functions, etc. Scala is not a FP language in it's strictest sense, but it delivers access to functional programming techniques.
Abstractions like Actors/Reactors, which are part of the framework (not language), completely free the developer to handle threads and critical section synchronization directly. What's more: Since 2.9.x, parallel collections are directly included in the library.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
One of the major challenges for any java developer is try to keep in pace of development of the language and new tools. Java is evolving all the time and it happens often that I hear from a friend or colleague about some useful tool I had never heard of before.
I'd love to hear about how people find out when new java specs come out or an interesting, new tool is released? For example, what java blogs do you follow?
Listen to the Java Posse podcast. It is fun, it is relevant and gives a great feel of the Java (and wider JVM) community. It also has sections on Scala, Groovy, Android and (from time to time) Clojure.
Look for it on iTunes or your other podcatcher of choice.
Keep reading questions and answers on Stackoverflow. You'll learn something new almost daily.
Another blog I can recommend: http://infoq.com/
In general blogs and twitter are very good, if you come across a good coder or project, start following his/it's blog or twitter. To get you started, here's whom I follow on twitter for computer related stuff
I tend to browse directories like http://java-source.net/ and http://www.manageability.org/blog/java regularly.
Finally, I follow RSS feeds of http://freshmeat.net/tags/java-libraries and http://freshmeat.net/tags/java
HTH
http://www.theserverside.com/ has daily updates on new java/j2ee tools, resources and useful features/tutorials once in a while. That and SO are my daily visits.
and on a lighter note - http://thedailywtf.com/ :)
Attend your local JUG meetings.
Find your group here:
http://java.net/jugs-list
I follow articles on Dzone.
I find IBM developerWorks specifically the Java zone a good place to keep up with Java and the broader developerWorks site useful in keeping up with IBM related technologies.
my favorites :
Dzone Refcardz
java specialists
i hope these can help you , i got a lot from them
javablogs.com is quite helpful. It's some kind of blogs aggregator, 'blog community' for blogs which discuss Java technology regularly
Yes, you should follow blogs. Search for Java blog feeds with for example Google Reader, and add them. Then you'll get the latest news in one place.
I follow In Relation To actively. It contains the blogs from JBOSS employees. Following Oracle blogs makes also sense.
To keep updated your self with new technologies or tools, you can subscribe to RSS feed.
Can subscribe to any tool new letters, google news. Follow some bolgs. Use google reader.
you can participate in any mail group. This will keep you updated.
JavaOne is a great conference if your employer will spring for it (it's rather expensive, esp. if you're not already located on the west coast). It has a good mix of practical and higher-level, five-years-in-the-future stuff. It helps me to have a solid block of time away from the details of work, so I can focus just on exploring new technologies and ideas.
They're also planning some worldwide JavaOnes in places like India this year.
Coolest single bit of technology I found out about there: http://www.lambdacs.com/debugger/
A bit ancient, not network based:
spend time (have lunch) with fellow workers, speak about your duties, his problems, any hidden features of the used programming language you/he came across (from SO maybe), about the best IDE, ..., new games (ups, not working the whole time :-) )
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm a very experienced Java programmer who has spent my entire time working with Java 1.4 and earlier. Where can I find a quick reference that will give me everything I need to know about the new features in Java5 and later in a quick reference?
Java 5 new features
Java 6 new features
The real meat is in Java 5. Generics, Autoboxing, Annotations.
Here's a good place to start:
https://docs.oracle.com/javase/1.5.0/docs/relnotes/features.html
http://java.sun.com/developer/technicalArticles/releases/j2se15/
I would thoroughly recommend Java Concurrency in Practice by Brian Goetz, Tim Peierls, Joshua Bloch, and Joseph Bowbeer. It focusses solely on good concurrency coding, but includes excellent guidance on the new concurrency features in the Java 5 and 6 libraries.
Of course, it is no help at all on the other features, but if you ever deal with threads (and if you have a GUI, then you have threads), then this book is indispensable.
Java 5 introduced several major updates, such as language improvements (i.e. Annotations, Generics, Autoboxing, and improved syntax for looping) among many others. Annotation is a mechanism for tagging classes with metadata so that, they can be used by metadata-aware programs. Generics is a mechanism of specifying types for objects belonging to collections, such as Arraylists, so that type safety is guaranteed at compile time. Autoboxing allows the automatic conversions between primitive types (e.g. int) and wrapper types (e.g. Integer). Improved syntax for looping includes the enhancements for each loop for going through the items of array or collections comparatively easily.
Java 6 focuses on new specifications and APIs including XML, Web Services, JDBC version 4.0, programming based on Annotations, API’s for Java compiler and Application client GUI.With new compiler API added with Java 6, the java compiler can now receive and/or send output to an abstraction of the file system (programs can specify/process compiler output). Furthermore, Java 6 added enhancements to the applications GUI capabilities in AWT (faster splash screens and support for system tray) and SWING (better drag-and-drop, support for customizing layouts, multithreading enhancements and ability to write GIF images).
I can recommend Bruce Eckel's "Thinking in Java" 4th edition. He goes over a bunch of basic stuff you can skip, but his treatment of new 1.5 features is very thorough, especially the chapter on generics. And it is a good Java reference to own.
Dietel : How to program Java
This book is highly recommended. Teaches everything, does it well. Starts with simple Hello World and ends up in you writing your own BASIC compiler. handles databases as well. Does everything, uml, design. Just can't say enough about it.
And it is also beautiful book, I mean in design and color and it is not dry.