Difference between revisions of "Java"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Basic Level)
(Introduction)
(19 intermediate revisions by 5 users not shown)
Line 8: Line 8:
  
 
<blockquote style="background-color: lemonchiffon; border: solid thin grey;">
 
<blockquote style="background-color: lemonchiffon; border: solid thin grey;">
[[Media:JavaTemplate.zip | Java Slide Template]]  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 
 
[[Glossary_for_Java | Glossary]]
 
[[Glossary_for_Java | Glossary]]
 
</blockquote>
 
</blockquote>
Line 16: Line 15:
 
== Basic Level==
 
== Basic Level==
  
#Introduction to Java
+
:'''Introduction to Java'''
#*Getting started with Java – installation  
+
#Getting started with Java – installation  
#** Install jdk from Synaptic Package Manager
+
#* Install jdk from Synaptic Package Manager
#** Choose openjdk-6-jdk from the list of packages available  
+
#* Choose openjdk-6-jdk from the list of packages available  
#**Mark it for installation
+
#*Mark it for installation
#**The installation will take a few seconds
+
#*The installation will take a few seconds
#**Verify the installation
+
#*Verify the installation
#**At the command prompt type java -version, so the version number of the jdk will be displayed
+
#*At the command prompt type java -version, so the version number of the jdk will be displayed
#**Run a simple java program and see if it works
+
#*Run a simple java program and see if it works
#**Type javac TestProgram.java for compiling the code and java TestProgram for executing the code
+
#*Type javac TestProgram.java for compiling the code and java TestProgram for executing the code
#*Java - First program
+
#Java - First program
#**write simple java program  
+
#*write simple java program  
#**print “My First Java Program!” on Console
+
#*print “My First Java Program!” on Console
#**save the file
+
#*save the file
#**file name given to the java file
+
#*file name given to the java file
#**compile the file
+
#*compile the file
#**run the file
+
#*run the file
#**correct the errors
+
#*correct the errors
#**naming conventions for class
+
#*naming conventions for class
#**naming conventions for method
+
#*naming conventions for method
#**naming conventions for variable
+
#*naming conventions for variable
#Eclipse
+
#:<br>
#*Installing Eclipse  
+
#:'''Eclipse'''
#**Install Eclipse on Ubuntu on the Terminal
+
#Installing Eclipse  
#**Set up the proxy on the Terminal  
+
#*Install Eclipse on Ubuntu on the Terminal
#**Then fetch the list of all the available softwares
+
#*Set up the proxy on the Terminal  
#**Type sudo apt-get update
+
#*Then fetch the list of all the available softwares
#**Then install eclipse on the Terminal
+
#*Type sudo apt-get update
#**Type sudo apt-get install eclipse
+
#*Then install eclipse on the Terminal
#**Verify if Eclipse is installed on the system
+
#*Type sudo apt-get install eclipse
#**Installing Eclipse on Debian,Kubuntu,Xubuntu
+
#*Verify if Eclipse is installed on the system
#**Installing Eclipse on Redhat  
+
#*Installing Eclipse on Debian,Kubuntu,Xubuntu
#**Installing Eclipse on Fedora,centos and suse linux
+
#*Installing Eclipse on Redhat  
#*Getting started with Eclipse
+
#*Installing Eclipse on Fedora,centos and suse linux
#**Eclipse is an Integrated Development Environment
+
#Getting started with Eclipse
#**It is a tool on which one can write, debug and run java programs easily
+
#*Eclipse is an Integrated Development Environment
#**Open Dash Home and type Eclipse in the search box.
+
#*It is a tool on which one can write, debug and run java programs easily
#**We get Workspace Launcher
+
#*Open Dash Home and type Eclipse in the search box.
#**On clicking on Workbench we get the Eclipse IDE
+
#*We get Workspace Launcher
#**Go to File->New->Project and select Java Project
+
#*On clicking on Workbench we get the Eclipse IDE
#**Create a project named EclipseDemo and create a class inside DemoClass
+
#*Go to File->New->Project and select Java Project
#**Learn about Package Explorer and Editor portlet
+
#*Create a project named EclipseDemo and create a class inside DemoClass
#**Add the println statement in<br/>
+
#*Learn about Package Explorer and Editor portlet
#* Hello World Program
+
#Hello World Program
#**Open Eclipse
+
#*Open Eclipse
#**Create a Java Project named DemoProject
+
#*Create a Java Project named DemoProject
#**Create a class named DemoClass
+
#*Create a class named DemoClass
#**Class name and file name will be the same
+
#*Class name and file name will be the same
#**Eclipse suggests various possibilities as we type a command
+
#*Eclipse suggests various possibilities as we type a command
#**Eclipse also completes the parentheses by automatically adding the closing parentheses
+
#*Eclipse also completes the parentheses by automatically adding the closing parentheses
#**Include the statement that we want to print
+
#*Include the statement that we want to print
#**Eclipse also completes the quotes by adding the closing quote
+
#*Eclipse also completes the quotes by adding the closing quote
#**Compile and execute the program
+
#*Compile and execute the program
#**Change the code to print<br/>  
+
#*Change the code to print<br/>  
#*Errors and Debugging
+
#Errors and Debugging
#**When writing a Java Program, here is a list of typical errors:
+
#*When writing a Java Program, here is a list of typical errors:
#**Missing semicolon(;)
+
#*Missing semicolon(;)
#**Missing double quotes(".")
+
#*Missing double quotes(".")
#**Mis-match of filename and classname
+
#*Mis-match of filename and classname
#**Typing the print statement n lower case
+
#*Typing the print statement n lower case
#**The line which has the error will be indicated with a red cross mark on the left margin
+
#*The line which has the error will be indicated with a red cross mark on the left margin
#**The list of errors is displayed by hovering the mouse over the cross mark
+
#*The list of errors is displayed by hovering the mouse over the cross mark
#**Create a class ErrorFree with Errors, debug the code and run it
+
#*Create a class ErrorFree with Errors, debug the code and run it
#**Eclipse also offers intelligent fixes<br/>  
+
#*Eclipse also offers intelligent fixes<br/>  
#*Programming features of Eclipse
+
#Programming features of Eclipse
#**Auto completion
+
#*Auto completion
#**Sets the corresponding closing brace when we open the brace
+
#*Sets the corresponding closing brace when we open the brace
#**Provides a drop-down list of methods when you start typing the code.
+
#*Provides a drop-down list of methods when you start typing the code.
#**Syntax highlighting
+
#*Syntax highlighting
#**Classname is highlighted in pink color and method in blue color.
+
#*Classname is highlighted in pink color and method in blue color.
#**Keyboard shortcuts
+
#*Keyboard shortcuts
#**F11 to debug a program and Ctrl plus H to search a specific file.
+
#*F11 to debug a program and Ctrl plus H to search a specific file.
#**Error highlighting
+
#*Error highlighting
#**Cross symbol in the program denotes errors
+
#*Cross symbol in the program denotes errors
#**Remove semicolon and error details are displayed when mouse is hovered over cross symbol.
+
#*Remove semicolon and error details are displayed when mouse is hovered over cross symbol.
#Fundamental Programming Structures in Java
+
#:<br>
#* Numerical datatypes
+
#:'''Fundamental Programming Structures in Java'''
#**Define datatypes and numerical datatypes
+
#Numerical datatypes
#**int
+
#*Define datatypes and numerical datatypes
#**float
+
#*int
#**byte
+
#*float
#**short
+
#*byte
#**long
+
#*short
#**double
+
#*long
#**range of each numerical datatypes
+
#*double
#**declaration and initializationof numerical datatypes.
+
#*range of each numerical datatypes
#**valid and invalid declaration
+
#*declaration and initializationof numerical datatypes.
#*Arithmetic Operations
+
#*valid and invalid declaration
#**Define an operator
+
#Arithmetic Operations
#**Define arithmetic operators
+
#*Define an operator
#**addition
+
#*Define arithmetic operators
#**subtraction
+
#*addition
#**multiplication
+
#*subtraction
#**division
+
#*multiplication
#**modulo
+
#*division
#**simple program to demonstrate arithmetic operators
+
#*modulo
#**appropriate datatypes for appropriate values
+
#*simple program to demonstrate arithmetic operators
#**save, compile and run the program<br/>  
+
#*appropriate datatypes for appropriate values
#* Strings
+
#*save, compile and run the program<br/>  
#**char datatype
+
#Strings
#**letter, digit, punctuation marks, '''tab''', or a space are all characters.
+
#*char datatype
#**Program explaining the variable and the character data.
+
#*letter, digit, punctuation marks, '''tab''', or a space are all characters.
* Introduction to strings
+
#*Program explaining the variable and the character data.
* Creating string by Direct Initialization
+
#*Introduction to strings
* Creating string by using new operator
+
#*Creating string by Direct Initialization
* String length()
+
#*Creating string by using new operator
* String concat()
+
#*String length()
* String toUpperCase()
+
#*String concat()
* String toLowerCase()<br/>  
+
#*String toUpperCase()
 
