Java
Class
• Class names should be nouns, in mixed case
• with the first letter of each internal word
capitalized.
• Try to kee...
Methods
• Methods should be verbs, in mixed case with
the first letter lowercase, with the first letter of
each internal w...
Variables
• Except for variables, all instance, class, and
• class constants are in mixed case with a
lowercase
• first le...
Basic Program
• class helloWorld
• {
• public static void main(String args[ ])
• {
• System.out.println(“Hello World!”);
•...
Class Identification
• The class definition
• The first line is a declaration statement to
introduce the code to the compu...
The main method
• Atleast one and only one main method.
• Java applets, however, do not contain main methods.
• public is ...
main(String args[ ])
• The String array
• The third line declares an array, an element
that stores a list of values like x...
System class & output
• System is a class in Java's default package and
handles system hardware.
• Out is an object of tha...
Java Comments
• The Java programming language supports three kinds
of comments:
1. Double slashes in front of a single lin...
Java Data and Variables
• byte
• Short
• int
• long
• float
• Double
• char
• boolean
Java Data and Variables
• Integer types have no fractional part; floating
point types have a fractional part. On paper,
in...
Java Data and Variables
• Type Size
• byte ……….8 bits
• Short……… 16 bits
• int …………..32 bits
• Long……….. 64 bits
• float …...
Java Data and Variables
• For each primitive type, there is a corresponding wrapper class.
A wrapper class can be used to ...
Java Arithmetic Operators
• The Java programming language has includes five
simple arithmetic operators like are + (additi...
Java Data and Variables
• x && y Conditional
AND If both x and y are true, result is true.
If either x or y are false, the...
Access Modifiers
• The first (left-most) modifier used lets you
control what other classes have access to a
member field. ...
Upcoming SlideShare
Loading in …5
×

ITFT - Java

200 views

Published on

JAVA, Basic of programming, OOPS

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
200
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

ITFT - Java

  1. 1. Java
  2. 2. Class • Class names should be nouns, in mixed case • with the first letter of each internal word capitalized. • Try to keep your class names simple • and descriptive. Use whole words—avoid • acronyms and abbreviations • Eg helloWorld,HelloWorld
  3. 3. Methods • Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. • run(); • runFast(); • getBackground();
  4. 4. Variables • Except for variables, all instance, class, and • class constants are in mixed case with a lowercase • first letter. Internal words start with capital • letters. • Variable names should be short yet meaningful. • The choice of a variable name should be mnemonic— that is, designed to indicate to the use. • int I; • char
  5. 5. Basic Program • class helloWorld • { • public static void main(String args[ ]) • { • System.out.println(“Hello World!”); • } • }
  6. 6. Class Identification • The class definition • The first line is a declaration statement to introduce the code to the computer before it is used: • class notifies the interpreter that a new class will be defined. • helloWorld is the unique name for this new class. • The curly braces signal the beginning and end of the class body
  7. 7. The main method • Atleast one and only one main method. • Java applets, however, do not contain main methods. • public is known as a 'global', a signal to the interpreter that this method can be used in other parts of the program. • The private keyword prevents the rest of the program from calling anything inside a method. • static tells the interpreter that the main method applies to everything in the helloWorld class, rather than just one element. Breathing and daily activities work as analogies for static and instance methods; daily activities vary but breathing is required. • void indicates that this method finishes operating without returning any results. • main is the unique identifier for this method and is a reserved word because all Java applications have one and only one main method. • The parentheses indicate that parameters can be passed to this method
  8. 8. main(String args[ ]) • The String array • The third line declares an array, an element that stores a list of values like x[1,2,3]. Contrast arrays with variables that store only one value at a time, like x=3. String defines the type of values received: numbers, characters, and symbols. Args is the unique name for this array, and the brackets signal its array status.
  9. 9. System class & output • System is a class in Java's default package and handles system hardware. • Out is an object of that class and handles output. • Println() is a method of System and accepts Hello, world! as a parameter to output to the screen. • Interpreters normally ignore spaces in stored values, so quotation marks declare this a string parameter to preserve such characters.
  10. 10. Java Comments • The Java programming language supports three kinds of comments: 1. Double slashes in front of a single line comment: int i=5; // Set the integer to 5 2. Matching slash-asterisk (/*) and asterisk-slash (*/) to bracket multi-line comments: /* Set the integer to 5 */ int i=5; 3. Matching slash-double asterisk (/**) & asterisk-slash(*/) for Javadoc automatic hypertext documentation, as in /** This applet tests graphics.
  11. 11. Java Data and Variables • byte • Short • int • long • float • Double • char • boolean
  12. 12. Java Data and Variables • Integer types have no fractional part; floating point types have a fractional part. On paper, integers have no decimal point, and floating point types do. But in main memory, there are no decimal points: even floating point values are represented with bit patterns. There is a fundamental difference between the method used to represent integers and the method used to represent floating point numbers.
  13. 13. Java Data and Variables • Type Size • byte ……….8 bits • Short……… 16 bits • int …………..32 bits • Long……….. 64 bits • float ……….32 bits • double……. 64 bits • variabletype variablename = data;
  14. 14. Java Data and Variables • For each primitive type, there is a corresponding wrapper class. A wrapper class can be used to convert a primitive data value into an object, and some type of objects into primitive data. The table shows primitive types and their wrapper class • primitive type Wrapper type • byte Byte • short Short • int Int • long Long • Float Float • double Double • char Character • Boolean Boolean
  15. 15. Java Arithmetic Operators • The Java programming language has includes five simple arithmetic operators like are + (addition), - (subtraction), * (multiplication), / (division), and % (modulo). • Use Returns true if • op1 + op2 op1 added to op2 • op1 - op2 op2 subtracted from op1 • op1 * op2 op1 multiplied with op2 • op1 / op2 op1 divided by op2 • op1 % op2 Computes the remainder of dividing op1 by op2
  16. 16. Java Data and Variables • x && y Conditional AND If both x and y are true, result is true. If either x or y are false, the result is false If x is false, y is not evaluated.
  17. 17. Access Modifiers • The first (left-most) modifier used lets you control what other classes have access to a member field. For the moment, consider only public and private. • public modifier—the field is accessible from all classes. • private modifier—the field is accessible only within its own class. • In the spirit of encapsulation, it is common to make fields private. This means that they can only be directly accessed from the Bicycle class. We still need access to these values, however.

×