A basic tutorial on classes and objects in Java. What is a class? How do you create objects and classes and how do you use them?
When the video is running, click the maximize button in the lower-right-hand corner to make it full screen.
Code for this tutorial:
class Person {
// Instance variables (data or "state")
String name;
int age;
// Classes can contain
// 1. Data
// 2. Subroutines (methods)
}
public class App {
public static void main(String[] args) {
// Create a Person object using the Person class
Person person1 = new Person();
person1.name = "Joe Bloggs";
person1.age = 37;
// Create a second Person object
Person person2 = new Person();
person2.name = "Sarah Smith";
person2.age = 20;
System.out.println(person1.name);
}
}
Joe Bloggs
Learn to program Java Swing with my complete video course – desktop programming and applets. Includes 7 free videos. Click here for details.
All pages on this site are copyright © 2013 John W. Purcell
Your tutorial on Multithreading rocks!!! Easy to understand and very helpful. I feel like a detailed topic on Collection Framework in Java will be very helpful for many people. Can you please work on such tutorial and upload here?
Thanks Kafil, that is a really good idea actually. Popular topic. I’ll try to create some videos on collections in the near future.