+
#*String toLowerCase()<br/>  
#* Primitive type conversions
+
#Primitive type conversions
 
+
#*define type conversion or type casting
* define type conversion or type casting
+
#*higher order integer to lower order integer- Explicit type casting
* higher order integer to lower order integer- Explicit type casting
+
#*program to show explicit type casting
* program to show explicit type casting
+
#*common mistake in explicit type casting.
* common mistake in explicit type casting.
+
#*program to show common mistake in explicit type casting
* program to show common mistake in explicit type casting
+
#*lower order integer to higher order integer – Implicit type casting
* lower order integer to higher order integer – Implicit type casting
+
#*program to show implicit type casting
* program to show implicit type casting
+
#*char to integer
* char to integer
+
#*integer to char
* integer to char
+
#*program to show char to int type casting.
* program to show char to int type casting.
+
#:<br>
 
+
#:'''Control flow'''
# Control flow
+
#Relational Operations
+
#*boolean datatype
#* Relational Operations
+
#*equal to and not equal to
 
+
#*less than and less than or equal to
* boolean datatype
+
#*greater than and greater than or equal to<br/>  
* equal to and not equal to
+
#Logical Operations
* less than and less than or equal to
+
#*use of logical operators
* greater than and greater than or equal to<br/>  
+
#*and (&&) operator
 
