Java Collections: Framework Or a library? [duplicate] - java

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is the difference between a framework and a library?
Java documentation says The collections framework
Why is java collections called a framework and not a library?
Now I am more confused about what I can expect from a framework as to a library..

The following characteristics differentiate Frameworks from libraries:
inversion of control - In a framework, unlike in libraries or normal user applications, the overall program's flow of control is not dictated by the caller, but by the framework.
default behavior - A framework has a default behavior. This default behavior must actually be some useful behavior and not a series of no-ops.
extensibility - A framework can be extended by the user usually by selective overriding or specialized by user code providing specific functionality.
non-modifiable framework code - The framework code, in general, is not allowed to be modified. Users can extend the framework, but not modify its code.
Basically a framework is a type of a library whose behavior cannot be changed. For instance, you can extend class ArrayList or HashMap in java, but you cannot change the behavior of those classes.

Related

How to check whether my app following S.O.L.I.D. Principle [duplicate]

This question already has answers here:
Are there any static analysis tools that will report how closely the SOLID principles are followed?
(2 answers)
Closed 7 months ago.
I have created one app in kotlin, I tried to follow all OOPS and SOLID principles in my app. But after development of whole app i want to check whether any class is missing or breaking rules of SOLID principle.
Try 1
Review the whole code in each class whether they are following SOLID principles or not. But if i have large number of files then it will take more time.
How can we do it automatically to check whether my app is following SOLID principles.
It is not possible to check it with an automatic tool. The concepts of S.O.L.I.D. principles cannot be converted in formulas to be calculated automatically.
Just to have an idea. The I means Interface Segregation Principle:
... ISP splits interfaces that are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them
How much an interface should be small? Who decides if two methods are related to the same concept so they can not be separated in different interfaces? There is no way to do that automatically
Let's consider another principle. The Dependency Inversion Principle:
... the "inversion" concept does not mean that lower-level layers depend on higher-level layers directly. Both layers should depend on abstractions (interfaces) that expose the behavior needed by higher-level layers.
Basically you should depends on interfaces instead of concrete classes. But what happens if you are using an external library that doesn't use interfaces? Your code is correct, but is not following the Dependency Inversion Principle so you will have a false negative in this case.
Similar considerations can be done also for other principles.

The difference between framework code and ordinary code [duplicate]

This question already has answers here:
What is a software framework? [closed]
(12 answers)
Closed 3 years ago.
Can someone just show me an example of a code snippet that is meant for a framework (Spring or Guice) vs how it would be written in an ordinary form? It could be any framework for either C++ or Java
The C++ language doesn't make that distinction. A "framework" is often a library that provides a more-or-less coherent set of types, objects, and functions for solving a particular class of problems. For example, a GUI framework manages a graphical user interface; a Unit Testing framework supports unit testing, etc.
When you build a library you use a librarian to combine various object files together into a library file. When you build an application using that library you link to the library; the linker pulls in the various parts of the library that your program uses.

Java 7u40 Java SE 8 sun.reflect.Reflection.getCallerClass [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i have read the following post
Oracle Discontinuing sun.reflect.Reflection.getCallerClass
i was wondering what this change really means.
1). Means that this class sun.reflect.Reflection.getCallerClass will be rewritten to provide more security in Java reflection?
2). Means this class will no more be needed? maybe another approach?
3). Reflection will be over in Java 8. method.invoke will throw UnsupportedOperationException.??
4). this will affect anything related to Spring or AspectJ Aspect Oriented Programming?
i was wondering because we use Reflection method.invoke to provide some flags to the class before being send to the DB. this raises another question if reflection is over what approach can i use to provide my behavior above. i think AOP is a way to go.
thanks a lot.
Short answer: you only need to worry if you use sun.reflect.Reflection.getCallerClass. (And it is ludicrous to suggest that Java reflection is being withdrawn.)
A longer answer is that the functionality provided by that method is being reworked in JEP 176. The old method is actually being removed ... not just deprecated. It is a method in the sun.* tree, and application code should not be calling it directly. The current plan seems to be:
to remove this functionality entirely if no valid use cases can be identified, or
provide a replacement API, or at least defer the hard removal of the current method from Java 7
The original primary use-case for this private API was for security managers and the like that needed to know who called them. Unfortunately, this approach has proven to be fragile. A new approach to that problem (using message handles) has been designed. Rather than leaving this API in place for application code to use willy-nilly for dubious purposes, they have decided to force the issue.
However, there are signs of push-back on this issue because it is causing breakages in things like Groovy and JRuby.
References:
This message thread: http://www.mail-archive.com/mlvm-dev#openjdk.java.net/msg05325.html
Your specific questions:
1). Means that this class sun.reflect.Reflection.getCallerClass will be rewritten to provide more security in Java reflection?
See above. I suspect that there is a security related motivation for this.
UPDATE - This confirms it: https://partners.immunityinc.com/idocs/Java%20MBeanInstantiator.findClass%200day%20Analysis.pdf
2). Means this class will no more be needed? maybe another approach?
See above. They haven't yet determined whether the functionality is needed.
3). Reflection will be over in Java 8. method.invoke will throw UnsupportedOperationException.??
No to both of these. This is just about a specific method of a specific class in the sun.* packages.
It does not impact on reflection in general or on method.invoke().
4). this will affect anything related to Spring or AspectJ Aspect Oriented Programming?
Probably not. It would only affect those technologies if they relied on that particular method. If they do, then the respective library maintainers will need to ensure that the Java team are aware of the use-cases that require this. I imagine the maintainers are tracking this.

