Generic « Data Types « Java Articles

Java Articles
1. Build Deploy
2. Class
3. Core Library
4. Data Types
5. Database JDBC
6. Design
7. Development
8. File Input Output
9. Graphics Desktop
10. J2EE Enterprise
11. J2ME Wireless
12. JVM
13. Language
14. Library Product
15. Network
16. Security
17. SOA Web Services
18. Test
19. Web Development
20. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Products
Java by API
Photoshop Tutorial
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Articles » Data Types » Generic 
1. Beware the dangers of generic Exceptions
"While working on a recent project, I found a piece of code that performed resource cleanup. Because it had many diverse calls, it could potentially throw six different exceptions. The original programmer, in an attempt to simplify the code (or just save typing), declared that the method throws Exception rather than the six different exceptions that could be thrown. This forced the calling code to be wrapped in a try/catch block that caught Exception. The programmer decided that because the code was for cleanup purposes, the failure cases weren't important, so the catch block remained empty as the system shut down anyway."

2. Generic Types, Part 2
"The generic types of java.util are relatively easy: for the most part they are collections classes, and type variables are used to represent the element type of the collection. Several important generic types in java.lang are more difficult. They are not collections, and it is not immediately apparent why they have been made generic. Studying these difficult generic types gives us a deeper understanding of how generics work and introduces some concepts that we have not yet covered in this chapter. Specifically, we'll examine the Comparable interface and the Enum class (the supertype of enumerated types, described later in this chapter) and will learn about an important but infrequently used feature of generics known as lower-bounded wildcards."

3. Generic Types, Part 1
"Editor's note: Java in a Nutshell, 5th Edition covers the extensive changes and new features in 5.0, chief among them generic types. In part one of this two-part excerpt, author David Flanagan walks through how to use generic types, and in part two next week, he covers how to write your own generic types and generic methods."

4. A Generic MVC Model in Java
"Model-View-Controller (MVC) is a widely used design pattern, especially popular in graphical user interface (GUI) programming. JDK 1.5 introduces parameterized types, or generics. Combining the two allows for a generic implementation of the MVC design pattern, freeing the programmer from writing code that handles the registration and notification of listeners, as well as from writing getter and setter methods for the properties of models. This article shows how this can be accomplished."

5. Java Tech: Generics and You
"How much do you know about generics? Based on your amount of generics knowledge, are you comfortable with having to maintain another developer's generified code, should your project manager tell you to do so? Perhaps you have not taken the time to determine how much you know about generics and how much you still have to learn. If you would like to assess your generics I.Q., you might find this article a helpful test of your generics knowledge."

6. (Not So) Stupid Questions 16: What's the Difference Between Wildcard Generics and no Generics?
"Editor's note: Sometimes the most interesting discussions begin when someone says, "This may be a stupid question, but ...." If the person asking the question has taken the time to think about the problem before asking, the question is often not stupid at all. The uncertainty points out an ambiguity in the specs, holes in the docs, or a search for how more experienced programmers might address a particular problem. From time to time, we will print one of the "(Not So) Stupid Questions" we receive and invite our readers to answer the question in the feedback section."

7. Using and Programming Generics in J2SE 5.0
"Generics are one of the most frequently requested language extensions to Java, and they have been finally added in J2SE 5.0. This article provides an introduction to programming with generics."

8. Writing a Generic Service Loader: How to Take advantage of Java's Flexibility and Power
"By building up a library of services, you provide a solution that is dynamically configurable at runtime for each user environment. Java's ability to create a class by name makes this easy. And Java applets require sophisticated, dynamic class loading, Java comes with some very powerful capabilities for client/server design built right into it. This program is an interesting example that shows you how to take advantage of these powers."

9. Preparing for Generics
"Generics -- also commonly known as parameterized types -- have been used in other computing languages for years. And now, due to popular demand, generics is slated to be added to the Java language with the 1.5 release."

10. JDK 1.5 Preview: Addition of Generics Improves Type Checking
"This article introduces the new generics feature by examining Sun's example pre-release implementation. It demonstrates how to use generics in a sample program, an extensible networked multimedia framework (NMF). Finally, it goes over using generics in the Collections classes."

11. Java theory and practice: Going wild with generics, Part 2
"There's a simple rule, called the get-put principle, which tells us which kind of wildcard to use. The get-put principle, as stated in Naftalin and Wadler's fine book on generics, Java Generics and Collections (see Resources), says:"