+
#*example to explain '''and''' operator
#* Logical Operations
+
#*program to demonstrate '''and''' operator
 
+
#*or (||) operator
* use of logical operators
+
#*example to explain '''or '''operator
* and (&&) operator
+
#*program to demonstrate '''or '''operator
* example to explain '''and''' operator
+
#*not (!) operator
* program to demonstrate '''and''' operator
+
#*program to demonstrate '''or '''operator
* or (||) operator
+
#*save, compile and run the programs<br/>  
* example to explain '''or '''operator
+
#if else construct
* program to demonstrate '''or '''operator
+
#*Conditional Statements and types of Conditional Statements
* not (!) operator
+
#*Use of if statement
* program to demonstrate '''or '''operator
+
#*Syntax for if statement
* save, compile and run the programs<br/>  
+
#*Program using if statement
 
+
#*Use of if else statement
#*if else construct
+
#*Syntax for if else statement
 
+
#*Program using if else statement
* Conditional Statements and types of Conditional Statements
+
#*Use of if else if statement
* Use of if statement
+
#*Syntax for if else if statement
* Syntax for if statement
+
#*Program using if else if statement<br/>  
* Program using if statement
+
#nested if and ternary operator
* Use of if else statement
+
#*explain nested if
* Syntax for if else statement
+
#*nested if syntax
* Program using if else statement
+
#*program to demonstrate nested if
* Use of if else if statement
+
#*explain the control flow of the program
* Syntax for if else if statement
+
#*explain ternary operator
* Program using if else if statement<br/>  
+
#*syntax for ternary operator
 
+
#*explain the syntax
#* nested if and ternary operator
+
#*program to demonstrate ternary operator
 
+
#*comparison between ternary operator and nested if
* explain nested if
+
#*save, compile and run the program<br/>  
* nested if syntax
+
#switch statement
* program to demonstrate nested if
+
#*define switch case statement
* explain the control flow of the program
+
#*compare switch and nested if
* explain ternary operator
+
#*switch case syntax
* syntax for ternary operator
+
#*working of a switch case statement
* explain the syntax
+
#*use of keyword switch
* program to demonstrate ternary operator
+
#*valid and invalid use of keyword '''case'''
* comparison between ternary operator and nested if
+
#*use of keyword default
* save, compile and run the program<br/>  
+
#*use of keyword break
 
+
#*program to demonstrate switch case statement
#* switch statement
+
#*save, compile and run the program to check the output
 
+
#while loop
* define switch case statement
+
#*Loop control statement  
* compare switch and nested if
+
#*types of loop control statements
* switch case syntax
+
#*Introduction to while loop
* working of a switch case statement
+
#*syntax of while loop
* use of keyword switch
+
#*Program using while loop
* valid and invalid use of keyword '''case'''
+
#*Check the output.
* use of keyword default
+
#*Introduction to infinite loop
* use of keyword break
+
#*loop variable modification
* program to demonstrate switch case statement
+
#*Check the output
* save, compile and run the program to check the output
+
#*How to terminate the infinite loop<br/>  
 
+
#for loop
#* while loop
+
#*syntax
 
+
#*introduction to for loop
* Loop control statement  
+
#*for loop syntax
* types of loop control statements
+
#*loop vaiable
* Introduction to while loop
+
#*loop condition
* syntax of while loop
+
#*loop variable increment or decrement
* Program using while loop
+
#* loop block
* Check the output.
+
#*flow of loop
* Introduction to infinite loop
+
#*advantage of using loop
* loop variable modification
+
#do while loop
* Check the output
+
#*define do while  
* How to terminate the infinite loop<br/>  
+
#*do while syntax
 
+
#*working of do while loop
 
+
#*example of do while loop
#* for loop
+
#*explain the do while programming
 
+
#*save, compile and run the program to check the output  
* syntax
+
#*how different is it from the while loop
* loop continuing condition
+
#*program to demonstrate the differences
* loop variable modification<br/>
+
#:<br>
 