What would be the best equivalent of Java annotations in C++? [duplicate]

This question already has answers here:
Adding Annotation Syntax to C++ Source
(2 answers)
Closed 10 years ago.
I'm a Java programmer and I'm learning c++ 11 which I like a lot. I really think it's great but I'm missing the notion of annotation in this language.
First, is there something close to Java style annotation in the standard ? I think there's not after my research.
What would be the closer, standard way (no compiler extensions), to "simulate" a Java style annotation in c++ ?
And please don't mention the c++ 11 override annotation. I mean user defined annotations.
There is nothing like annotations in standard C++. For alternatives, it depends on why you want to use annotations.
one of the use of annotations in Java is to mark some methods or classes with meta-data so it can be retrieved through reflection at runtime. But reflection in standard C++ is very limited, so there is nothing like that. I haven't had a look at boost::reflect, maybe it can be useful to you.
another use of annotations is to have tools that intervenes at compile time to inject some code or to do checks. The tool to do this kind of stuff in C++ is the preprocessor.

Web Frameworks: How is Play different from Spring MVC? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
The Play Framework offers the following quick overview, but with the exception of the Groovy template engine (which you can get in Spring MVC if you want), Spring seems to offer all the same features and more...
Fix the bug and hit reload! Edit your Java files, save, refresh your browser and see the results immediately! No need to compile, deploy or restart the server. Spring does this, which can get annoying.
Stateless model Play is a real "Share nothing" system. Ready for REST, it is easily scaled by running multiple instances of the same application on several servers. Typical Spring applications have a stateless application tier; it's not purely RESTful unless you want to be, but Spring is "ready for REST".
Efficient template system A clean template system based on Groovy as an expression language. It provides template inheritence, includes and tags. Spring uses Java, but Groovy is an option too.
Resolve errors quickly When an error occurs, play shows you the source code and the exact line containing the problem. Even in templates. Spring does this as well.
All you need to create a cool web application Provides integration with Hibernate, OpenID, Memcached... And a plugin system. Spring integrates with everything and more.
Pure Java Code with Java, use any Java library and develop with your preferred IDE. Integrates nicely with eclipse or netbeans. Spring is pure Java as well.
Really fast Starts fast and runs fast! Subjective, but Spring is pretty quick.
So what does the Play Framework actually do differently than Spring MVC?
In a nutshell what can Spring do that Play framework cannot (and vice-versa)?
I find the "pure Java" claim on either side very funny.
Of course, it's unrealistic for a project to use absolutely nothing but java. Still, a "pure Java" label should have some standards, I don't think either framework qualifies.
Play actually modifies the semantics of Java language. That is all right as long as it's clearly specified. If you do some byte code manipulation, just be honest about it. Usually it's done by AOP-ish trick, instance methods are decorated with additional behaviors, their manifest behaviors - these written in the code, are usually preserved. This is not too hard to accept, we can pretend our code are subclassed by the framework and our methods are overridden with additional behavior.
In Play, one static method calling another static method in the same class can have magical effects, and the behavior is nothing like a method call. That is a huge problem, if a Java programmer can no longer be certain what a static method call is.
Spring - well, their Java part is still pure Java all right. But it's so magical(from java's POV), and depends so heavily on a heavy framework, calling Spring "pure Java", is like calling a burger "pure vege" if we overlook the meat. The meat is the best part!

Categories

Resources