Java_Fundamentals_Summary.pdf - Object-Based Programming...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Object-Based Programming: JAVA Fundamentals Summary Page 1 of 23 Core Concepts of Programming Programming deals with real world objects and convert them into data that can be manipulated using a programming language. A video store objects include: 1. The Store 2. The Movies 3. The People Java allows us to model the objects by creating classes: Classes are "blue prints" that define - an object's properties such as movie titles, directors, etc. and its behavior, e.g.; how these movies 'behave', e.g., rented or bought; The core concepts are essential for making these real world objects into classes that you can work with in programming. Data types Variables Objects Classes Methods Method parameters Return types and values Creating objects Accessors and Mutators Data Types Different data types can be used in various ways depending on the type. Strings are used to form words; sentences, etc. that require sequence of characters or values wrapped in double quotes ("…") Derives from the Java String class String literals can contain any valid Unicode characters: alpha-numeric and symbols or no characters at all (null). A string literal cannot span multiple lines but can be concatenated using the "+" sign
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Object-Based Programming: JAVA Fundamentals Summary Page 2 of 23 There are also certain special characters in Java require escape sequences for display using the backslash-symbol combination: \b - backspace \t tab \n newline \r - carriage return; \" 2x quote \' - 1x quote \\ - backslash // Displaying double quotes System.out.println( "The first little piggy said " + "\"Not by the hair of my chinny chin chin!\"") More things you can do with strings: String greeting = "Hello!" // Change the case System.out.println(greeting.toUpperCase()) System.out.println(greeting.toLowerCase()) String phrase = "Time flies like an arrow." // Extract a part of a string (substring) using the starting and ending index values String substring = phrase.substring(5, 10); // Output the extracted string System.out.println(substring); // Replace a substring String phrase2 = phrase.replace("arrow", "air plane"); // Check for matching substring If (substring.equals( "flies" )) { System.out.println( "Matching string exists in the phrase." ); } else { System.out.println( "No Matching string exists in the phrase." ); } } Numbers are primitive type , i.e., there is no associated class behind them literal Integers (+/-, 0 whole numbers) do not use commas Doubles floating point - use decimal form Exponentiation e.g., 12.0E2 = 144.0 Boolean TRUE / FALSE When doing calculations, remember the order of operations .
Image of page 2
Object-Based Programming: JAVA Fundamentals Summary Page 3 of 23 Casting Casting converts one data type to another data type public class TypeCasting { public static void main(String[] args) { double dNum = 34.59; // double value int iNum = (int) dNum; // place the type spec (int) to // convert double to integer System.out.println(iNum); String sNum = "50"; // string value iNum = Integer.parseInt(sNum); // parseInt method in Interger class // converts string to integer System.out.println(iNum); } } Variables
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern