Java Tutorial – External References (Oracle Java Docs
Only)
This reference list contains only official Oracle Java documentation links (Java SE / JDK).
Use it as a bibliography or “Further Reading” section for a Java tutorial.
Java Classes/Objects
Java is an object-oriented programming language.
Everything in Java is associated with classes and objects, along with its attributes and
methods. For example: in real life, a car is an object. The car has attributes, such as weight
and color, and methods, such as drive and brake.
A Class is like an object constructor, or a "blueprint" for creating objects.
Create a Class
To create a class, use the keyword class.
In this example, we create a class named "Main" with a variable x:
[Link]
public class Main {
int x = 5;
Remember from the Java Syntax chapter that a class should always start with an uppercase
first letter, and that the name of the java file should match the class name.
Create an Object
In Java, an object is created from a class. We have already created the class named Main, so
now we can use this to create objects.
To create an object of Main, specify the class name, followed by the object name, and use the
keyword new:
ExampleGet your own Java Server
Create an object called "myObj" and print the value of x:
public class Main {
int x = 5;
public static void main(String[] args) {
Main myObj = new Main();
[Link](myObj.x);
Multiple Objects
You can create multiple objects of one class:
Example
Create two objects of Main:
public class Main {
int x = 5;
public static void main(String[] args) {
Main myObj1 = new Main(); // Object 1
Main myObj2 = new Main(); // Object 2
[Link](myObj1.x);
[Link](myObj2.x);
}
Using Multiple Classes
You can also create an object of a class and access it in another class. This is often used for
better organization of classes (one class has all the attributes and methods, while the other
class holds the main() method (code to be executed)).
Remember that the name of the java file should match the class name. In this example, we
have created two files in the same directory/folder:
[Link]
[Link]
[Link]
public class Main {
int x = 5;
[Link]
class Second {
public static void main(String[] args) {
Main myObj = new Main();
[Link](myObj.x);
When both files have been compiled:
C:\Users\Your Name>javac [Link]
C:\Users\Your Name>javac [Link]
Run the [Link] file:
C:\Users\Your Name>java Second
And the output will be:
5
Java Classes/Objects
Java is an object-oriented programming language.
Everything in Java is associated with classes and objects, along with its attributes and
methods. For example: in real life, a car is an object. The car has attributes, such as weight
and color, and methods, such as drive and brake.
A Class is like an object constructor, or a "blueprint" for creating objects.
Create a Class
To create a class, use the keyword class.
In this example, we create a class named "Main" with a variable x:
[Link]
public class Main {
int x = 5;
Remember from the Java Syntax chapter that a class should always start with an uppercase
first letter, and that the name of the java file should match the class name.
Create an Object
In Java, an object is created from a class. We have already created the class named Main, so
now we can use this to create objects.
To create an object of Main, specify the class name, followed by the object name, and use the
keyword new:
ExampleGet your own Java Server
Create an object called "myObj" and print the value of x:
public class Main {
int x = 5;
public static void main(String[] args) {
Main myObj = new Main();
[Link](myObj.x);
Multiple Objects
You can create multiple objects of one class:
Example
Create two objects of Main:
public class Main {
int x = 5;
public static void main(String[] args) {
Main myObj1 = new Main(); // Object 1
Main myObj2 = new Main(); // Object 2
[Link](myObj1.x);
[Link](myObj2.x);
Using Multiple Classes
You can also create an object of a class and access it in another class. This is often used for
better organization of classes (one class has all the attributes and methods, while the other
class holds the main() method (code to be executed)).
Remember that the name of the java file should match the class name. In this example, we
have created two files in the same directory/folder:
[Link]
[Link]
[Link]
public class Main {
int x = 5;
[Link]
class Second {
public static void main(String[] args) {
Main myObj = new Main();
[Link](myObj.x);
When both files have been compiled:
C:\Users\Your Name>javac [Link]
C:\Users\Your Name>javac [Link]
Run the [Link] file:
C:\Users\Your Name>java Second
And the output will be:
Java Classes/Objects
Java is an object-oriented programming language.
Everything in Java is associated with classes and objects, along with its attributes and
methods. For example: in real life, a car is an object. The car has attributes, such as weight
and color, and methods, such as drive and brake.
A Class is like an object constructor, or a "blueprint" for creating objects.
Create a Class
To create a class, use the keyword class.
In this example, we create a class named "Main" with a variable x:
[Link]
public class Main {
int x = 5;
Remember from the Java Syntax chapter that a class should always start with an uppercase
first letter, and that the name of the java file should match the class name.
Create an Object
In Java, an object is created from a class. We have already created the class named Main, so
now we can use this to create objects.
To create an object of Main, specify the class name, followed by the object name, and use the
keyword new:
ExampleGet your own Java Server
Create an object called "myObj" and print the value of x:
public class Main {
int x = 5;
public static void main(String[] args) {
Main myObj = new Main();
[Link](myObj.x);
}
Multiple Objects
You can create multiple objects of one class:
Example
Create two objects of Main:
public class Main {
int x = 5;
public static void main(String[] args) {
Main myObj1 = new Main(); // Object 1
Main myObj2 = new Main(); // Object 2
[Link](myObj1.x);
[Link](myObj2.x);
Using Multiple Classes
You can also create an object of a class and access it in another class. This is often used for
better organization of classes (one class has all the attributes and methods, while the other
class holds the main() method (code to be executed)).
Remember that the name of the java file should match the class name. In this example, we
have created two files in the same directory/folder:
[Link]
[Link]
[Link]
public class Main {
int x = 5;
[Link]
class Second {
public static void main(String[] args) {
Main myObj = new Main();
[Link](myObj.x);
When both files have been compiled:
C:\Users\Your Name>javac [Link]
C:\Users\Your Name>javac [Link]
Run the [Link] file:
C:\Users\Your Name>java Second
And the output will be:
Java Classes/Objects
Java is an object-oriented programming language.
Everything in Java is associated with classes and objects, along with its attributes and
methods. For example: in real life, a car is an object. The car has attributes, such as weight
and color, and methods, such as drive and brake.
A Class is like an object constructor, or a "blueprint" for creating objects.
Create a Class
To create a class, use the keyword class.
In this example, we create a class named "Main" with a variable x:
[Link]
public class Main {
int x = 5;
Remember from the Java Syntax chapter that a class should always start with an uppercase
first letter, and that the name of the java file should match the class name.
Create an Object
In Java, an object is created from a class. We have already created the class named Main, so
now we can use this to create objects.
To create an object of Main, specify the class name, followed by the object name, and use the
keyword new:
ExampleGet your own Java Server
Create an object called "myObj" and print the value of x:
public class Main {
int x = 5;
public static void main(String[] args) {
Main myObj = new Main();
[Link](myObj.x);
}
Multiple Objects
You can create multiple objects of one class:
Example
Create two objects of Main:
public class Main {
int x = 5;
public static void main(String[] args) {
Main myObj1 = new Main(); // Object 1
Main myObj2 = new Main(); // Object 2
[Link](myObj1.x);
[Link](myObj2.x);
Using Multiple Classes
You can also create an object of a class and access it in another class. This is often used for
better organization of classes (one class has all the attributes and methods, while the other
class holds the main() method (code to be executed)).
Remember that the name of the java file should match the class name. In this example, we
have created two files in the same directory/folder:
[Link]
[Link]
[Link]
public class Main {
int x = 5;
[Link]
class Second {
public static void main(String[] args) {
Main myObj = new Main();
[Link](myObj.x);
When both files have been compiled:
C:\Users\Your Name>javac [Link]
C:\Users\Your Name>javac [Link]
Run the [Link] file:
C:\Users\Your Name>java Second
And the output will be:
Java Classes/Objects
Java is an object-oriented programming language.
Everything in Java is associated with classes and objects, along with its attributes and
methods. For example: in real life, a car is an object. The car has attributes, such as weight
and color, and methods, such as drive and brake.
A Class is like an object constructor, or a "blueprint" for creating objects.
Create a Class
To create a class, use the keyword class.
In this example, we create a class named "Main" with a variable x:
[Link]
public class Main {
int x = 5;
Remember from the Java Syntax chapter that a class should always start with an uppercase
first letter, and that the name of the java file should match the class name.
Create an Object
In Java, an object is created from a class. We have already created the class named Main, so
now we can use this to create objects.
To create an object of Main, specify the class name, followed by the object name, and use the
keyword new:
ExampleGet your own Java Server
Create an object called "myObj" and print the value of x:
public class Main {
int x = 5;
public static void main(String[] args) {
Main myObj = new Main();
[Link](myObj.x);
Multiple Objects
You can create multiple objects of one class:
Example
Create two objects of Main:
public class Main {
int x = 5;
public static void main(String[] args) {
Main myObj1 = new Main(); // Object 1
Main myObj2 = new Main(); // Object 2
[Link](myObj1.x);
[Link](myObj2.x);
Using Multiple Classes
You can also create an object of a class and access it in another class. This is often used for
better organization of classes (one class has all the attributes and methods, while the other
class holds the main() method (code to be executed)).
Remember that the name of the java file should match the class name. In this example, we
have created two files in the same directory/folder:
[Link]
[Link]
[Link]
public class Main {
int x = 5;
}
[Link]
class Second {
public static void main(String[] args) {
Main myObj = new Main();
[Link](myObj.x);
When both files have been compiled:
C:\Users\Your Name>javac [Link]
C:\Users\Your Name>javac [Link]
Run the [Link] file:
C:\Users\Your Name>java Second
And the output will be:
References
[1] Java SE Documentation (overview). [Link]
[Link]
[2] Java Platform, Standard Edition Documentation (release index).
[Link]
[3] JDK 17 Documentation Home. [Link]
[4] Java SE 17 API Specification (Overview).
[Link]
[5] [Link] module summary (Java SE 17).
[Link]
[6] API Help (Java SE 17 & JDK 17).
[Link]
[7] Java SE Specifications index. [Link]
[8] The Java Language Specification (JLS) — Java SE 17 PDF.
[Link]
[9] The Java Language Specification (JLS) — Java SE 17 HTML.
[Link]
[10] The Java Virtual Machine Specification (JVMS) — Java SE 17 PDF.
[Link]
[11] The Java Virtual Machine Specification (JVMS) — Java SE 17 HTML.
[Link]
[12] Java Tutorials (Oracle). [Link]
[13] Trail: Learning the Java Language (Oracle Tutorials).
[Link]
[14] Trail: Collections (Oracle Tutorials).
[Link]
[15] JDK 17 Release Notes landing page.
[Link]