1 Java Introduction
1 Java Introduction
JAVA
Programming Language
2
is a language for computers. is an artificial language. is a series of instructions based on syntaxes. is a notation for writing programs.
A computer tool that allows a programmer to write commands in a format that is more easily understood or remembered by a person, and in such a way that they can be translated into codes that the computer can understand and execute.
Types
3
every program comes with a starting phase, a list of tasks and operations, and an ending stage. made up of procedures, subroutines, or methods.
Fortran, Basic
requires that programmers break program structure into small pieces of code. associated with a "top-down" approach to design.
C, Pascal
requires the designer to specify the data structures as well as the types of operations to be applied on those data structures. a program thus becomes a collection of cooperating objects, rather than a list of instructions.
Object Oriented Simple & Secure Architecture Neutral Portable & Robust Interpreted High Performance Distributed Dynamic Multi-threaded AWT & Event Handling
Designing Goal
5
Heart of Java
6
The key that allows java to solve both the security and the portability problems just described is that the output of a java compiler is not executable code. It is byte code, byte code is a highly optimized set of instructions designed to be executed by the java runtime system, which is called the java virtual machine (JVM). That is, in its standard form, the JVM is an interpreter for byte code
LANGUAGE FUNDAMENTALS
Installing Java
9
Download the Java Development Kit (JDK) for your platform. (Its free) Run the .exe file to install java on your machine. (or) Follow the instructions given.
Setting Path
10
Start Control Panel System Advanced Click on Environment Variables, under System Variables, find PATH, and click on it. In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value. Close the window. (Or) In command prompt set classpath=%path%;.; (Or) set path=location of class;
To Compile
javac
xxx.java
To Execute
java
xxx
Language Elements
12
Tokens
In
a Java program, all characters are grouped into symbols called tokens.
13
Identifiers: names the programmer chooses Keywords: names already in the programming language Separators (also known as punctuators): punctuation characters and paired-delimiters Operators: symbols that operate on arguments and produce results Literals (specified by their type)
Numeric: int,float and double Logical: boolean Textual: char and String Reference: null
*/
Keywords
14
Keywords are reserved words that are predefined in the language. All the keywords are in lowercase.
Data Types
15
Reference variables are created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed. For example, Employee, Puppy etc. Class objects, and various type of array variables come under reference data type. Default value of any reference variable is null. A reference variable can be used to refer to any object of the declared type or any compatible type. Example : Animal animal = new Animal("giraffe");
Operators
18
An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and variables Ex: a+b
Types
19
1.
2.
3. 4. 5. 6. 7. 8.
Arithmetic operators Relational operators Logical operators Assignment operators Increment and decrement operators Conditional operators Bitwise operators Special operators
Control Statements
20
Selection Statements
if, if-else, if-else-if ladder, nested if-else switch-case
Iteration Statements
while do-while for Nested loops
Jump Statements
break continue return
public class First { public static void main(String args[]) { System.out.println(Java is my passion); } }
Basic Syntax
22
Case Sensitivity - Java is case sensitive which means identifier Hello and hello would have different meaning in Java. Class Names - For all class names the first letter should be in Upper Case. If several words are used to form a name of the class each inner words first letter should be in Upper Case. Example: class MyFirstJavaClass Method Names - All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. Example: public void myMethodName() Program File Name - Name of the program file should exactly match the class name. public static void main(String args[]) - java program processing starts from the main() method which is a mandatory part of every java program..