12. Magic with Merlin: The generics prototype
"The forthcoming beta release of Tiger, version 1.5 of J2SE scheduled for the first half of 2004, includes several language-level changes to the Java platform. With the exception of the addition of some minor new keywords like strictfp and assertions, the Java programming language itself hasn't changed much since the addition of inner classes back in version 1.1. This next version of the standard edition is expected to have a number of significant changes. Assuming Java Specification Requests (JSRs) 14 and 201 make their way into JSR 176 (the Tiger release), you'll find support for parameterized data types (also called generics), system-supported enumerations, autoboxing, enhanced for loops, and static imports. Let's explore the early access to these features Sun provides in a prototype."

13. Java theory and practice: Generics gotchas
"Generic types (or generics) bear a superficial resemblance to templates in C++, both in their syntax and in their expected use cases (such as container classes). But the similarity is only skin-deep -- generics in the Java language are implemented almost entirely in the compiler, which performs type checking and type inference, and then generates ordinary, non-generic bytecodes. This implementation technique, called erasure (where the compiler uses the generic type information to ensure type safety, but then erases it before generating the bytecode), has some surprising, and sometimes confusing, consequences. While generics are a big step forward for type safety in Java classes, learning to use generics will almost certainly provide some opportunity for head-scratching (and sometimes cursing) along the way."

14. Java theory and practice: Going wild with generics, Part 1
"Wildcards ? the funky question marks where a type parameter should go ? are a means of expressing a type constraint in terms of an unknown type. They were not part of the original design for generics (derived from the Generic Java (GJ) project); they were added as the design process played out over the five years between the formation of JSR 14 and its final release."

15. Catching more errors at compile time with Generic Java
"The problem with using class Object is that there is no way for us to specify what types we intend to store in a generic object. In contrast, parametric types allow us to specify what types we intend to store in a generic object. After you have made your intent clear, the compiler can enforce your wishes. This allows the compiler to catch more errors that would otherwise occur at run time. To catch the error at run time, the offending code must be executed, which may or may not happen depending on the test cases. Therefore, it is possible that errors, which are easily detectable with the use of parametric types, will ship in production code. Catching more errors at compile time is an exceedingly good reason to use GJ."

16. Classworking toolkit: Reflecting generics
"Many articles have been written to cover using the Generics feature of Java 5 (including those linked in Resources). For this article, I assume you already know the basics of generics. We'll get started with some sample code and then jump right into how you access generic information at run time."

17. Classworking toolkit: Generics with ASM
"To access generics information without loading classes into the JVM, you need a way of reading the generics information stored inside the binary class representation. In some prior articles, I've shown how the ASM classworking library provides a very clean interface for reading and writing binary classes. In this article, I'll show how you can use ASM both to retrieve the raw generics information out of class files and to interpret the generics in a useful manner. Before digging into the ASM details, I'll start off with a look at how generics information is actually encoded into the binary classes."

18. JCP Watch: Java Help 2.0 and the Generic Connection Framework Specifications Released
"This week two JSRs reached the final specification deliverable making them endorsed Java standards. Java Help 2.0 and the Generic Connection Framework for J2ME were ratified and released in final form. In addition, the executive committees passed the final ballots for JSRs dealing with J2EE client provisioning, the Portlet specification and JMX remoting."

19. Term of the Week: Generics
"The lack of generics is changing for both development platforms with the next releases of Microsoft's .NET Framework and corresponding Visual Studio .NET toolset codenamed Whidbey and Sun's Java SDK 1.5 codenamed Tiger. Both Microsoft and Sun are touting generics as a major improvement in their languages. If you develop with either of these platforms, generics is a term you'll be seeing a lot more of in the future. It is interesting to note that Microsoft initially announced generics as a C# "Whidbey" feature but later announced generics would be supported in "Whidbey" in Visual Basic, Visual C++, and Visual J# as well."

20. TIP: Taking Advantage of Java Generics
"Although the syntax can become verbose, Java Generics can help simplify code, express intent, and provide compile time checking of type usage. Developers should learn to take advantages of these features of Java5."

21. Generics in J2SE 5.0
"This is the first lesson in a series designed to teach you how to use some of the new features in J2SETM 5.0. This lesson will teach you some of the rudimentary aspects of the new capability commonly referred to as generics. This lesson will also teach you how to use the enhanced for loop with collections and also with arrays."

22. Generics 101: Mastering the Fundamentals > Type Safety
"This article helps you master generics fundamentals by first focusing on type safety, in which you discover the motivation for adding generics to Java. The article next explores generic types and generic methods, which manifest generics at the source code level. For brevity, this article focuses on essentials and does not delve into too many details—complete coverage of generics would probably occupy an entire book."

w__w__w.__j_av_a___2__s__.co___m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.