Why isn't java.io.Bits public? [closed] - java

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 8 years ago.
Improve this question
I've done a lot with IO in Java and after looking for code to convert primitives to byte arrays and back I found source for java.io.Bits on one of the Java source code hosting websites. After a quick glance I realized it's exactly what I need, except it's package-private. So I made a copy which I made public, stored in my project's package and used (only in personal projects, I assure you). I find it very useful.
My question is, why is this package-private? I can see it being really useful for people who work with IO and I see no disadvantage from changing it's visibility to public (in rt.jar). Or is there perhaps an equivalent (and please don't mention other libraries)?
Here's a link to a randomly chosen website that has Java source for java.io.Bits: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/io/Bits.java

You'd have to ask one of the Java devs for sure, but by making it package private, the API can be treated as "internal" - i.e. it might change or disappear at any time. This means the API can be developed relatively quickly, and doesn't need to go through the same relatively thorough testing process that public APIs need to go through (since once they're released, they're stuck there for good.)
In short, making an API public has long term implications, and it requires much, much more work than just hitting a switch.
I would hazard a guess it started life as a "hacked together" group of functions useful for a few other classes in the IO package, and has just stayed there ever since.

It's package-private, sure, but there are public APIs that expose the same behavior, e.g. ByteBuffer.wrap(array).getInt(index) and the other methods on ByteBuffer. You're almost certainly better off using that properly designed, well-documented public API than trying to wrap or copy internal implementation details from Java.

Related

