Learn Java language fundamentals with Unit nexus

29
Java Language Fundamentals / 1 of 28 Java Language Fundamentals Session 2

description

Learn Java with unit nexus pvt ltd with practical on live projects.

Transcript of Learn Java language fundamentals with Unit nexus

Page 1: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 1 of 28

Java Language Fundamentals

Session 2

Page 2: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 2 of 28

Objectives

Interpret the Java program Understand the basics of the Java language Identify data types

Page 3: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 3 of 28

Java Program Structure

Environment Information Class Declaration Tokens:

Identifiers Keywords / Reserve words Separators Literals Operators

Page 4: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 4 of 28

Sample Java program

Page 5: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 5 of 28

Compiling and executing the sample program

Page 6: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 6 of 28

Passing Command Line Arguments (1)

Page 7: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 7 of 28

Passing Command Line Arguments (2)

Page 8: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 8 of 28

Basics of the Java Language

Classes & Methods

Data types

Variables

Operators

Control structures

Page 9: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 9 of 28

Classes in Java

Class declaration Syntax

class Classname {

var_datatype variablename;:

 met_datatype methodname(parameter_list):

}

Page 10: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 10 of 28

Sample class

Page 11: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 11 of 28

Nested Classes

Defining one class within another is called ‘Nesting’

Types: Static Non-static

Page 12: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 12 of 28

Data Types

byte char boolean short int long float double

Array

Class

Interface

Page 13: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 13 of 28

Type Casting

One data type is converted into another data type

Example float c = 34.89675f;

int b = (int)c + 10;

Page 14: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 14 of 28

Variables

Three components of a variable declaration: Data type Name Initial value to be assigned (optional)

Syntaxdatatype identifier [=value][, identifier[=value]...];

Page 15: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 15 of 28

Java Reserve words

Page 16: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 16 of 28

Array Declarations

Three ways for Array Declaration: datatype identifier [ ];

datatype identifier [ ] = new datatype[size];

datatype identifier [ ]= {value1,value2,….valueN};

Page 17: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 17 of 28

Methods in Classes

A method is defined as the actual implementation of an operation on an object

Syntax access_specifier modifier datatype method_name(parameter_list)

{

//body of method

}

Page 18: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 18 of 28

Sample usage of Method

Page 19: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 19 of 28

Access specifiers for Methods

Page 20: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 20 of 28

Method Modifiers static

abstract

final

native

synchronized

volatile

Page 21: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 21 of 28

Methods Overloading

Overloaded Methods: Are in the same class Have the same name Have different parameter lists

Overloaded methods are a form of compile time polymorphism

Page 22: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 22 of 28

Methods Overriding

Overridden Methods: Are in the superclass as well as the subclass Are redefined in the subclass

Overridden methods are a form of runtime polymorphism

Page 23: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 23 of 28

Class Constructors

Special method used to initialize member variables of the class

Same name as the Class name and does not have a return type

Called when an object is created Types:

Explicit constructors Implicit constructors

Page 24: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 24 of 28

Derived class constructors

Has the same name as the subclass

Statement that calls the constructor of the superclass should be the first statement in the constructor of a subclass

Page 25: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 25 of 28

Operators

Java Provides following categories of Operators: Arithmetic Operators Bitwise Operators Relational Operators Logical Operators Conditional Operators Assignment Operators

Page 26: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 26 of 28

Operator Precedence

Page 27: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 27 of 28

Escape Sequence

Page 28: Learn Java language fundamentals with Unit nexus

Java Language Fundamentals / 28 of 28

Control Flow

Decision – making if-else statement Switch-else statement

Loops while loop do-while loop for loop

Page 29: Learn Java language fundamentals with Unit nexus

Want to contact Unit Nexus

Unit Nexus Zirakpur Official Website Like Unit Nexus Pvt. Ltd. On Facebook Add Unit Nexus to your professional Network

on Linked In Company Profile of Unit Nexus

Java Language Fundamentals / 29 of 28