







































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Core Java - Core Java
Typology: Lecture notes
1 / 79
This page cannot be seen from the preview
Don't miss anything!
Chapter 1 : ########################################
Type your source code.Save as :
Compile the
youll get a second document named
Put a class in a source file...Put methods in a class...Put statementsin a method
Every Java application has to have at least one class, and at least one main method
Running a program means telling the Java Virtual Machine (JVM) to Load the class, then start executing its main() method. Keep running til all the code in main is finished.
A single-line comment begins with two forward slashes...Each statement must end in a
semicolon...Most white space doesnt matter...Classes and methods must be defined within a pair of curly braces.
As long as some condition is true, you do everything inside the loop block. The loop block is bounded by a pair of curly braces, so whatever you want to repeat needs to be inside that block.
things the object knows -- Things an object knows about itself are called instance variables things the object does -- Things an object can do are called methods
A class is a blueprint for an object. It tells the virtual machine how to make an object of that particular type. Each object made from that class can have its own values for the instance variables of that class.
Analogy - JVM as Architect and class as the blueprint design how to design a building
One analogy for objects is a packet of unused Rolodexcards. Each card has the same blank fields (the instance variables). When you fill out a card you are creating an instance (object), and the entries you make on that card represent its state.
The methods of the class are the things you do to a particular card;
need objects talking to other objects, as opposed to a static main() method creating and testing objects
Each time an object is created in Java, it goes into an area of memory known as The Heap. All objectsno matter when, where, or how theyre created live on the heap.
But its not just any old memory heap; the Java heap is actually called the Garbage-Collectible Heap. When you create an object, Java allocates memory space on the heap according to how much that particular object needs. An object with, say, 15 instance variables, will probably need more space than an object with only two instance variables. But what happens when you need to reclaim that space? How do you get an object out of the heap when youre done with it?
Chapter 3 : Know Your Variables ########################################
variables come in two flavors: primitive and reference. So far youve used variables in two places as object state (instance variables),
and as local variables (variables declared within a method) , as arguments (values sent to a method by the calling code), and as return types(values sent back to the caller of the method). Youve seen variables declared as simple primitive integer values (type int). Youve seen variables declared as something more complex like a String or an array.
Variables come in two flavors:
of 2486, and name the variable height. Each primitive variable has a fixed number of bits (cup size).
float f = 32.5f note the f. Gotta have that with a float, because Java thinks anything with a floating point is a double, unless you use f.
Type Bit Depth Value Range
boolean (JVM-specific) true or false char 16 bits 0 to 65535
#numeric (all are signed)# -- integer
-- floating point float 32 bits varies double 64 bits varies
There is actually no such thing as an object variable.Theres only an object reference variable.
An object reference variable holds bits that represent a way to access an object. You cant stuff an object into a variable There arent giant expandable cups that can grow to the size of any object. Objects live in one place and one place onlythe garbage collectible heap!
You use the dot operator (.) on a reference variable to say, use the thing before the dot to get me the thing after the dot.