read java in under an hour

19
Learn To Read Java In under an hour!

Upload: molly-rand

Post on 25-Apr-2015

118 views

Category:

Technology


2 download

DESCRIPTION

Presentation for Women Who Code Austin on May 5, 2014. Now with notes included for SlideShare. Recorded livestream here: baer.ly/1us79Za. Want to learn Android Dev? Take the Udemy course! https://www.udemy.com/become-an-android-developer-from-scratch/?couponCode=MOLLYBLOG

TRANSCRIPT

Page 1: Read Java in Under an Hour

Learn To Read JavaIn under an hour!

Page 2: Read Java in Under an Hour

Speaker todaysSpeaker = Molly Rand;

Page 3: Read Java in Under an Hour

Speaker todaysSpeaker = Molly Rand;

Notes:

Become an Android Developer From Scratch is the Udemy course created by the guys who trained me. You can find it online here: https://www.udemy.com/become-an-android-developer-from-scratch/, and if you don’t want to pay full price there’s a promo code on my blog at codemolly.tumblr.com. Please feel free to tweet at me or hit me up on my blog if you want to connect/ have questions about Android programming from a noob’s perspective.

Page 4: Read Java in Under an Hour

CODE STRUCTURE

Page 5: Read Java in Under an Hour

Hallmarks of Java

• Object Oriented

• Static typing

• Libraries

• Mature Platform

Page 6: Read Java in Under an Hour

Hallmarks of Java

• Object Oriented

• Static typing

• Libraries

• Mature Platform

Notes:

This is a great article my mentor shared on one coder’s opinions about why he likes Java: http://stevewedig.com/2014/02/17/why-and-how-i-write-java/

Page 7: Read Java in Under an Hour

Code Components

File

Class

Attributes

Methods

Page 8: Read Java in Under an Hour

Code Components

File

Class

Attributes

Methods

Notes:

Your file name should match your class name (it’s convention, and a really good one). The package at the top of the file lets you know what files are grouped together in a single project.

Attributes are like the nouns/adjectives. They tell you what your class has and describe it.

Methods are like your verbs – they tell you what objects of that class can do and how they do it.

Page 9: Read Java in Under an Hour

JAVA GRAMMAR

Page 10: Read Java in Under an Hour

Clues in the Case

• PascalCase• Used for class names

• Found in class signature and variable declarations (data type)

• camelCase• Variables and method names

• snake_case• Mainly seen in built-in static variables (constants)

• Also XML in Android programming

Page 11: Read Java in Under an Hour
Page 12: Read Java in Under an Hour

Notes:

Curly braces are your biggest indicator when deciphering Java code. If you can separate the code into blocks you reduce your cognitive load and can deal with the file one small piece at a time.

Semicolons come at the end of every java statement – important to note because sometimes one statement will take up multiple lines, or less often you may have multiple statements on a single line

Parentheses in a method signature (next slide) tell you what that method needs as input in order to run. When a method is called, those input parameters go in the parentheses of the method call.

Brackets are used when denoting that you are creating an array, and when accessing individual elements of an array.

Operators are used in mathematical expressions and logic comparisons.

Page 13: Read Java in Under an Hour
Page 14: Read Java in Under an Hour

Notes:This is a Java method signature – where a method (action an object of a class can take) is defined.

The accessibility keyword denotes who can call this method. Public methods can be called by objects wherever they’re created. Private methods can only be called internally within the class. Protected methods are more complicated, but worth some research if you really want to get into Java.

The return type is the data type you will get back when the method is run. A return type of void simply means that the code within the method will run, but you won’t have any kind of object returned to you (maybe variables within the object change, maybe something happens on your screen). If the return type is not void, there must be a statement within the method’s code block (between the curly braces) that returns a variable of that type.Parameters have a declared type and variable name. The type is because Java is a statically typed language, and the variable name is so that we can use the parameter within this method without having to know what it’s called anywhere else in the code. This is super handy for making modular, reusable code. Methods can have 0, 1, or many parameters of any number of data types.

Page 15: Read Java in Under an Hour

Any method that has a signature like this can then be called on objects of its class. A method call looks like variableName.methodName(parameter); Passing in the wrong number or type of parameters will result in a compile-time error. If a method signature has a return type other than void, you’ll typically want to assign that method call to a variable of the corresponding type. For example: if my method is public boolean isTrue(){ } then simply calling variable.isTrue(); won’t do anything. I need to say boolean truth = variable.isTrue(); and then I can use truth in logic tests in later code statements.

Page 16: Read Java in Under an Hour

LET’S LOOK AT SOME CODE!

Page 17: Read Java in Under an Hour

Method Signature

Block of code

Parameter is an object of the NoteSlide class (Defined in the same project)

Method name is slideTime

Returns a String

Page 18: Read Java in Under an Hour

Method Signature

Block of code

Page 19: Read Java in Under an Hour

Declaring variables of type int

Calling method valueOf which takes a single int as a parameter and

returns a String