Is mixing Java and Kotlin a bad idea? [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 last year.
Improve this question
I've been trying to learn Kotlin but I find it to be a lot easier to learn when I can slowly apply it to things I'm working on in Java. Is it a bad idea to mix Java and Kotlin in production?
I know the overall goal is to use one or the other but is there anything wrong with the latter?
Objectively, we can say that compatibility with Java was one of Kotlin's main objectives, according to the official docs:
Kotlin is 100% interoperable with the Java programming language and major emphasis has been placed on making sure that your existing codebase can interact properly with Kotlin. You can easily call Kotlin code from Java and Java code from Kotlin. This makes adoption much easier and lower-risk. There’s also an automated Java-to-Kotlin converter built into the IDE that simplifies migration of existing code.
Many features are designed specifically to ease calling Java from Kotlin or vice versa: for example, the fact that property accessors are implemented in the same way as normal Java accessor methods, and the ability to implement SAM interfaces; and where Kotlin implements things differently, there are often annotations or other ways to use a Java-style implementation.
And in my own experience, there are no issues with mixing Java and Kotlin classes. Many of our projects have both (new classes written in Kotlin, a few old ones converted but many still in Java), and I'm not aware of any significant problems. I also converted a major project from Java to Kotlin, one class at a time — and after each one, everything still compiled and tested and ran perfectly.
Of course, new projects can be written in Kotlin from the start; but if you already know Java, mixing in some Kotlin is absolutely an option, and may be the easiest approach. You can convert parts to Kotlin piecemeal, when convenient, or leave them in Java long-term; pretty much everything just works, and you benefit from the parts that are in Kotlin. (You might even find that the way you write Java code benefits from knowing Kotlin!)

Can programs write their own code? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have noticed people speak about AI. My perception of A.I is code written such that a program can learn and simulate human behavior or even write its own code. I want to know if this can be done with java language on an IDE and if so an example code would be nice( code that can write its own code).
This can be done in any general-purpose language; there is nothing inherent to a computer language which would make the resulting program either able or unable to "learn" because learining is a much higher-level concept.
Also note that learning is not exactly a clear-cut concept: any program whose behavior changes based on previous input could be argued to have "learnt" something.
Historically, LISP has been perceived as a language particularly well-suited for AI work, and indeed was the primary language of the AI movement of the '80s. An important reason for this is that it is particularly easy to make a program which writes LISP programs. This not to say that a Java program couldn't be made to do the same; it would just be far less convenient and require much more library support.
What you refer to is called http://en.wikipedia.org/wiki/Self-modifying_code and is not the same as AI. It was often used in the assembler days for performance optimization (for example removing a conditional statement after it is sure it will never be executed again) but I have never seen it used in Java, even thought it surely is possible. See also Self modifying code in Java.
You might want to take a look at machine learning. This branch of AI revolves around systems which learn from data given to them. If you really want to learn, there is a course available on machine learning on coursera.org.

Reference doc to know the reason for making any rule in java [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
When something new is introduced Java, Oracle releases API doc and tutorials about how to use it and rules to follow. But does it release any document about the decisions or thoughts behind making the API that way or why the design is made like that.
For example,
Why we don't have static and protected outer classes.
Why we can't extend more than one class in Java.
Why Subclass overridden method cannot throw more exceptions than that of superclass method.
These might be obvious for someone who is working on Java for a long time and came to know about the valid reason behind these through experience.
But someone who is new to Java or someone who is using it for first time might not get it straightway.
So is there any reference doc released by Oracle which can be referred to know the reasons behind those rules.
Not for already existing rules but yes for newly added features in the particular release.
When ever java releases the new version, it is releasing the release not for that version regarding what all enhancements and features are added with the example.
Following is the link of Java 7 Release Note with all added features and enhancements -
http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-418459.html
On this page if you click on any feature, it will take to the detail of particular feature.
for example, on this page if you click on - Multithreaded Custom Class Loaders in Java SE 7 it will take to the page which contains the detail like what was the scenario where it was required and what is now supported to come out of it as -
http://docs.oracle.com/javase/7/docs/technotes/guides/lang/cl-mt.html
Well as others answered, there is no such documentation but you can easily find the answers on the net (on Java release notes, JSRs, forums...and this site.
Concerning your precise questions:
protected and static are by nature used in the scope of a class.
Inheritance is limited to one class because of the diamond problem .interface are Java's (and others such as c#) solution for that.
You cannot make incompatible changes on the methods through overriding. Adding one exception breaks the possibility of polymorphism. In that case, the code calling this method should know the exact implementation to correctly handle the exception.

Are Custom Libraries Unprofessional? [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
I'm still in university at the moment, and I'll likely either try to get security or programming job. My first programming course used a custom library that came with the book. It replaced and added many of the basics of Java like Arrays, completely custom math functions, input (scanner), Hashmaps, Queues and Stacks.
If I did land a programming gig, is it considered unprofessional to use a given custom library such as the one above? Either way, I've pretty much weaned myself off of 75% of the custom classes in favor of standard Java classes/objects, but I wanted to know if slipping in a premade class from a textbook is frowned upon. Thanks guys.
"Custom library" is too broad a category to be useful. Libraries that reimplement functionality that's standard in the JRE, such as the Collections API, are almost certainly useless, and probably did more harm than help in an educational setting. However, there are a large number of tools, particularly Google Guava (enhanced collections like multisets and bimaps), the Apache Commons tools (including string parsing, hashCode building, and the like), slf4j/log4j for logging, and runtime environments such as Spring that are basically standard in the industry.
The general principle is "don't reinvent the wheel". If you have an example class out of a textbook that gets a basic job done that isn't in the standard API or one of the de facto standard third-party libraries, by all means use it, but don't prefer some professor's half-baked and untested implementation to ones that have been in use by thousands of developers for years.
Good programmers write good code, excellent programmers find excellent code.
If your library is any good I suspect it's more a case of everyone grabbing a copy.

GWT code OR GWT Designer? [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 7 years ago.
Improve this question
I am new to GWT. I have a question. Which way is better to learn/use GWT programming. Either to learn using GWT by writing code for creating user interface OR through GWT Designer? I am also aking this question in the context of good programming practices & industry requirements.
I agree that code is much better. Plus later on when you want to do more fine tuning of your UI, exact position up to the pixel level for example, I have found that the Designer is not very easy for aligning widgets. You will need to get down to the code level anyway to do so.
Another benefit like it was already mentioned is you will get a better understanding of what is going on.
In my opinion it's better to learn to code it from scratch. That way you get a much better understanding of what the underlying code does. Because you'll also have to consider supporting the GUI you develop as well. And if you use a designer, while it's a lot quicker, it'll add it's own code to it, and it may not be pure GWT code.
So in my opinion, code it by hand, sure it'll take longer, but you'll understand it better, and be able to support it. And it'll be another great skill to your bow.
I use a mixed solution. Designer for main blocks and code for details...
I would suggest to start with coding rather than the designer. From a learning point of view, coding gives more information regarding how you can use and extend functionality.
Client side scripting involves good styling, alignment which you will understand once you work via the code and scripts.

Categories

Resources