FUNDAMENTALS OF JAVA
-
Upload
virginiainternational -
Category
Documents
-
view
2 -
download
0
Transcript of FUNDAMENTALS OF JAVA
Compilation Unit• The entire file or .java file is called Compilation Unit
• In Compilation Unit , we can have multiple classes.
• Every Java application has at least one class.
• At least one class has to be public.
Main() method• There is a common signature in every Java program which is an entry point called main() method.
• This is where the Java program starts.
• This is called Starting point for a java class.
Class & Object• Classes are the basis of objects.
• Every java application has at least one class.
• In other words, a class can be defined as a template/blue print that describes the behaviors/states that object of its type support.
• Example of class: blueprint of building a car, a template or model of a building, floor.
Class & Object• A class is can also be considered as a container which holds or stores within it self.
• An object can be defined as an instance of a class.
• Objects have states and behaviors.• States are the properties or attributes in the world of Java.
• Behaviors are the methods or functions in the world of Java.
Class & Object• Example : Object : CarState: color, make, modelBehavior: Drive
• Example : Object :Human BeingsState :name, address -- Properties/AttributesBehavior : Move, dance, work, run, shout -- Methods/Functions
Naming a class• Name of the class is it has to start with _ (underscore), letter, $(dollar) sign .
• Always give some meaningful name which tells you about what your class is saying.
Access Modifiers• public is accessed by any number of classes.
• private is accessible within the class.
• protected is accessible within the class and all the classes within the packages.
More about Java Programming
• Java is --Case Sensitive
--Does not really care about white space. That means does not really requires indentation.
--Statements always ends with semi-colon(;)
Comments• Comments are notes or documents or keypoints about your program.
• Compiler ignores everything that is writen in between the slashes.
• Categorized as two types:• Single line commentsEg: // displaying the output
• Multiple line comments Eg: /******************* These are my comments *********** */
Keywords• Keywords are always constant and we can never change them.
• public • static • void • System• For• If• …………etc
Java Data Types
• Java Data Types are of two types:
• Primitive Data Types : System build datatypes which cannot be broken down.
• User Defined Types : Users define the data types.
Java Data Types• Primitive Data Types are of 8 types:
• byte -- 8bits • short -- 16bits• int – 32 bits• long – 64bits• float– 32 bits• double – 64 bits• char– 8bits• boolean - 8 bits
Examples
long ssn = 999999999L; float pi = 3.1415F; int var = 123;
char letter =‘a’; boolean one =true; double =1244.5;