+
#:'''Arrays'''
#* do while loop
+
#Introduction to Arrays
 
+
#*About Arrays
* define do while  
+
#*Declare an Array
* do while syntax
+
#*Initialize an array
* working of do while loop
+
#*Intilalization using for loop
* example of do while loop
+
#*Index of an array elements
* explain the do while programming
+
#*change values of an array
* save, compile and run the program to check the output  
+
#*print the value of an array
* how different is it from the while loop
+
#*Advantage of an array.
* program to demonstrate the differences
+
#Array operations
 
+
#*import java.util.Arrays
# Arrays  
+
#*use methods from class Arrays
 
+
#*toString() method
#* Introduction to Arrays
+
#*sort() method
 
+
#*fill() method
* What are arrays
+
#*copyof() method
* Types of arrays
+
#*copyofRange() method
* How to create arrays
+
#*about parameters for each method.
 
+
#:'''Classes & Objects''' 
#*Array operations
+
#Creating class  
 
+
#*Whatever we can see in this world are all objects
* Accessing array items
+
#*Objects can be categorized into groups known as class
* Checking for bounds
+
#*This is class in real world
 
+
#*Human Being is an example of class in real world
#Classes & Objects  
+
#*Class in java is the blue print from which individual objects are created
 
+
#*Class consists defines a set of properties called variables and a set of behaviors called methods
#* Creating class  
+
#*Syntax for creating class
 
+
#*Create a simple class Student using Eclipse
* Whatever we can see in this world are all objects
+
#*The Student class can contain properties<br/>  
* Objects can be categorized into groups known as class
+
#Creating Object
* This is class in real world
+
#*An object is an instance of a class
* Human Being is an example of class in real world
+
#*Each object consist of state and behavior
* Class in java is the blue print from which individual objects are created
+
#*Object stores it state in fields or variables
* Class consists defines a set of properties called variables and a set of behaviors called methods
+
#*It exposes its behavior through methods
* Syntax for creating class
+
#*Reference variables
* Create a simple class Student using Eclipse
+
#*Create a class named TestStudent
* The Student class can contain properties<br/>  
+
#*Create an object of the Student class
 
+
#*Use new operator
#*Creating Object
+
#*Check what the reference variable contains
 
+
#*Create one more object of the Student class and check what the reference variable contains
* An object is an instance of a class
+
#Instance fields
* Each object consist of state and behavior
+
#*Also known as non-static fields
* Object stores it state in fields or variables
+
#*Open the TestStudent class which we have created
* It exposes its behavior through methods
+
#*Access the fields roll_number and name using dot operator
* Reference variables
+
#*See the output
* Create a class named TestStudent
+
#*Initialize the field and see the output
* Create an object of the Student class
+
#*Change the modifier of the fields to private
* Use new operator
+
#*Debug the error that you get
* Check what the reference variable contains
+
#*Change the modifier to protected
* Create one more object of the Student class and check what the reference variable contains
+
#*Each object of a class will have unique values
 
+
#*Create two objects of the Student class  
#* Instance fields
+
#Methods
 
+
#*method definition  
* Also known as non-static fields
+
#*write simple method
* Open the TestStudent class which we have created
+
#*method returning value
* Access the fields roll_number and name using dot operator
+
#*call a method in another method
* See the output
+
#*flow of the program
* Initialize the field and see the output
+
#*call a static method
* Change the modifier of the fields to private
+
#*call a method from another class
* Debug the error that you get
+
#*method signature
* Change the modifier to protected
+
#*method body  
* Each object of a class will have unique values
+
#:<br>
* Create two objects of the Student class  
+
#:'''Constructors'''
 
+
#Default constructor
#* Methods
+
#*what is a constructor?
 
+
#*what is a default constructor?
* method definition  
+
#*when is it called?
* write simple method
+
#*define a constructor
* method returning value
+
#*initialize the variables
* call a method in another method
+
#*call the constructor
* flow of the program
+
#*difference between constructor and method<br/>  
* call a static method
+
#Parameterized constructors
* call a method from another class
+
#*What is a parameterized constructor?
* method signature
+
#*create constructor without parameter
* method body  
+
#*create a constructor with parameter
 
+
#*assign values to the variables in the constructor
# Constructors
+
#*pass arguments during the constructor call
 
+
#*working of parameterized constructor
#*Default constructor
+
#*show common errors
 
+
#*resolve the errors
* what is a constructor?
+
#*create another parameterized constructor
* what is a default constructor?
+
#*why to use constructor?
* when is it called?
+
#Using this keyword
* define a constructor
+
#*this is a reference to the current object
* initialize the variables
+
#*helps to avoid name conflicts
* call the constructor
+
#*we can use this keyword inside a constructor to call another one
* difference between constructor and method<br/>  
+
#*the constructors must be in the same class
 
+
#*explicit constructor invocation
#*Parameterized constructors
+
#*Explain it using the parameterized constructor code
 
+
#*Make this statement the last one in the constructor
* What is a parameterized constructor?
+
#*You will get an error
* create constructor without parameter
+
#*this statement should be the first one inside a constructor
* create a constructor with parameter
+
#Non-static block
* assign values to the variables in the constructor
+
#*Non-static block  
* pass arguments during the constructor call
+
#*Any code written between two curly brackets  
* working of parameterized constructor
+
#*Executed for each object that is created  
* show common errors
+
#*Executes before constructor's execution  
* resolve the errors
+
#*can initialize instance member variables of the class  
* create another parameterized constructor
+
#*create a class named NonStaticTest  
* why to use constructor?
+
#*Create a non-static block and a constructor inside it  
 
+
#*Check the output  
#*Using this keyword
+
#*Include multiple non-static blocks  
 
+
#*they will be executed in the sequence in which they appear in the class  
* this is a reference to the current object
+
#*Check the output  
* helps to avoid name conflicts
+
#*Non-static block is not a substitute for constructor
* we can use this keyword inside a constructor to call another one
+
#Constructor Overloading
* the constructors must be in the same class
+
#*define multiple constructor
* explicit constructor invocation
+
#*what is constructor overloading?
* Explain it using the parameterized constructor code
+
#*constructor with different number of parameters.
* Make this statement the last one in the constructor
+
#*parameters with different datatypes.
* You will get an error
+
#*how is constructor overloaded?
* this statement should be the first one inside a constructor
+
#*flow of overloading process.
 
+
#*advantage of constructor overloading.
#*Non-static block
+
#Method Overloading
 
+
#*define multiple methods.
* Non-static block  
+
#*methods with same name.
* Any code written between two curly brackets  
+
#*methods with different number of parameters.
* Executed for each object that is created  
+
#*methods with different datatypes of parameter.
* Executes before constructor's execution  
+
#*what is method overloading?
* can initialize instance member variables of the class  
+
#*example for overloadin method
* create a class named NonStaticTest  
+
#*how to overload method?
* Create a non-static block and a constructor inside it  
+
#*advantage of method overloading.
* Check the output  
+
#*error in method overloading.
* Include multiple non-static blocks  
+
#Taking user input in Java
* they will be executed in the sequence in which they appear in the class  
+
#*What is BufferedReader?
* Check the output  
+
#*Importing three classes from Java.io package
* Non-static block is not a substitute for constructor
+
#*How to take the input from the user?
 
+
#*Syntax to implement BufferedReader
#*Constructor Overloading
+
#*What is InputStreamReader?
 
+
#*Create object of InputStreamReader
* define multiple constructor
+
#*Create object of BufferedReader
* what is constructor overloading?
+
#*About IOException
* constructor with different number of parameters.
+
#*About throws keyword
* parameters with different datatypes.
+
#*Typecasting
* how is constructor overloaded?
+
* flow of overloading process.
+
* advantage of constructor overloading.
+
 
+
#*Method Overloading
+
 
+
* define multiple methods.
+
* methods with same name.
+
* methods with different number of parameters.
+
* methods with different datatypes of parameter.
+
* what is method overloading?
+
* example for overloadin method
+
* how to overload method?
+
* advantage of method overloading.
+
* error in method overloading.
+
  
 
== Intermediate Level ==
 
== Intermediate Level ==
 
+
#Subclassing and Method Overriding
== Advanced Level ==
+
#*Definition of subclassing
 +
#*Demo of subclassing using an Employee and Manager class
 +
#*Single inheritance
 +
#*Use of extends keyword
 +
#*Private members in a super class
 +
#*Definition of method overriding
 +
#*Annotation
 +
#*@Override Annotation
 +
#Calling methods of the superclass
 +
#*super keyword
 +
#*Call methods of the super class
 +
#*Constructor of the super class
 +
#*Demo of super keyword using an Employee and Manager class
 +
#*Single inheritance
 +
#*Use of extends keyword
 +
#*Private members in a super class
 +
#Using final keyboard
 +
#*final keyword
 +
#*What is final keyword and its application?
 +
#*Where final keyword can be declared?
 +
#*final variable
 +
#*final static variables
 +
#*static block
 +
#*final variable as parameter
 +
#*final method
 +
#*private final method
 +
#*final class
 +
#Polymorphism
 +
#*Polymorphism in Java
 +
#*Run-time polymorphism
 +
#*Virtual Method Invocation
 +
#*Compile-time polymorphism
 +
#*Role of JVM
 +
#*IS-A test
 +
#*Static binding
 +
#*Dynamic binding
 +
