Notes
Notes - notes.io |
holds only one piece of data at a time
the variable holds the actual value
int num1 = 17;
example: int and double
class
holds more than one piece of data at a time
can hold data of different types
has built in methods (tools)
users can create their own classes
the variable holds the memory location of the actual data -refers to it
string word1 = "hello";
example strings
quick example
string a = "what";
string b = a;
string a holds the what in a location
b refers to the variable address.
Both b and a point to the same location (the string what)
what if there is no reference?
for example
string word;
null- special value that means "no reference"
string alpha = "the final frontier";
alpha = null; <---- No place to hold the variable "the final frontier"
It is garbage collected. Java goes through and cleans up any unattached values in memory.
Example:
String alpha = "the final frontier";
String beta = alpha;
alpha = null; <---- the reference for the final frontier is erased for string alpha but not for beta
We don't use == because it tests identity. THE == tests the value stored directly in a and b.
String is an example of a class data type because it has methods and tools to work on
how strings work
the letters in strings are stored as individual characters. Each is given an address.
the addresses start at zero. You can find the length by word.length()
concatenation: add strings
word3 = word1 + word2
the + symbol is overloaded
this means it has multiple uses depending on the situation
tools for working on strings
.equals() tests for equality
this method is built into string
it tests if the contents are equal
.charAt()
tells us hwat letter is at a spot in the String
the fist spot is 0
string w = "variable"
system.out.println(w.charAt(2));
prints r
.indexOf(c)
put in a character, tells were it is
string w = "variable";
system.out.println(w.indexOf(('i'));
prints 3
.subString(start, stop)
pulls of a section of a string from start to stop -1)
string w = "variable";
System.out.println(w.substring(2,5));
prints ria
.subString(start)
pulls of a section of string from start to the end of the array
string w = "variable";
system.out.println(w.subString(4));
prints able
.toUpperCase()
.toLowerCase()
.CompareTo(other)
compares two strings alphabetically
String s = "ardvark";
System.out.print(s.compareTo("zebra");
prints -25
object
in java, an object is a variable of a class type
it can hold lots of data and has methods
it is different
arrays are objects
an array is an object that holds more than one thing in memory
all items in the array are the same data
to create:
int[] list = new int[7];
this creates an array called list of 7 integers
use the new command - this is what stores the reference to where the data is in memory
new
this is a java command
it creates a new reference: this is when java stores the memory address in the variable
we used this with Scanner
element: the box of array. each box holds a value. all values are the same data type
index: the address of the elements. Starts at 0 and ends at (length -1)
initialize: stores known values in an array
The end is always length -1
The number inside the square brackets tell us the address.
initializer lists
automatically sets the values in an array.
int[] list = {14, -10, 1, 0, 9,}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team