background preloader

Java Generics FAQs - Frequently Asked Questions

Java Generics FAQs - Frequently Asked Questions
All text and content found at URLs starting with (collectively, "the Java Generics FAQ") are the sole property of Angelika Langer. Copyright @ 2004-2019 by Angelika Langer . All rights reserved. Except as specifically granted below, you may not modify, copy, publish, sell, display, transmit (in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise), adapt, distribute, store in a retrieval system, create derivative works, or in any other way use or exploit the contents of the Java Generics FAQ, without the prior consent of the author. All rights, titles and interest, including copyrights and other applicable intellectual property rights, in any of the material belongs to the provider of the material. In particular, I do NOT grant permission to copy the Java Generics FAQ or any part of it to a public Web server. Other forms of non-commercial use may be allowed with prior written permission. Commercial Use Related:  JavaJava - General

Factory Chain: A Design Pattern for Factories with Generics by Hugo Troche - developer.*, Developer Dot Star Introduction The recent Java 5 (a.k.a. Java 1.5) generics implementation opens both new problems and new opportunities in the implementation of the "Gang of Four" (GoF) Factory patterns [Gamma, et al 1995]. On the one hand, we want a class factory to determine the type it will instantiate at run time. On the other hand, when we use generics correctly the compiler has to be able to determine the type of any call at compile time; casting with generics is considered unsafe. As we’ll see, these two opposing facts make it cumbersome to implement classic factories with generics. Factories The Factory pattern is powerful. In Figure 1 we have the interface Car. Figure 1. To implement this UML, we need is a class that will return a Car type according to some logic executed at run time. Listing 1. As we can see in ClassicFactory, the type of car that getCar() returns is decided at run time. Generics Object obj = ...; //The compiler will produce a warning for this cast. public class CustomVector Class

Developing an Enterprise Application for Oracle WebLogic Server This tutorial demonstrates how to use the IDE to create a web application that uses JavaServer Faces (JSF) 2.x and the Java Persistence API (JPA) 2.0 and then deploy the application to the Oracle WebLogic Server. In this tutorial you will register the WebLogic Server with the IDE, and then use wizards in the IDE to create a JDBC resource and entity and bean classes. You will then use the IDE to deploy the application to the server and register the new datasource. Contents To follow this tutorial, you need the following software and resources. Notes. This project uses the sample database that is available for either the MySQL or JavaDB database servers. Registering the Oracle WebLogic Server In this tutorial you will deploy a web application to the Oracle WebLogic Server. Downloading and Installing the Server Download the installer from the Oracle WebLogic Server Downloads page. Registering the Server with the IDE Open the Services window. Opening the Admin Console Note. Note. <? Note. Note. <?

Java Generics - Wilcard Instantiations of Parameterized Types Wildcard Instantiations of Parameterized Types JavaPro Online, May 2004 Angelika Langer & Klaus Kreft Wildcard Instantiations of Parameterized Types What is the purpose of wildcards? Using Wildcard Instantiations Using Wildcards With An Upper Bound Using Unbounded Wildcards Using Wildcards With A Lower Bound Remaining Limitations Summary References With the release of J2SE 1.5 (announced for August 2004) parameterized types and methods, also known as Java Generics, will be available as a new language feature of the Java programming language. 1.1 What is the purpose of wildcards? Consider a hierarchy of shape classes with an abstract superclass Shape and several subclasses such as Circle, Triangle, Rectangle, etc. public abstract class Shape { public abstract void draw(); } public final class Circle { ... Given a collection of shapes we might want to implement a drawAllShapes() method. This method can be invoked as follows: It does, however, disallow the following invocation: A “?”

The Java HotSpot Performance Engine Architecture Table of Contents Back to Top Chapter 1. Introduction and Overview The Java HotSpot™ virtual machine implementation (Java HotSpot™ VM) is Sun Microsystems, Inc.'s high-performance VM for the Java platform. The Java platform has become a mainstream vehicle for software development and deployment. The Java HotSpot VM builds upon Java technology's cross-platform support and robust security model with new features and capabilities for scalability, quality, and performance. The Java HotSpot VM supports virtually all aspects of development, deployment, and management of corporate applications, and is used by: Integrated development environments (IDEs) including the Sun Java Studio Tools, the NetBeans open source project, IBM's Eclipse, IntelliJ IDEA, Oracle JDeveloper, and others. Sun Microsystems, Inc. is also driving performance improvements through the use of various industry standard and internally developed benchmarks. Java HotSpot VM -- Built on a Solid Foundation Chapter 2. Overview

An Introduction to Generics in Java > Generic Methods Like generic classes, methods and constructors can also have type parameters. These parameters are declared prior to the return type of the method and can be used as return types, argument types, and in the throws clause. For example, see Listing 4. Listing 4 Generic method—finds max T 1 public <T extends Comparable> T max(T t1, T t2) { 2 if (t1.compareTo(t2) > 0) 3 return t1; 4 else return t2; 5 } Here, the method "max(...)" has a single type parameter "T" declared as "<T extends Comparable>". Listing 5 Clients of generic max method 1 Integer iresult = max(new Integer(100), new Integer(200)); 2 String sresult = max("AA", "BB"); 3 Number nresult = max(new Integer(100), "AAA"); // does not compile Line 1 of Listing 5 shows a typical invocation of our method. Line 2 of Listing 5 demonstrates the same functionality, only this time using a different implementor of Comparable, String. Line 3 of Listing 5 generates the following compiler error:

An Eclipse / GlassFish / Java EE 6 Tutorial » Programming For whatever reason my programming blog got lost in binary space. Because of the popularity of this page, I’ve restored in from a backup. I probably won’t restore the rest of the site though. Version 1.4, last updated May 23, 2011 – 11:10 The content of this tutorial is still relevant, but you may also consider my new open source Azzyzt JEE Tools, a set of Eclipse plugins that greatly simplify the process of creating a Java Enterprise application using the patterns outlined in this tutorial. In “4 – Equipment” I have committed myself to using Eclipse and the Java Enterprise Edition as my tools, while in “5 – Patterns And Languages” I’ve declared my high-level goals for implementing a next step of design pattern-based tools. I am no expert in this field, some important things may be missing, so just take the following as a set of things that work for me. Applicability This is a tutorial about using Eclipse and the GlassFish v3 Java application server to implement Java EE 6 applications. or

Java Generics - Introduction Language Features of Java Generics Introduction and Overview JavaPro Online, March 2004 Angelika Langer & Klaus Kreft Language Features - Overview and Introduction What is the purpose of generics? Generic Types Bounded Type Parameters Generic Methods Wildcard Instantiations of Parameterized Types Summary of Java Generics Language Features Implementation of the Java Generics Language Features Translation of Generics Type Erasure Summary References Language Features J2SE 1.5 will become available by mid of 2004 and will include support for generic types and methods (see / JDK15 /). What is the purpose of generics? The need for generic types stems from the implementation and use of collections, like the ones in the Java collection framework (see / JDK15 /). In Java, this kind of generic programming is achieved today (in non-generic Java) by means of Object references: a generic list is implemented as a collection of Object references. Generic Types Bounds Here is an example:

FriendPackages - APIDesign From APIDesign Common object oriented languages offer some kind of encapsulation, which often takes form of having public, protected and private access modifiers. Indeed, designers soon found that this is not enough and as such C++ has friend keyword and Java adds additional package private access type. The problem with the Java approach is that it generally dictates the files layout of your friends. Their sources need to be placed in the same directory. This often leads people to open the APIs up and use public or protected modifiers, sometimes annotating the method with a javadoc note do not call me, I am part of the implementation. One of the solutions is to add yet another modifiers to Java and introduce concept of friend packages. Imagine you have an API class called Item with public getter and setter while its constructor and its addChangeListener methods are dedicated only for friends. Code from See the whole file. Code from See the whole file.

An Introduction to Domain Driven Design Click here to view the complete list of archived articles This article was originally published in the Winter 2009 issue of Methods & Tools An Introduction to Domain Driven Design Dan Haywood, Haywood Associates Ltd, Today’s enterprise applications are undoubtedly sophisticated and rely on some specialized technologies (persistence, AJAX, web services and so on) to do what they do. The philosophy of domain-driven design (DDD) – first described by Eric Evans in his book [1] of the same name – is about placing our attention at the heart of the application, focusing on the complexity that is intrinsic to the business domain itself. Domain-driven design consists of a set of patterns for building enterprise applications from the domain model out. In this article I’m going to run through some of the main patterns of DDD, pick up on some areas where newbies seem to struggle, and highlight some tools and resources (one in particular) to help you apply DDD in your work.

Top 10 Causes of Java EE Enterprise Performance Problems Performance problems are one of the biggest challenges to expect when designing and implementing Java EE related technologies. Some of these common problems can be faced when implementing either lightweight or large IT environments; which typically include several distributed systems from Web portals & ordering applications to enterprise service bus (ESB), data warehouse and legacy Mainframe storage systems. It is very important for IT architects and Java EE developers to understand their client environments and ensure that the proposed solutions will not only meet their growing business needs but also ensure a long term scalable & reliable production IT environment; and at the lowest cost possible. This article will consolidate and share the top 10 causes of Java EE performance problems I have encountered working with IT & Telecom clients over the last 10 years along with high level recommendations. #1 - Lack of proper capacity planning Recommendations Recommendation