#Abstract Classes
 +
#*Abstract Classes in Java
 +
#*What  are Abstract Methods
 +
#*What are Concrete Methods
 +
#*Properties of Abstract Methods and Abstract Classes
 +
#*How to use Abstract Methods
 +
#Java Interfaces
 +
#*Java Interfaces
 +
#*Implementing Interface
 +
#*Implementation Classes
 +
#*Interfaces Vs Abstract classes
 +
#*Implementing Multiple Interfaces
 +
#*Usage of Interfaces with an example
 +
#Static Variables
 +
#*What is Static Variable in Java?
 +
#*Usage of Static Variables with Example
 +
#*Static Variables Vs Instance Variables
 +
#*Final Static Constants
 +
#Static Methods
 +
#*What is static method in Java?
 +
#*Static methods Vs Instance methods
 +
#*Usage of static method with example
 +
#*Passing object variables in a static method
 +
#Static Blocks
 +
#*What is a static block
 +
#*Declaring and defining a static block
 +
#*How static blocks are invoked and executed

Revision as of 08:35, 26 March 2018

Introduction

Welcome to online web tutorials for java
Java[ http://java.sun.com ]is a free and open source high level programming language. It is simple as well as object oriented language. Till date, the Java platform has attracted more than 6.5 million software developers. Java Platform, Standard Edition (Java SE) lets you develop and deploy Java applications on desktops and servers, as well as today's demanding Embedded and Real-Time environments.From laptops to mobile phones, game consoles to scientific supercomputers, music players to the Internet,Set-top boxes to printers, Web cams to medical devices,Ooops that is a huge list to follow,Java is everywhere!!!!!

This set of tutorials will cover features and usage of Java version 1.6.x Please see the associated text box of individual spoken tutorials on the website to decide the versions of Java and OS to which it is applicable.

The Spoken Tutorial Effort for Java is contributed jointly by TalentSprint, Hyderabad and the Spoken Tutorial Team, IIT Bombay. Other contributors who helped in the creation of the scripts are ............

Glossary

Basic Level

Introduction to Java
  1. Getting started with Java – installation
    • Install jdk from Synaptic Package Manager
    • Choose openjdk-6-jdk from the list of packages available
    • Mark it for installation
    • The installation will take a few seconds
    • Verify the installation
    • At the command prompt type java -version, so the version number of the jdk will be displayed
    • Run a simple java program and see if it works
    • Type javac TestProgram.java for compiling the code and java TestProgram for executing the code
  2. Java - First program
    • write simple java program
    • print “My First Java Program!” on Console
    • save the file
    • file name given to the java file
    • compile the file
    • run the file
    • correct the errors
    • naming conventions for class
    • naming conventions for method
    • naming conventions for variable

    Eclipse
  3. Installing Eclipse
    • Install Eclipse on Ubuntu on the Terminal
    • Set up the proxy on the Terminal
    • Then fetch the list of all the available softwares
    • Type sudo apt-get update
    • Then install eclipse on the Terminal
    • Type sudo apt-get install eclipse
    • Verify if Eclipse is installed on the system
    • Installing Eclipse on Debian,Kubuntu,Xubuntu
    • Installing Eclipse on Redhat
    • Installing Eclipse on Fedora,centos and suse linux
  4. Getting started with Eclipse
    • Eclipse is an Integrated Development Environment
    • It is a tool on which one can write, debug and run java programs easily
    • Open Dash Home and type Eclipse in the search box.
    • We get Workspace Launcher
    • On clicking on Workbench we get the Eclipse IDE
    • Go to File->New->Project and select Java Project
    • Create a project named EclipseDemo and create a class inside DemoClass
    • Learn about Package Explorer and Editor portlet
  5. Hello World Program
    • Open Eclipse
    • Create a Java Project named DemoProject
    • Create a class named DemoClass
    • Class name and file name will be the same
    • Eclipse suggests various possibilities as we type a command
    • Eclipse also completes the parentheses by automatically adding the closing parentheses
    • Include the statement that we want to print
    • Eclipse also completes the quotes by adding the closing quote
    • Compile and execute the program
    • Change the code to print
  6. Errors and Debugging
    • When writing a Java Program, here is a list of typical errors:
    • Missing semicolon(;)
    • Missing double quotes(".")
    • Mis-match of filename and classname
    • Typing the print statement n lower case
    • The line which has the error will be indicated with a red cross mark on the left margin
    • The list of errors is displayed by hovering the mouse over the cross mark
    • Create a class ErrorFree with Errors, debug the code and run it
    • Eclipse also offers intelligent fixes
  7. Programming features of Eclipse
    • Auto completion
    • Sets the corresponding closing brace when we open the brace
    • Provides a drop-down list of methods when you start typing the code.
    • Syntax highlighting
    • Classname is highlighted in pink color and method in blue color.
    • Keyboard shortcuts
    • F11 to debug a program and Ctrl plus H to search a specific file.
    • Error highlighting
    • Cross symbol in the program denotes errors
    • Remove semicolon and error details are displayed when mouse is hovered over cross symbol.

    Fundamental Programming Structures in Java
  8. Numerical datatypes
    • Define datatypes and numerical datatypes
    • int
    • float
    • byte
    • short
    • long
    • double
    • range of each numerical datatypes
    • declaration and initializationof numerical datatypes.
    • valid and invalid declaration
  9. Arithmetic Operations
    • Define an operator
    • Define arithmetic operators
    • addition
    • subtraction
    • multiplication
    • division
    • modulo
    • simple program to demonstrate arithmetic operators
    • appropriate datatypes for appropriate values
    • save, compile and run the program
  10. Strings
    • char datatype
    • letter, digit, punctuation marks, tab, or a space are all characters.
    • Program explaining the variable and the character data.
    • Introduction to strings
    • Creating string by Direct Initialization
    • Creating string by using new operator
    • String length()
    • String concat()
    • String toUpperCase()
    • String toLowerCase()
  11. Primitive type conversions
    • define type conversion or type casting
    • higher order integer to lower order integer- Explicit type casting
    • program to show explicit type casting
    • common mistake in explicit type casting.
    • program to show common mistake in explicit type casting
    • lower order integer to higher order integer – Implicit type casting
    • program to show implicit type casting
    • char to integer
    • integer to char
    • program to show char to int type casting.

    Control flow
  12. Relational Operations
    • boolean datatype
    • equal to and not equal to
    • less than and less than or equal to
    • greater than and greater than or equal to
  13. Logical Operations
    • use of logical operators
    • and (&&) operator
    • example to explain and operator
    • program to demonstrate and operator
    • or (||) operator
    • example to explain or operator
    • program to demonstrate or operator
    • not (!) operator
    • program to demonstrate or operator
    • save, compile and run the programs
  14. if else construct
    • Conditional Statements and types of Conditional Statements
    • Use of if statement
    • Syntax for if statement
    • Program using if statement
    • Use of if else statement
    • Syntax for if else statement
    • Program using if else statement
    • Use of if else if statement
    • Syntax for if else if statement
    • Program using if else if statement
  15. nested if and ternary operator
    • explain nested if
    • nested if syntax
    • program to demonstrate nested if
    • explain the control flow of the program
    • explain ternary operator
    • syntax for ternary operator
    • explain the syntax
    • program to demonstrate ternary operator
    • comparison between ternary operator and nested if
    • save, compile and run the program
  16. switch statement
    • define switch case statement
    • compare switch and nested if
    • switch case syntax
    • working of a switch case statement
    • use of keyword switch
    • valid and invalid use of keyword case
    • use of keyword default
    • use of keyword break
    • program to demonstrate switch case statement
    • save, compile and run the program to check the output
  17. while loop
    • Loop control statement
    • types of loop control statements
    • Introduction to while loop
    • syntax of while loop
    • Program using while loop
    • Check the output.
    • Introduction to infinite loop
    • loop variable modification
    • Check the output
    • How to terminate the infinite loop
  18. for loop
    • syntax
    • introduction to for loop
    • for loop syntax
    • loop vaiable
    • loop condition
    • loop variable increment or decrement
    • loop block
    • flow of loop
    • advantage of using loop
  19. do while loop
    • define do while
    • do while syntax
    • working of do while loop
    • example of do while loop
    • explain the do while programming
    • save, compile and run the program to check the output
    • how different is it from the while loop
    • program to demonstrate the differences

    Arrays
  20. Introduction to Arrays
    • About Arrays
    • Declare an Array
    • Initialize an array
    • Intilalization using for loop
    • Index of an array elements
    • change values of an array
    • print the value of an array
    • Advantage of an array.
  21. Array operations
    • import java.util.Arrays
    • use methods from class Arrays
    • toString() method
    • sort() method
    • fill() method
    • copyof() method
    • copyofRange() method
    • about parameters for each method.
    Classes & Objects
  22. Creating class
    • Whatever we can see in this world are all objects
    • Objects can be categorized into groups known as class
    • This is class in real world
    • Human Being is an example of class in real world
    • Class in java is the blue print from which individual objects are created
    • Class consists defines a set of properties called variables and a set of behaviors called methods
    • Syntax for creating class
    • Create a simple class Student using Eclipse
    • The Student class can contain properties
  23. Creating Object
    • An object is an instance of a class
    • Each object consist of state and behavior
    • Object stores it state in fields or variables
    • It exposes its behavior through methods
    • Reference variables
    • Create a class named TestStudent
    • Create an object of the Student class
    • Use new operator
    • Check what the reference variable contains
    • Create one more object of the Student class and check what the reference variable contains
  24. Instance fields
    • Also known as non-static fields
    • Open the TestStudent class which we have created
    • Access the fields roll_number and name using dot operator
    • See the output
    • Initialize the field and see the output
    • Change the modifier of the fields to private
    • Debug the error that you get
    • Change the modifier to protected
    • Each object of a class will have unique values
    • Create two objects of the Student class
  25. Methods
    • method definition
    • write simple method
    • method returning value
    • call a method in another method
    • flow of the program
    • call a static method
    • call a method from another class
    • method signature
    • method body

    Constructors
  26. Default constructor
    • what is a constructor?
    • what is a default constructor?
    • when is it called?
    • define a constructor
    • initialize the variables
    • call the constructor
    • difference between constructor and method
  27. Parameterized constructors
    • What is a parameterized constructor?
    • create constructor without parameter
    • create a constructor with parameter
    • assign values to the variables in the constructor
    • pass arguments during the constructor call
    • working of parameterized constructor
    • show common errors
    • resolve the errors
    • create another parameterized constructor
    • why to use constructor?
  28. Using this keyword
    • this is a reference to the current object
    • helps to avoid name conflicts
    • we can use this keyword inside a constructor to call another one
    • the constructors must be in the same class
    • explicit constructor invocation
    • Explain it using the parameterized constructor code
    • Make this statement the last one in the constructor
    • You will get an error
    • this statement should be the first one inside a constructor
  29. Non-static block
    • Non-static block
    • Any code written between two curly brackets
    • Executed for each object that is created
    • Executes before constructor's execution
    • can initialize instance member variables of the class
    • create a class named NonStaticTest
    • Create a non-static block and a constructor inside it
    • Check the output
    • Include multiple non-static blocks
    • they will be executed in the sequence in which they appear in the class
    • Check the output
    • Non-static block is not a substitute for constructor
  30. Constructor Overloading
    • define multiple constructor
    • what is constructor overloading?
    • constructor with different number of parameters.
    • parameters with different datatypes.
    • how is constructor overloaded?
    • flow of overloading process.
    • advantage of constructor overloading.
  31. Method Overloading
    • define multiple methods.
    • methods with same name.
    • methods with different number of parameters.
    • methods with different datatypes of parameter.
    • what is method overloading?
    • example for overloadin method
    • how to overload method?
    • advantage of method overloading.
    • error in method overloading.
  32. Taking user input in Java
    • What is BufferedReader?
    • Importing three classes from Java.io package
    • How to take the input from the user?
    • Syntax to implement BufferedReader
    • What is InputStreamReader?
    • Create object of InputStreamReader
    • Create object of BufferedReader
    • About IOException
    • About throws keyword
    • Typecasting

Intermediate Level

  1. Subclassing and Method Overriding
    • Definition of subclassing
    • Demo of subclassing using an Employee and Manager class
    • Single inheritance
    • Use of extends keyword
    • Private members in a super class
    • Definition of method overriding
    • Annotation
    • @Override Annotation
  2. Calling methods of the superclass
    • super keyword
    • Call methods of the super class
    • Constructor of the super class
    • Demo of super keyword using an Employee and Manager class
    • Single inheritance
    • Use of extends keyword
    • Private members in a super class
  3. Using final keyboard
    • final keyword
    • What is final keyword and its application?
    • Where final keyword can be declared?
    • final variable
    • final static variables
    • static block
    • final variable as parameter
    • final method
    • private final method
    • final class
  4. Polymorphism
    • Polymorphism in Java
    • Run-time polymorphism
    • Virtual Method Invocation
    • Compile-time polymorphism
    • Role of JVM
    • IS-A test
    • Static binding
    • Dynamic binding
  5. Abstract Classes
    • Abstract Classes in Java
    • What are Abstract Methods
    • What are Concrete Methods
    • Properties of Abstract Methods and Abstract Classes
    • How to use Abstract Methods
  6. Java Interfaces
    • Java Interfaces
    • Implementing Interface
    • Implementation Classes
    • Interfaces Vs Abstract classes
    • Implementing Multiple Interfaces
    • Usage of Interfaces with an example
  7. Static Variables
    • What is Static Variable in Java?
    • Usage of Static Variables with Example
    • Static Variables Vs Instance Variables
    • Final Static Constants
  8. Static Methods
    • What is static method in Java?
    • Static methods Vs Instance methods
    • Usage of static method with example
    • Passing object variables in a static method
  9. Static Blocks
    • What is a static block
    • Declaring and defining a static block
    • How static blocks are invoked and executed

Contributors and Content Editors

Arya Ratish, Minal, Nancyvarkey, PoojaMoolya, Pratham920, Pratik kamble, Priyacst