Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Head First Java, Lecture notes of Computer Engineering and Programming

Core Java - Core Java

Typology: Lecture notes

2012/2013

Uploaded on 01/29/2013

bunkeraditya
bunkeraditya 🇮🇳

4

(2)

8 documents

1 / 79

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
########################################
Chapter 1 :
########################################
Type your source code.Save as : <lename>.java
Compile the <lename>.java le by running javac(the compiler
application). If you dont have errors,
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f

Partial preview of the text

Download Head First Java and more Lecture notes Computer Engineering and Programming in PDF only on Docsity!

Chapter 1 : ########################################

Type your source code.Save as : .java

Compile the .java file by running javac(the compiler application). If you dont have errors,

youll get a second document named .class -- The compiler- generated .class file is made up of bytecodes... Run the program by starting the Java Virtual Machine (JVM) with the translates the bytecode into something the underlying platform understands, and runs your program.

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.