All about java.util.Date | Jon Skeet's coding blog. This post is an attempt to reduce the number of times I need to explain things in Stack Overflow comments. You may well be reading it via a link from Stack Overflow – I intend to refer to this post frequently in comments. Note that this post is mostly not about text handling – see my post on common mistakes in date/time formatting and parsing for more details on that. There are few classes which cause so many similar questions on Stack Overflow as java.util.Date. There are four causes for this: Date and time work is fundamentally quite complicated and full of corner cases. It’s manageable, but you do need to put some time into understanding it.The java.util.Date class is awful in many ways (details given below).It’s poorly understood by developers in general.It’s been badly abused by library authors, adding further to the confusion.
TL;DR: java.util.Date in a nutshell The most important things to know about java.util.Date are: You should avoid it if you possibly can. Now, onto the details… Quora. Winterbe/java8-tutorial. Understanding sun.misc.Unsafe - DZone Java. The biggest competitor to the Java virtual machine might be Microsoft's CLR that hosts languages such as C#. The CLR allows to write unsafe code as an entry gate for low level programming, something that is hard to achieve on the JVM. If you need such advanced functionality in Java, you might be forced to use the JNI which requires you to know some C and will quickly lead to code that is tightly coupled to a specific platform. With sun.misc.Unsafe, there is however another alternative to low-level programming on the Java plarform using a Java API, even though this alternative is discouraged.
Nevertheless, several applications rely on sun.misc.Unsafe such for example objenesis and therewith all libraries that build on the latter such for example kryo which is again used in for example Twitter's Storm. Therefore, it is time to have a look, especially since the functionality of sun.misc.Unsafe is considered to become part of Java's public API in Java 9. Native Memory Allocation. Pattern (Java Platform SE 6) Java.lang.Object java.util.regex.Pattern All Implemented Interfaces: Serializable public final class Patternextends Objectimplements Serializable A compiled representation of a regular expression.
A regular expression, specified as a string, must first be compiled into an instance of this class. A typical invocation sequence is thus Pattern p = Pattern.compile("a*b"); Matcher m = p.matcher("aaaaab"); boolean b = m.matches(); A matches method is defined by this class as a convenience for when a regular expression is used just once. Boolean b = Pattern.matches("a*b", "aaaaab"); is equivalent to the three statements above, though for repeated matches it is less efficient since it does not allow the compiled pattern to be reused. Instances of this class are immutable and are safe for use by multiple concurrent threads. Summary of regular-expression constructs Backslashes, escapes, and quoting Character Classes The precedence of character-class operators is as follows, from highest to lowest: Since: flags.
10 Things You Didn't Know About Java. So, you’ve been working with Java since the very beginning? Remember the days when it was called “Oak”, when OO was still a hot topic, when C++ folks thought that Java had no chance, when Applets were still a thing? I bet that you didn’t know at least half of the following things. Let’s start this week with some great surprises about the inner workings of Java. 1. There is no such thing as a checked exception That’s right! Today, everyone agrees that checked exceptions were a mistake.
Do you want proof that the JVM doesn’t know such a thing? 01.public class Test { 04. public static void main(String[] args) { 05. doThrow(new SQLException()); 08. static void doThrow(Exception e) { 09. 12. 13. static <E extends Exception> 14. void doThrow0(Exception e) throws E { 15. throw (E) e; Not only does this compile, this also actually throws the SQLException, you don’t even need Lombok’s @SneakyThrows for that. More details about the above can be found in this article here, or here, on Stack Overflow. 2. 2. Parameter passing - Is Java "pass-by-reference"
Get Involved. Android is an open-source software stack created for a wide array of devices with different form factors. The primary purposes of Android are to create an open software platform available for carriers, OEMs, and developers to make their innovative ideas a reality and to introduce a successful, real-world product that improves the mobile experience for users. We also wanted to make sure there was no central point of failure, where one industry player could restrict or control the innovations of any other. The result is a full, production-quality consumer product with source code open for customization and porting. Android was originated by a group of companies known as the Open Handset Alliance, led by Google. The companies that have invested in Android have done so on its merits because we believe an open platform is necessary. Uncontrolled customization can, of course, lead to incompatible implementations. On Memory Leaks in Java and in Android. | Development Chaos Theory.
Just because it’s a garbage collected language doesn’t mean you can’t leak memory or run out of it. Especially on Android where you get so little to begin with. Now of course sometimes the answer is that you just need more memory. If your program is a Java command line program to load the entire road map of the United States to do some network algorithms, you probably need more than the default JVM configurations give you.
Sometimes it’s not even a full-on leak, but a large chunk of memory isn’t being released in time as a consequence of some holder object that isn’t being released in time. There are some tools that can help. With Android, you can use DDMS to get an idea what’s going on, and you can even dump a snapshot of the heap by using the Dump HPROF File option. Public void onCreate(Bundle savedInstanceState) { ... Now what this does is rather simple: we have a queue of items which are put into a linked list, and our background thread loads those items, one at a time. No? Track memory allocations.
Despite the impressive hardware of the first Android phones (T-Mobile G1 and ADP1) writing efficient mobile applications is not always straightforward. Android applications rely on automatic memory management handled by Dalvik's garbage collector which can sometimes cause performance issues if you are not careful with memory allocations. In a performance sensitive code path, like the layout or drawing method of a view or the logic code of a game, any allocation comes at a price. After too many allocations, the garbage collector will kick in and stop your application to let it free some memory. Most of the time, garbage collections happen fast enough for you not to notice.
Most of the time, garbage collection occurs because of tons of small, short-lived objects and some garbage collectors, like generational garbage collectors, can optimize the collection of these objects so that the application does not get interrupted too often. Trail: Learning the Java Language: Table of Contents (The Java™ Tutorials) Interface vs abstract class.