Creating Class Type Objects

This section describes how class type objects can be created using the 'new' operator and special methods.

There are a number of ways to create a class type object:

1. The "new" operator - A class type object can be created using the new operator to call the class constructor. Examples are listed below:

   new String("Hello"); // creates a String object
   new java.util.Date(); // creates a Date object
   new java.util.ArrayList<String>(); // creates an ArrayList<String>

2. Special method - A class type object can be created using special methods provided by classes. Examples are listed below:

   javax.net.SocketFactory.getDefault().createSocket(); 
      // creates a java.net.Socket object
   
   java.security.KeyPairGenerator.getInstance("DSA");
      // creates a java.security.KeyPairGenerator object

3. String literal and String concatenation - A String type object can be created using a String literal or a String concatenation. Examples are listed below:

   "Hello" // creates a String object
   "Hello"+" world!" // creates a String object

Last update: 2014.

Table of Contents

 About This Book

 Installing JDK 1.8 on Windows

 Execution Process, Entry Point, Input and Output

 Primitive Data Types and Literals

 Bits, Bytes, Bitwise and Shift Operations

 Managing Bit Strings in Byte Arrays

Reference Data Types and Variables

 Reference Types Supported in Java

Creating Class Type Objects

 Class Type Variables Storing References

 Interface Type Variables

 Class and Interface Hierarchy

 Supertype and Subtype

 Explicit and Implicit Type Casting

 Type Casting Example Program

 Type Casting Compile and Runtime Error

 StringBuffer - The String Buffer Class

 System Properties and Runtime Object Methods

 Generic Classes and Parameterized Types

 Generic Methods and Type Inference

 Lambda Expressions and Method References

 Execution Threads and Multi-Threading Java Programs

 ThreadGroup Class and "system" ThreadGroup Tree

 Synchronization Technique and Synchronized Code Blocks

 Deadlock Condition Example Programs

 Garbage Collection and the gc() Method

 Outdated Tutorials

 References

 PDF Printing Version