background preloader

General (Java)

Facebook Twitter

Static initialization blocks (static constructors)

How to convert string to int in Java. Java enum for loop example. By Alvin Alexander.

Java enum for loop example

Last updated: Dec 16, 2013. Enum Types (The Java™ Tutorials > Learning the Java Language > Classes and Objects) An enum type is a special data type that enables for a variable to be a set of predefined constants.

Enum Types (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

The variable must be equal to one of the values that have been predefined for it. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week. Because they are constants, the names of an enum type's fields are in uppercase letters. In the Java programming language, you define an enum type by using the enum keyword. For example, you would specify a days-of-the-week enum type as: public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }

Operator Precedence/priority in Java. Generics in Java. Hierarchy and classification.

Generics in Java

[edit] According to Java Language Specification:[3] A type variable is an unqualified identifier. Type variables are introduced by generic class declarations, generic interface declarations, generic method declarations, and by generic constructor declarations.A class is generic if it declares one or more type variables. These type variables are known as the type parameters of the class. Motivation[edit] Bien comprendre les "generics" de Java. Kill Java Applet via Javascript.

Reflection (Java)

Instaceof (Typage statique) Life Cycle Of An Applet (Introduction to Java Applet) Introduction In this article we are going to describe the Java applet technology.

Life Cycle Of An Applet (Introduction to Java Applet)

We also discuss the basics of Java applets; how to develop applets that interact richly with their environment, and how to deploy applets.An applet is a special Java program that runs in a browser enabled with Java technology (JRE) that can be downloaded from the internet and run. An applet is typically embedded inside a HTML page and runs in the context of a browser. An applet is designed to run remotely in the client browser, so there are some restrictions on it. The applet can't access system resources on the local computer. Life Cycle Of An Applet These are the different stages involved in the life cycle of an applet. Initialization State Running State Idle or stopped state Dead State Display State Initialization State The life cycle of an applet begins when the applet is first loaded into the browser and called the init() method.

Public void init(){Statements} Running State Syntax. Java example to get Object class name at runtime. Enum Types (The Java™ Tutorials > Learning the Java Language > C. Enums JRE >=1.5. In prior releases, the standard way to represent an enumerated type was the int Enum pattern: // int Enum Pattern - has severe problems!

Enums JRE >=1.5

Public static final int SEASON_WINTER = 0; public static final int SEASON_SPRING = 1; public static final int SEASON_SUMMER = 2; public static final int SEASON_FALL = 3; This pattern has many problems, such as: Not typesafe - Since a season is just an int you can pass in any other int value where a season is required, or add two seasons together (which makes no sense). Les enum en java. Enum (Java 2 Platform SE 5.0) Java.lang.Object java.lang.Enum<E> All Implemented Interfaces: Serializable, Comparable<E> public abstract class Enum<E extends Enum<E>>extends Objectimplements Comparable<E>, Serializable This is the common base class of all Java language enumeration types.

Enum (Java 2 Platform SE 5.0)

Since: See Also: Serialized Form. Java 5.0 Enum: why not valueOf(int ordinal)? Homework - Java - Convert String to enum. Enum.valueOf - Today's tip. Voici un point rapide sur les enums et plus spécifiquement sur les méthodes valueOf et values.

Enum.valueOf - Today's tip

Clone (Java method) Classes that want copying functionality must implement some method to do so.

clone (Java method)

To a certain extent that function is provided by "Object.clone()". The default implementation of Object.clone() performs a shallow copy. When a class desires a deep copy or some other custom behavior, they must perform that in their own clone() method after they obtain the copy from the superclass. Java - cast byte to enum. Basic Types in Java. Java supports a number of built-in basic types: integer types: byte, short, int, longreal number types: float, doublebooleancharStringObject Integer Types Take a look at the table below summarizing the size and ranges of the different integer types in Java: Here is an example illustrating how to declare variables of type byte, short, int and long: Real Number Types.

Basic Types in Java

Java decimal String format. RoundingMode (Java 2 Platform SE 5.0) Java.lang.Object java.lang.Enum<RoundingMode> java.math.RoundingMode All Implemented Interfaces: Serializable, Comparable<RoundingMode>

RoundingMode (Java 2 Platform SE 5.0)

Convert String to Enum Instance. String to Enum Example. Making the Most of Java 5.0: Enum Tricks. So your organization has finally moved to Java 5.0...and you are wondering what you can do with some of its new features. In this first of a series of articles on Java 5.0, I'll show you some of the interesting ways that you can exploit the new language features to improve the way you code Java. First off, enumerations. Introduction to Enums The enumeration is a way of creating self-documenting code, a big improvement over the "magic" integer or string constants which are often used to represent a defined set of values. Enumerations abound in object models, and examples are not hard to find: days of the week, colors, card suits, etc. //use optional assignment to ints to illustrate enum suit { SPADES = 1, HEARTS = 2, DIAMONDS = 3, CLUBS = 4 }; James Gosling on Apple, Apache, Google, Oracle and the Future of Java. Java - Convert integer to string.