Difference between revisions of "Java"
Pratham920 (Talk | contribs) (→Basic Level) |
PoojaMoolya (Talk | contribs) (→Intermediate Level) |
||
(33 intermediate revisions by 6 users not shown) | |||
Line 5: | Line 5: | ||
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. | 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 . | + | 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 Prathamesh Salunke, Arya Ratish, Ashwini Patil. |
+ | |||
+ | '''Learners''': UG/PG CSE/IT/CS students. | ||
<blockquote style="background-color: lemonchiffon; border: solid thin grey;"> | <blockquote style="background-color: lemonchiffon; border: solid thin grey;"> | ||
− | |||
[[Glossary_for_Java | Glossary]] | [[Glossary_for_Java | Glossary]] | ||
</blockquote> | </blockquote> | ||
Line 14: | Line 15: | ||
__TOC__ | __TOC__ | ||
− | = Basic Level = | + | == Basic Level== |
− | # | + | :'''Introduction to Java''' |
− | * Install jdk from Synaptic Package Manager | + | #Getting started with Java – installation |
− | * Choose openjdk-6-jdk from the list of packages available | + | #* Install jdk from Synaptic Package Manager |
− | * Mark it for installation | + | #* Choose openjdk-6-jdk from the list of packages available |
− | * The installation will take a few seconds | + | #*Mark it for installation |
− | * Verify the installation | + | #*The installation will take a few seconds |
− | * At the command prompt type java -version, so the version number of the jdk will be displayed | + | #*Verify the installation |
− | * Run a simple java program and see if it works | + | #*At the command prompt type java -version, so the version number of the jdk will be displayed |
− | * Type javac TestProgram.java for compiling the code and java TestProgram for executing the code | + | #*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 | |
− | + | #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 | + | #:<br> |
− | + | #:'''Eclipse''' | |
− | + | #Installing Eclipse | |
− | + | #*Install Eclipse on Ubuntu on the Terminal | |
− | * Install Eclipse on Ubuntu on the Terminal | + | #*Set up the proxy on the Terminal |
− | * Set up the proxy on the Terminal | + | #*Then fetch the list of all the available softwares |
− | * Then fetch the list of all the available softwares | + | #*Type sudo apt-get update |
− | * Type sudo apt-get update | + | #*Then install eclipse on the Terminal |
− | * Then install eclipse on the Terminal | + | #*Type sudo apt-get install eclipse |
− | * Type sudo apt-get install eclipse | + | #*Verify if Eclipse is installed on the system |
− | * Verify if Eclipse is installed on the system | + | #*Installing Eclipse on Debian,Kubuntu,Xubuntu |
− | * Installing Eclipse on Debian,Kubuntu,Xubuntu | + | #*Installing Eclipse on Redhat |
− | * Installing Eclipse on Redhat | + | #*Installing Eclipse on Fedora,centos and suse linux |
− | * Installing Eclipse on Fedora,centos and suse linux | + | #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. | |
− | * Eclipse is an Integrated Development Environment | + | #*We get Workspace Launcher |
− | * It is a tool on which one can write, debug and run java programs easily | + | #*On clicking on Workbench we get the Eclipse IDE |
− | * Open Dash Home and type Eclipse in the search box. | + | #*Go to File->New->Project and select Java Project |
− | * We get Workspace Launcher | + | #*Create a project named EclipseDemo and create a class inside DemoClass |
− | * On clicking on Workbench we get the Eclipse IDE | + | #*Learn about Package Explorer and Editor portlet |
− | * Go to File->New->Project and select Java Project | + | #Hello World Program |
− | * Create a project named EclipseDemo and create a class inside DemoClass | + | #*Open Eclipse |
− | * Learn about Package Explorer and Editor portlet | + | #*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 | |
− | * Open Eclipse | + | #*Eclipse also completes the quotes by adding the closing quote |
− | * Create a Java Project named DemoProject | + | #*Compile and execute the program |
− | * Create a class named DemoClass | + | #*Change the code to print<br/> |
− | * Class name and file name will be the same | + | #Errors and Debugging |
− | * Eclipse suggests various possibilities as we type a command | + | #*When writing a Java Program, here is a list of typical errors: |
− | * Eclipse also completes the parentheses by automatically adding the closing parentheses | + | #*Missing semicolon(;) |
− | * Include the statement that we want to print | + | #*Missing double quotes(".") |
− | * Eclipse also completes the quotes by adding the closing quote | + | #*Mis-match of filename and classname |
− | * Compile and execute the program | + | #*Typing the print statement n lower case |
− | * Change the code to print<br/> | + | #*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<br/> | |
− | + | #Programming features of Eclipse | |
− | * When writing a Java Program, here is a list of typical errors: | + | #*Auto completion |
− | * Missing semicolon(;) | + | #*Sets the corresponding closing brace when we open the brace |
− | * Missing double quotes(".") | + | #*Provides a drop-down list of methods when you start typing the code. |
− | * Mis-match of filename and classname | + | #*Syntax highlighting |
− | * Typing the print statement n lower case | + | #*Classname is highlighted in pink color and method in blue color. |
− | * The line which has the error will be indicated with a red cross mark on the left margin | + | #*Keyboard shortcuts |
− | * The list of errors is displayed by hovering the mouse over the cross mark | + | #*F11 to debug a program and Ctrl plus H to search a specific file. |
− | * Create a class ErrorFree with Errors, debug the code and run it | + | #*Error highlighting |
− | * Eclipse also offers intelligent fixes<br/> | + | #*Cross symbol in the program denotes errors |
− | + | #*Remove semicolon and error details are displayed when mouse is hovered over cross symbol. | |
− | + | #:<br> | |
− | + | #:'''Fundamental Programming Structures in Java''' | |
− | + | #Numerical datatypes | |
− | * Auto completion | + | #*Define datatypes and numerical datatypes |
− | * Sets the corresponding closing brace when we open the brace | + | #*int |
− | * Provides a drop-down list of methods when you start typing the code. | + | #*float |
− | * | + | #*byte |
− | * | + | #*short |
− | * | + | #*long |
− | * F11 to debug a program and Ctrl plus H to search a specific file. | + | #*double |
− | * | + | #*range of each numerical datatypes |
− | * | + | #*declaration and initializationof numerical datatypes. |
− | * Remove semicolon and error details are displayed when mouse is hovered over cross symbol. | + | #*valid and invalid declaration |
− | + | #Arithmetic Operations | |
− | + | #*Define an operator | |
− | + | #*Define arithmetic operators | |
− | + | #*addition | |
− | + | #*subtraction | |
− | * | + | #*multiplication |
− | * int | + | #*division |
− | * float | + | #*modulo |
− | * byte | + | #*simple program to demonstrate arithmetic operators |
− | * short | + | #*appropriate datatypes for appropriate values |
− | * long | + | #*save, compile and run the program<br/> |
− | * double | + | #Strings |
− | * range of each numerical datatypes | + | #*char datatype |
− | * declaration and initializationof numerical datatypes. | + | #*letter, digit, punctuation marks, '''tab''', or a space are all characters. |
− | * valid and invalid declaration | + | #*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() |
− | * addition | + | #*String toUpperCase() |
− | * subtraction | + | #*String toLowerCase()<br/> |
− | * multiplication | + | #Primitive type conversions |
− | * division | + | #*define type conversion or type casting |
− | * modulo | + | #*higher order integer to lower order integer- Explicit type casting |
− | * simple program to demonstrate arithmetic operators | + | #*program to show explicit type casting |
− | * appropriate datatypes for appropriate values | + | #*common mistake in explicit type casting. |
− | * save, compile and run the program<br/> | + | #*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 | |
− | * char datatype | + | #*program to show char to int type casting. |
− | * letter, digit, punctuation marks, '''tab''', or a space are all characters. | + | #:<br> |
− | * Program explaining the variable and the character data. | + | #:'''Control flow''' |
− | * Introduction to strings | + | #Relational Operations |
− | * Creating string by Direct Initialization | + | #*boolean datatype |
− | * Creating string by using new operator | + | #*equal to and not equal to |
− | * String length() | + | #*less than and less than or equal to |
− | * String concat() | + | #*greater than and greater than or equal to<br/> |
− | * String toUpperCase() | + | #Logical Operations |
− | * String toLowerCase()<br/> | + | #*use of logical operators |
− | + | #*and (&&) operator | |
− | + | #*example to explain '''and''' operator | |
− | + | #*program to demonstrate '''and''' operator | |
− | + | #*or (||) operator | |
− | * define type conversion or type casting | + | #*example to explain '''or '''operator |
− | * higher order integer to lower order integer- Explicit type casting | + | #*program to demonstrate '''or '''operator |
− | * program to show explicit type casting | + | #*not (!) operator |
− | * common mistake in explicit type casting. | + | #*program to demonstrate '''or '''operator |
− | * program to show common mistake in explicit type casting | + | #*save, compile and run the programs<br/> |
− | + | #if else construct | |
− | * lower order integer to higher order integer – Implicit type casting | + | #*Conditional Statements and types of Conditional Statements |
− | * program to show implicit type casting | + | #*Use of if statement |
− | * char to integer | + | #*Syntax for if statement |
− | * integer to char | + | #*Program using if statement |
− | * program to show char to int type casting. | + | #*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<br/> |
− | * equal to and not equal to | + | #nested if and ternary operator |
− | * less than and less than or equal to | + | #*explain nested if |
− | * greater than and greater than or equal to<br/> | + | #*nested if syntax |
− | + | #*program to demonstrate nested if | |
− | + | #*explain the control flow of the program | |
− | + | #*explain ternary operator | |
− | + | #*syntax for ternary operator | |
− | * use of logical operators | + | #*explain the syntax |
− | * and (&&) operator | + | #*program to demonstrate ternary operator |
− | * example to explain '''and''' operator | + | #*comparison between ternary operator and nested if |
− | * program to demonstrate '''and''' operator | + | #*save, compile and run the program<br/> |
− | * or (||) operator | + | #switch statement |
− | * example to explain '''or '''operator | + | #*define switch case statement |
− | * program to demonstrate '''or '''operator | + | #*compare switch and nested if |
− | * not (!) operator | + | #*switch case syntax |
− | * program to demonstrate '''or '''operator | + | #*working of a switch case statement |
− | * save, compile and run the programs<br/> | + | #*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 | |
− | * Conditional Statements and types of Conditional Statements | + | #*save, compile and run the program to check the output |
− | * Use of if statement | + | #while loop |
− | * Syntax for if statement | + | #*Loop control statement |
− | * Program using if statement | + | #*types of loop control statements |
− | * Use of if else statement | + | #*Introduction to while loop |
− | * Syntax for if else statement | + | #*syntax of while loop |
− | * Program using if else statement | + | #*Program using while loop |
− | * Use of if else if statement | + | #*Check the output. |
− | * Syntax for if else if statement | + | #*Introduction to infinite loop |
− | * Program using if else if statement<br/> | + | #*loop variable modification |
− | + | #*Check the output | |
− | + | #*How to terminate the infinite loop<br/> | |
− | + | #for loop | |
− | + | #*syntax | |
− | * explain nested if | + | #*introduction to for loop |
− | * nested if syntax | + | #*for loop syntax |
− | * program to demonstrate nested if | + | #*loop vaiable |
− | * explain the control flow of the program | + | #*loop condition |
− | * explain ternary operator | + | #*loop variable increment or decrement |
− | * syntax for ternary operator | + | #* loop block |
− | * explain the syntax | + | #*flow of loop |
− | * program to demonstrate ternary operator | + | #*advantage of using loop |
− | * comparison between ternary operator and nested if | + | #do while loop |
− | * save, compile and run the program<br/> | + | #*define do while |
− | + | #*do while syntax | |
− | + | #*working of do while loop | |
− | + | #*example of do while loop | |
− | + | #*explain the do while programming | |
− | * define switch case statement | + | #*save, compile and run the program to check the output |
− | * compare switch and nested if | + | #*how different is it from the while loop |
− | * switch case syntax | + | #*program to demonstrate the differences |
− | * working of a switch case statement | + | #:<br> |
− | * use of keyword switch | + | #:'''Arrays''' |
− | * valid and invalid use of keyword '''case''' | + | #Introduction to Arrays |
− | * use of keyword default | + | #*About Arrays |
− | * use of keyword break | + | #*Declare an Array |
− | * program to demonstrate switch case statement | + | #*Initialize an array |
− | * save, compile and run the program to check the output | + | #*Intilalization using for loop |
− | + | #*Index of an array elements | |
− | + | #*change values of an array | |
− | + | #*print the value of an array | |
− | * Loop control statement | + | #*Advantage of an array. |
− | * types of loop control statements | + | #Array operations |
− | * Introduction to while loop | + | #*import java.util.Arrays |
− | * syntax of while loop | + | #*use methods from class Arrays |
− | * Program using while loop | + | #*toString() method |
− | * Check the output. | + | #*sort() method |
− | * Introduction to infinite loop | + | #*fill() method |
− | * loop variable modification | + | #*copyof() method |
− | * Check the output | + | #*copyofRange() method |
− | * How to terminate the infinite loop<br/> | + | #*about parameters for each method. |
− | + | #:'''Classes & Objects''' | |
− | + | #Creating class | |
− | + | #*Whatever we can see in this world are all objects | |
− | + | #*Objects can be categorized into groups known as class | |
− | * syntax | + | #*This is class in real world |
− | * loop | + | #*Human Being is an example of class in real world |
− | * loop variable | + | #*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<br/> | |
− | * define do while | + | #Creating Object |
− | * do while syntax | + | #*An object is an instance of a class |
− | * working of do while loop | + | #*Each object consist of state and behavior |
− | * example of do while loop | + | #*Object stores it state in fields or variables |
− | * explain the do while programming | + | #*It exposes its behavior through methods |
− | * save, compile and run the program to check the output | + | #*Reference variables |
− | * how different is it from the while loop | + | #*Create a class named TestStudent |
− | * program to demonstrate the differences | + | #*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 | |
− | + | #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 | |
− | + | #Methods | |
− | * Whatever we can see in this world are all objects | + | #*method definition |
− | * Objects can be categorized into groups known as class | + | #*write simple method |
− | * This is class in real world | + | #*method returning value |
− | * Human Being is an example of class in real world | + | #*call a method in another method |
− | * Class in java is the blue print from which individual objects are created | + | #*flow of the program |
− | * Class consists defines a set of properties called variables and a set of behaviors called methods | + | #*call a static method |
− | * Syntax for creating class | + | #*call a method from another class |
− | * Create a simple class Student using Eclipse | + | #*method signature |
− | * The Student class can contain properties<br/> | + | #*method body |
− | + | #:<br> | |
− | + | #:'''Constructors''' | |
− | + | #Default constructor | |
− | + | #*what is a constructor? | |
− | * An object is an instance of a class | + | #*what is a default constructor? |
− | * Each object consist of state and behavior | + | #*when is it called? |
− | * Object stores it state in fields or variables | + | #*define a constructor |
− | * It exposes its behavior through methods | + | #*initialize the variables |
− | * Reference variables | + | #*call the constructor |
− | * Create a class named TestStudent | + | #*difference between constructor and method<br/> |
− | * Create an object of the Student class | + | #Parameterized constructors |
− | * Use new operator | + | #*What is a parameterized constructor? |
− | * Check what the reference variable contains | + | #*create constructor without parameter |
− | * Create one more object of the Student class and check what the reference variable contains | + | #*create a constructor with parameter |
− | + | #*assign values to the variables in the constructor | |
− | + | #*pass arguments during the constructor call | |
− | + | #*working of parameterized constructor | |
− | * Also known as non-static fields | + | #*show common errors |
− | * Open the TestStudent class which we have created | + | #*resolve the errors |
− | * Access the fields roll_number and name using dot operator | + | #*create another parameterized constructor |
− | * See the output | + | #*why to use constructor? |
− | * Initialize the field and see the output | + | #Using this keyword |
− | * Change the modifier of the fields to private | + | #*this is a reference to the current object |
− | * Debug the error that you get | + | #*helps to avoid name conflicts |
− | * Change the modifier to protected | + | #*we can use this keyword inside a constructor to call another one |
− | * Each object of a class will have unique values | + | #*the constructors must be in the same class |
− | * Create two objects of the Student 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 | |
− | * method definition | + | #*this statement should be the first one inside a constructor |
− | * write simple method | + | #Non-static block |
− | * method returning value | + | #*Non-static block |
− | * call a method in another method | + | #*Any code written between two curly brackets |
− | * flow of the program | + | #*Executed for each object that is created |
− | * call a static method | + | #*Executes before constructor's execution |
− | * call a method from another class | + | #*can initialize instance member variables of the class |
− | * method signature | + | #*create a class named NonStaticTest |
− | * method body | + | #*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 | |
− | * what is a constructor? | + | #*Non-static block is not a substitute for constructor |
− | * what is a default constructor? | + | #Constructor Overloading |
− | * when is it called? | + | #*define multiple constructor |
− | * define a constructor | + | #*what is constructor overloading? |
− | * initialize the variables | + | #*constructor with different number of parameters. |
− | * call the constructor | + | #*parameters with different datatypes. |
− | * difference between constructor and method<br/> | + | #*how is constructor overloaded? |
− | + | #*flow of overloading process. | |
− | + | #*advantage of constructor overloading. | |
− | + | #Method Overloading | |
− | + | #*define multiple methods. | |
− | * What is a parameterized constructor? | + | #*methods with same name. |
− | * create constructor without parameter | + | #*methods with different number of parameters. |
− | * create a constructor with parameter | + | #*methods with different datatypes of parameter. |
− | * assign values to the variables in the constructor | + | #*what is method overloading? |
− | * pass arguments during the constructor call | + | #*example for overloadin method |
− | * working of parameterized constructor | + | #*how to overload method? |
− | * show common errors | + | #*advantage of method overloading. |
− | * resolve the errors | + | #*error in method overloading. |
− | * create another parameterized constructor | + | #Taking user input in Java |
− | * why to use constructor? | + | #*What is BufferedReader? |
− | + | #*Importing three classes from Java.io package | |
− | + | #*How to take the input from the user? | |
− | + | #*Syntax to implement BufferedReader | |
− | * this is a reference to the current object | + | #*What is InputStreamReader? |
− | * helps to avoid name conflicts | + | #*Create object of InputStreamReader |
− | * we can use this keyword inside a constructor to call another one | + | #*Create object of BufferedReader |
− | * the constructors must be in the same class | + | #*About IOException |
− | * explicit constructor invocation | + | #*About throws keyword |
− | * Explain it using the parameterized constructor code | + | #*Typecasting |
− | * Make this statement the last one in the constructor | + | |
− | * You will get an error | + | |
− | * this statement should be the first one inside a constructor | + | |
− | + | ||
− | + | ||
− | + | ||
− | * 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 | + | |
− | + | ||
− | + | ||
− | + | ||
− | * 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. | + | |
− | + | ||
− | + | ||
− | + | ||
− | * 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 | |
− | + | #*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 | ||
+ | #Exception Handling | ||
+ | #*What is an Exception | ||
+ | #*Types of Exceptions | ||
+ | ##Checked Exceptions | ||
+ | ##Unchecked Exceptions | ||
+ | #*Explaining ''ArrayIndexOutOfBoundsException'' | ||
+ | #*Demonstrating Checked Exceptions with example | ||
+ | #*Handling Exceptions using try-catch blocks | ||
+ | #*Explaining ''ArithmeticException'' | ||
+ | #*Demonstrating Unchecked Exceptions with example | ||
+ | #*Explaining ''FileNotFoundException'' | ||
+ | #*Usage of finally block | ||
+ | #*Explaining ''NullPointerException'' | ||
+ | #Custom Exceptions | ||
+ | #*What is a Custom Exception | ||
+ | #*Demonstration of custom exception | ||
+ | #*Custom exception example - "InvalidMarkException" | ||
+ | #*Usage of "throw" keyword | ||
+ | #*How to resolve errors in custom exceptions | ||
+ | #*Resolve error using "Add throws declaration" option | ||
+ | #*Usage of "throws" keyword | ||
+ | #*Example for "FileNotFoundException" | ||
+ | #*How to handle multiple exceptions | ||
+ | #*How to use "surround with try/catch" option |
Latest revision as of 15:33, 9 October 2020
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 Prathamesh Salunke, Arya Ratish, Ashwini Patil.
Learners: UG/PG CSE/IT/CS students.
Basic Level
- Introduction to Java
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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()
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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.
- 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
- 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
- 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
- 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
- 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
- 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
- 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?
- 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
- 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
- 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.
- 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.
- 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
- 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
- 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
- Exception Handling
- What is an Exception
- Types of Exceptions
- Checked Exceptions
- Unchecked Exceptions
- Explaining ArrayIndexOutOfBoundsException
- Demonstrating Checked Exceptions with example
- Handling Exceptions using try-catch blocks
- Explaining ArithmeticException
- Demonstrating Unchecked Exceptions with example
- Explaining FileNotFoundException
- Usage of finally block
- Explaining NullPointerException
- Custom Exceptions
- What is a Custom Exception
- Demonstration of custom exception
- Custom exception example - "InvalidMarkException"
- Usage of "throw" keyword
- How to resolve errors in custom exceptions
- Resolve error using "Add throws declaration" option
- Usage of "throws" keyword
- Example for "FileNotFoundException"
- How to handle multiple exceptions
- How to use "surround with try/catch" option
Contributors and Content Editors
Arya Ratish, Minal, Nancyvarkey, PoojaMoolya, Pratham920, Pratik kamble, Priyacst