πŸ€cheeky❀️determinedπŸ€ΈπŸ»β€β™‚οΈfortunateβ˜•οΈgiddy✨thrilledπŸƒunstoppable❣️favored☁️blissful🌈forwardπŸ€luckyβ˜•οΈgleefulπŸ’purposefulπŸƒirreverent⚑️happy✨charmed☁️fresh❣️tenaciousπŸ’elatedπŸ€excited❀️joyful πŸ€cheeky❀️determinedπŸ€ΈπŸ»β€β™‚οΈfortunateβ˜•οΈgiddy✨thrilledπŸƒunstoppable❣️favored☁️blissful🌈forwardπŸ€luckyβ˜•οΈgleefulπŸ’purposefulπŸƒirreverent⚑️happy✨charmed☁️fresh❣️tenaciousπŸ’elatedπŸ€excited❀️joyful
← Blog

Intro to Java: Classes & Objects

September 7, 2018 work

'Why Java?' is the question everyone asks me when I tell them I'm taking Treehouse's Beginning Java class. My response is always the same, 'Because Salesforce's programming language (Apex) is very similar to Java, but Intro to Apex courses are few and far between.' I was familiar with an object thanks to Salesforce. In Java, these unique attributes are called a class. Because I love ice cream I'm going to use that as the example for my post.

Makes sense, right? But you're probably asking why you need a class for ice cream. An Opportunity for example? Opportunities don't have flavors, they have close dates and amounts. So a class is a neat template (or blueprint) for whatever object you want to create. Here's my ice cream class in code:

class IceCream {
  String flavor;
  String texture;
  String color;
  String brand;
}

I'm declaring the class at the beginning and giving it a name (IceCream). Then inside the curly braces I'm declaring the attributes (or variables) that my IceCream class has. 'String' means that I'm expecting a word as my value, i.e. mint-chocolate chip.

But what about objects? Objects are created from classes. This is called instantiation. You can create many objects from one class.

Note: If you are coming to Java from Salesforce, this concept is a bit confusing. Because in our world there are objects (like the Opportunity object) and then records created inside the object. Java doesn't use the concept of records. They use classes (which is Salesforce's version of an object) and then objects (which I knew as records).

Not so bad, right? In my next post, I'll talk about modifiers. Thanks to Craig Dennis & Doug Ayers for helping me with the concepts in this post.