background preloader


Facebook Twitter

Java is Pass-by-Value, Dammit! - Scott Stanchfield. Serbo-Croation Translation Available!

Java is Pass-by-Value, Dammit! - Scott Stanchfield

Woohoo! Jovana Milutinovich gratiously offered to translate this article to Serbo-Croation! You can read the translation here: Thanks a million, Jovana! Introduction I finally decided to write up a little something about Java's parameter passing. I'm a compiler guy at heart. Pass-by-value The actual parameter (or argument expression) is fully evaluated and the resulting value is copied into a location being used to hold the formal parameter's value during method/function execution. Pass-by-reference The formal parameter merely acts as an alias for the actual parameter. Java is strictly pass-by-value, exactly as in C. When the method or constructor is invoked (15.12), the values of the actual argument expressions initialize newly created parameter variables, each of the declared Type, before execution of the body of the method or constructor. [In the above, values is my emphasis, not theirs] Java 7: Project Coin in code examples. We Recommend These Resources This blog introduces - by code examples - some new Java 7 features summarized under the term Project Coin.

Java 7: Project Coin in code examples

The goal of Project Coin is to add a set of small language changes to JDK 7. These changes do simplify the Java language syntax. Less typing, cleaner code, happy developer ;-) Let's look into that. Prerequisites Install Java 7 SDK on your machine Install Eclipse Indigo 3.7.1 You need to look out for the correct bundles for your operating system. In your Eclipse workspace you need to define the installed Java 7 JDK in your runtime.

Next you need to set the compiler level to 1.7 in Java > Compiler. Project CoinImproved literals A literal is the source code representation of a fixed value. Thought Spearmints: @SuppressWarnings and its applicability to various program elements. I cooked up a toy Java 5 class that generates warnings of the "unchecked" family when compiled: package pholser.util; import java.util.Arrays; public class Stack<T> { private final Object[] storage; private int top; public Stack() { = new Object[ 5 ]; } public Stack( final Stack<T> other ) { = (Object[]); =; final T currentTop = (T) storage[ top ]; } public void push( final T item ) { checkPrecondition( isFull(), "can't push a full stack" ); storage[ top++ ] = item; } public T pop() { checkPrecondition( isEmpty(), "can't pop an empty stack" ); return (T) storage[ --top ]; } public T peek() { checkPrecondition( isEmpty(), "can't peek an empty stack" ); return (T) storage[ --top ]; } @Override public boolean equals( final Object that ) { if ( this == that ) return true; if ( that == null || !

Thought Spearmints: @SuppressWarnings and its applicability to various program elements

GetClass().equals( that.getClass() ) ) return false; final Stack<? > other = (Stack<? Sure enough, no warnings. Fair enough. Golden. Or. Eamonn McManus's Blog: Getting rid of unchecked warnings for casts. Posted by emcmanus on March 30, 2007 at 3:27 AM PDT If you've ever made a serious effort to get rid of "unchecked" warnings from the Java compiler (the ones it gives you with -Xlint:unchecked) then you'll probably have found some cases where you know a cast is correct but you can't convince the compiler of it.

Eamonn McManus's Blog: Getting rid of unchecked warnings for casts

Is there anything better than adding @SuppressWarnings("unchecked") around the whole method? The problem with the @SuppressWarnings solution is that it's much too broad. It suppresses warnings for the whole method, even though it's just one little cast that you want to allow. What if there's another place in the method where the compiler would have given a warning, telling you about a real problem? 10 examples of Enum in Java - What is Enum in Java Enum in Java is a keyword, a feature which is used to represent fixed number of well known values in Java, For example Number of days in Week, Number of planets in Solar system etc.

10 examples of Enum in Java -

Enumeration (Enum) in Java was introduced in JDK 1.5 and it is one of my favorite features of J2SE 5 among Autoboxing and unboxing , Generics, varargs and static import. One of the common use of Enum which emerged in recent years is Using Enum to write Singleton in Java, which is by far easiest way to implement Singleton and handles several issues related to thread-safety and Serialization automatically.

By the way, Java Enum as type is more suitable to represent well known fixed set of things and state, for example representing state of Order as NEW, PARTIAL FILL, FILL or CLOSED. Java SE APIs & Documentation. Get Ready for Java 7 with the Free JDK 7 Reference Card. Oracle submitted the release content for both Java SE 7 and 8 to the JCP at the end of last year.

Get Ready for Java 7 with the Free JDK 7 Reference Card

The JDK 7 and 8 JSRs represented Oracle's "Plan B" approach for separating JDK 7 into two separate releases. In the months since, JDK 7 has progressed to the Developer Preview milestone and the final version isn't too far off. To provide developers with an at-a-glance reference guide of all the essential JDK 7 elements, has published the JDK 7 Reference Card. Java Basics: Table of Contents [First Draft - June 2005] Trail: Essential Classes: Table of Contents (The Java™ Tutorials) Trail: JDBC(TM) Database Access: Table of Contents (The Java™ Tutorials) Java Programming Notes.

Java Notes.

Java Programming Notes


Top Ten New Things You Can Do with NIO. New I/O? Why do we need a new I/O? What's wrong with the old I/O? There's nothing wrong with the classes in the package; they work just dandy -- for what they do. But it turns out there are quite a lot of things the traditional Java I/O model can't handle. Things like non-blocking modes, file locks, readiness selection, scatter/gather, and so on. NIO brings a host of powerful new capabilities to the Java platform. In this article I'm not going to explain buffers, channels, selectors, and the other denizens of the NIO depths. Annotations. Many APIs require a fair amount of boilerplate code.


For example, in order to write a JAX-RPC web service, you must provide a paired interface and implementation. This boilerplate could be generated automatically by a tool if the program were “decorated” with annotations indicating which methods were remotely accessible. Other APIs require “side files” to be maintained in parallel with programs. For example JavaBeans requires a BeanInfo class to be maintained in parallel with a bean, and Enterprise JavaBeans (EJB) requires a deployment descriptor. It would be more convenient and less error-prone if the information in these side files were maintained as annotations in the program itself. The Java platform has always had various ad hoc annotation mechanisms. Annotations do not directly affect program semantics, but they do affect the way programs are treated by tools and libraries, which can in turn affect the semantics of the running program.