9801 200 111 | info@neosphere.com.np
9801 200 111 | info@neosphere.com.np Application Fundamentals
9801 200 111 | info@neosphere.com.np Types of Software https://whatis.techtarget.com/definition/system-software System Software https://searchsoftwarequality.techtarget.com/definition/application Application Software Application Software Games, MS Office, Browser etc. System Software Operating System, Tools & Utilities, Compilers Hardware Disk, CPU, RAM
9801 200 111 | info@neosphere.com.np Types of Application Web Desktop Mobile ▪ Java ▪ .NET ▪ PHP ▪ Python ▪ Others ▪ Java ▪ .NET ▪ Python ▪ Others ▪ Android (java, Kotlin) ▪ iOS (Swift) L a n g u a g e s
9801 200 111 | info@neosphere.com.np We require database to store data
9801 200 111 | info@neosphere.com.np Driver We require JDBC (Java Database Connectivity) Driver to perform operation with Databases
9801 200 111 | info@neosphere.com.np It is intended to let application developers "write once, run anywhere" (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.
9801 200 111 | info@neosphere.com.np Java is Object Oriented
9801 200 111 | info@neosphere.com.np public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } Compile: javac filename.java Run: java ClassName
9801 200 111 | info@neosphere.com.np javac HelloWorld.java Compile: java HelloWorld Run:
9801 200 111 | info@neosphere.com.np This is the entry point of our Java program. the main method has to have this exact signature in order to be able to run our program. public again means that anyone can access it. static means that you can run this method without creating an instance of HelloWorld. void means that this method doesn't return any value. main is the name of the method.
9801 200 111 | info@neosphere.com.np • The HelloWorld.java file is known as source code file. • It is compiled by invoking tool named javac.exe, which compiles the source code into a .class file. • The .class file contains the bytecode which is interpreted by java.exe tool. • java.exe interprets the bytecode and runs the program.
9801 200 111 | info@neosphere.com.np Package in Java A package in Java is used to group related classes. Think of it as a folder in a file directory. We use packages to avoid name conflicts, and to write a better maintainable code. Packages are divided into two categories:
9801 200 111 | info@neosphere.com.np Java Packages • Built-in Packages (packages from the Java API) • User-defined Packages (create your own packages)
9801 200 111 | info@neosphere.com.np Importing packages import package.name.Class; // Import a single class import package.name.*; // Import the whole package
9801 200 111 | info@neosphere.com.np Scanner Class in Java import java.util.Scanner; class MyClass { public static void main(String[] args) { Scanner myObj = new Scanner(System.in); System.out.println("Enter username"); String userName = myObj.nextLine(); System.out.println("Username is: " + userName); } }
9801 200 111 | info@neosphere.com.np To import a whole package, end the statement with an asterisk sign (*). import java.util.*;
9801 200 111 | info@neosphere.com.np Methods in Java • A method is a block of code which only runs when it is called. • You can pass data, known as parameters, into a method.
9801 200 111 | info@neosphere.com.np modifier returnType nameOfMethod (Parameter List) { // method body }
9801 200 111 | info@neosphere.com.np Variables and Types Although Java is object oriented, not all types are objects. It is built on top of basic variable types called primitives. List of all primitives in Java: byte (number, 1 byte) short (number, 2 bytes) int (number, 4 bytes) long (number, 8 bytes) float (float number, 4 bytes) double (float number, 8 bytes) char (a character, 2 bytes) boolean (true or false, 1 byte)
9801 200 111 | info@neosphere.com.np Java is a strong typed language, which means variables need to be defined before we use them. int myNumber; myNumber = 5;
9801 200 111 | info@neosphere.com.np String is not a primitive. It's a real type, but Java has special treatment for String. // Create a string with a constructor String s1 = new String("Who let the dogs out?"); // Just using "" creates a string, so no need to write it the previous way. String s2 = "Who who who who!"; // Java defined the operator + on strings to concatenate: String s3 = s1 + s2; int num = 5; String s = "I have " + num + " cookies"; //Be sure not to use "" with primitives. Can also concat string to primitives:
9801 200 111 | info@neosphere.com.np Operator Operator in java is a symbol that is used to perform operations
9801 200 111 | info@neosphere.com.np Operator Precedence Operators Precedence postfix expr++ expr-- unary ++expr --expr +expr -expr ~ ! multiplicative * / % additive + - shift << >> >>> relational < > <= >= instanceof equality == != bitwise AND & bitwise exclusive OR ^ bitwise inclusive OR | logical AND && logical OR || ternary ? : assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
9801 200 111 | info@neosphere.com.np Simple Assignment Operator =
9801 200 111 | info@neosphere.com.np Arithmetic Operators + Additive operator (also used for String concatenation) - Subtraction operator * Multiplication operator / Division operator % Remainder operator
9801 200 111 | info@neosphere.com.np Unary Operators + Unary plus operator; indicates positive value (numbers are positive without this, however) - Unary minus operator; negates an expression ++ Increment operator; increments a value by 1 -- Decrement operator; decrements a value by 1 ! Logical complement operator; inverts the value of a boolean
9801 200 111 | info@neosphere.com.np Equality and Relational Operators == Equal to != Not equal to > Greater than >= Greater than or equal to < Less than <= Less than or equal to
9801 200 111 | info@neosphere.com.np && Conditional-AND || Conditional-OR ?: Ternary (shorthand for if-then-else statement)
9801 200 111 | info@neosphere.com.np Bitwise and Bit Shift Operators ~ Unary bitwise complement << Signed left shift >> Signed right shift >>> Unsigned right shift & Bitwise AND ^ Bitwise exclusive OR | Bitwise inclusive OR
9801 200 111 | info@neosphere.com.np Conditionals Java uses boolean variables to evaluate conditions. The boolean values true and false are returned when an expression is compared or evaluated. For example: int a = 4; boolean b = a == 4; if (b) { System.out.println("It's true!"); }
9801 200 111 | info@neosphere.com.np The if-then Statement The if-then statement is the most basic of all the control flow statements void applyBrakes() { // the "if" clause: bicycle must be moving if (isMoving){ // the "then" clause: decrease current speed currentSpeed--; } }
9801 200 111 | info@neosphere.com.np If this test evaluates to false (meaning that the bicycle is not in motion), control jumps to the end of the if-then statement. void applyBrakes() { // the "if" clause: bicycle must be moving if (isMoving){ // the "then" clause: decrease current speed currentSpeed--; } }
9801 200 111 | info@neosphere.com.np The if-then-else Statement void applyBrakes() { if (isMoving) { currentSpeed--; } else { System.err.println("The bicycle has already stopped!"); } }
9801 200 111 | info@neosphere.com.np class IfElseDemo { public static void main(String[] args) { int testscore = 76; char grade; if (testscore >= 90) { grade = 'A'; } else if (testscore >= 80) { grade = 'B'; } else if (testscore >= 70) { grade = 'C'; } else if (testscore >= 60) { grade = 'D'; } else { grade = 'F'; } System.out.println("Grade = " + grade); } }
9801 200 111 | info@neosphere.com.np The switch Statement A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types (discussed in Enum Types), the String class, and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer
9801 200 111 | info@neosphere.com.np public class SwitchDemo { public static void main(String[] args) { int month = 8; String monthString; switch (month) { case 1: monthString = "January"; break; case 2: monthString = "February"; break; case 3: monthString = "March"; break; case 4: monthString = "April"; break;
9801 200 111 | info@neosphere.com.np case 5: monthString = "May"; break; case 6: monthString = "June"; break; case 7: monthString = "July"; break; case 8: monthString = "August"; break; case 9: monthString = "September"; break; case 10: monthString = "October"; break; case 11: monthString = "November"; break; case 12: monthString = "December"; break; default: monthString = "Invalid month"; break; } System.out.println(monthString); }
9801 200 111 | info@neosphere.com.np • The body of a switch statement is known as a switch block. • A statement in the switch block can be labeled with one or more case or default labels. • The switch statement evaluates its expression, then executes all statements that follow the matching case label.
9801 200 111 | info@neosphere.com.np The while and do-while Statements The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as: while (expression) { statement(s) }
9801 200 111 | info@neosphere.com.np The while statement evaluates expression, which must return a boolean value.
9801 200 111 | info@neosphere.com.np class WhileDemo { public static void main(String[] args){ int count = 1; while (count < 11) { System.out.println("Count is: " + count); count++; } } }
9801 200 111 | info@neosphere.com.np Do…while class DoWhileDemo { public static void main(String[] args){ int count = 1; do { System.out.println("Count is: " + count); count++; } while (count < 11); } }
9801 200 111 | info@neosphere.com.np The for Statement The for statement provides a compact way to iterate over a range of values. Programmers often refer to it as the "for loop" because of the way in which it repeatedly loops until a particular condition is satisfied.
9801 200 111 | info@neosphere.com.np for (initialization; termination; increment) { statement(s) }
9801 200 111 | info@neosphere.com.np class ForDemo { public static void main(String[] args){ for(int i=1; i<11; i++){ System.out.println("Count is: " + i); } } }
9801 200 111 | info@neosphere.com.np Enhanced for class EnhancedForDemo { public static void main(String[] args){ int[] numbers = {1,2,3,4,5,6,7,8,9,10}; for (int item : numbers) { System.out.println("Count is: " + item); } } }

Java Programming Workshop

  • 1.
    9801 200 111| info@neosphere.com.np
  • 2.
    9801 200 111| info@neosphere.com.np Application Fundamentals
  • 3.
    9801 200 111| info@neosphere.com.np Types of Software https://whatis.techtarget.com/definition/system-software System Software https://searchsoftwarequality.techtarget.com/definition/application Application Software Application Software Games, MS Office, Browser etc. System Software Operating System, Tools & Utilities, Compilers Hardware Disk, CPU, RAM
  • 4.
    9801 200 111| info@neosphere.com.np Types of Application Web Desktop Mobile ▪ Java ▪ .NET ▪ PHP ▪ Python ▪ Others ▪ Java ▪ .NET ▪ Python ▪ Others ▪ Android (java, Kotlin) ▪ iOS (Swift) L a n g u a g e s
  • 5.
    9801 200 111| info@neosphere.com.np We require database to store data
  • 6.
    9801 200 111| info@neosphere.com.np Driver We require JDBC (Java Database Connectivity) Driver to perform operation with Databases
  • 7.
    9801 200 111| info@neosphere.com.np It is intended to let application developers "write once, run anywhere" (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.
  • 8.
    9801 200 111| info@neosphere.com.np Java is Object Oriented
  • 9.
    9801 200 111| info@neosphere.com.np public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } Compile: javac filename.java Run: java ClassName
  • 10.
    9801 200 111| info@neosphere.com.np javac HelloWorld.java Compile: java HelloWorld Run:
  • 11.
    9801 200 111| info@neosphere.com.np This is the entry point of our Java program. the main method has to have this exact signature in order to be able to run our program. public again means that anyone can access it. static means that you can run this method without creating an instance of HelloWorld. void means that this method doesn't return any value. main is the name of the method.
  • 12.
    9801 200 111| info@neosphere.com.np • The HelloWorld.java file is known as source code file. • It is compiled by invoking tool named javac.exe, which compiles the source code into a .class file. • The .class file contains the bytecode which is interpreted by java.exe tool. • java.exe interprets the bytecode and runs the program.
  • 13.
    9801 200 111| info@neosphere.com.np Package in Java A package in Java is used to group related classes. Think of it as a folder in a file directory. We use packages to avoid name conflicts, and to write a better maintainable code. Packages are divided into two categories:
  • 14.
    9801 200 111| info@neosphere.com.np Java Packages • Built-in Packages (packages from the Java API) • User-defined Packages (create your own packages)
  • 15.
    9801 200 111| info@neosphere.com.np Importing packages import package.name.Class; // Import a single class import package.name.*; // Import the whole package
  • 16.
    9801 200 111| info@neosphere.com.np Scanner Class in Java import java.util.Scanner; class MyClass { public static void main(String[] args) { Scanner myObj = new Scanner(System.in); System.out.println("Enter username"); String userName = myObj.nextLine(); System.out.println("Username is: " + userName); } }
  • 17.
    9801 200 111| info@neosphere.com.np To import a whole package, end the statement with an asterisk sign (*). import java.util.*;
  • 18.
    9801 200 111| info@neosphere.com.np Methods in Java • A method is a block of code which only runs when it is called. • You can pass data, known as parameters, into a method.
  • 19.
    9801 200 111| info@neosphere.com.np modifier returnType nameOfMethod (Parameter List) { // method body }
  • 20.
    9801 200 111| info@neosphere.com.np Variables and Types Although Java is object oriented, not all types are objects. It is built on top of basic variable types called primitives. List of all primitives in Java: byte (number, 1 byte) short (number, 2 bytes) int (number, 4 bytes) long (number, 8 bytes) float (float number, 4 bytes) double (float number, 8 bytes) char (a character, 2 bytes) boolean (true or false, 1 byte)
  • 21.
    9801 200 111| info@neosphere.com.np Java is a strong typed language, which means variables need to be defined before we use them. int myNumber; myNumber = 5;
  • 22.
    9801 200 111| info@neosphere.com.np String is not a primitive. It's a real type, but Java has special treatment for String. // Create a string with a constructor String s1 = new String("Who let the dogs out?"); // Just using "" creates a string, so no need to write it the previous way. String s2 = "Who who who who!"; // Java defined the operator + on strings to concatenate: String s3 = s1 + s2; int num = 5; String s = "I have " + num + " cookies"; //Be sure not to use "" with primitives. Can also concat string to primitives:
  • 23.
    9801 200 111| info@neosphere.com.np Operator Operator in java is a symbol that is used to perform operations
  • 24.
    9801 200 111| info@neosphere.com.np Operator Precedence Operators Precedence postfix expr++ expr-- unary ++expr --expr +expr -expr ~ ! multiplicative * / % additive + - shift << >> >>> relational < > <= >= instanceof equality == != bitwise AND & bitwise exclusive OR ^ bitwise inclusive OR | logical AND && logical OR || ternary ? : assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
  • 25.
    9801 200 111| info@neosphere.com.np Simple Assignment Operator =
  • 26.
    9801 200 111| info@neosphere.com.np Arithmetic Operators + Additive operator (also used for String concatenation) - Subtraction operator * Multiplication operator / Division operator % Remainder operator
  • 27.
    9801 200 111| info@neosphere.com.np Unary Operators + Unary plus operator; indicates positive value (numbers are positive without this, however) - Unary minus operator; negates an expression ++ Increment operator; increments a value by 1 -- Decrement operator; decrements a value by 1 ! Logical complement operator; inverts the value of a boolean
  • 28.
    9801 200 111| info@neosphere.com.np Equality and Relational Operators == Equal to != Not equal to > Greater than >= Greater than or equal to < Less than <= Less than or equal to
  • 29.
    9801 200 111| info@neosphere.com.np && Conditional-AND || Conditional-OR ?: Ternary (shorthand for if-then-else statement)
  • 30.
    9801 200 111| info@neosphere.com.np Bitwise and Bit Shift Operators ~ Unary bitwise complement << Signed left shift >> Signed right shift >>> Unsigned right shift & Bitwise AND ^ Bitwise exclusive OR | Bitwise inclusive OR
  • 31.
    9801 200 111| info@neosphere.com.np Conditionals Java uses boolean variables to evaluate conditions. The boolean values true and false are returned when an expression is compared or evaluated. For example: int a = 4; boolean b = a == 4; if (b) { System.out.println("It's true!"); }
  • 32.
    9801 200 111| info@neosphere.com.np The if-then Statement The if-then statement is the most basic of all the control flow statements void applyBrakes() { // the "if" clause: bicycle must be moving if (isMoving){ // the "then" clause: decrease current speed currentSpeed--; } }
  • 33.
    9801 200 111| info@neosphere.com.np If this test evaluates to false (meaning that the bicycle is not in motion), control jumps to the end of the if-then statement. void applyBrakes() { // the "if" clause: bicycle must be moving if (isMoving){ // the "then" clause: decrease current speed currentSpeed--; } }
  • 34.
    9801 200 111| info@neosphere.com.np The if-then-else Statement void applyBrakes() { if (isMoving) { currentSpeed--; } else { System.err.println("The bicycle has already stopped!"); } }
  • 35.
    9801 200 111| info@neosphere.com.np class IfElseDemo { public static void main(String[] args) { int testscore = 76; char grade; if (testscore >= 90) { grade = 'A'; } else if (testscore >= 80) { grade = 'B'; } else if (testscore >= 70) { grade = 'C'; } else if (testscore >= 60) { grade = 'D'; } else { grade = 'F'; } System.out.println("Grade = " + grade); } }
  • 36.
    9801 200 111| info@neosphere.com.np The switch Statement A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types (discussed in Enum Types), the String class, and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer
  • 37.
    9801 200 111| info@neosphere.com.np public class SwitchDemo { public static void main(String[] args) { int month = 8; String monthString; switch (month) { case 1: monthString = "January"; break; case 2: monthString = "February"; break; case 3: monthString = "March"; break; case 4: monthString = "April"; break;
  • 38.
    9801 200 111| info@neosphere.com.np case 5: monthString = "May"; break; case 6: monthString = "June"; break; case 7: monthString = "July"; break; case 8: monthString = "August"; break; case 9: monthString = "September"; break; case 10: monthString = "October"; break; case 11: monthString = "November"; break; case 12: monthString = "December"; break; default: monthString = "Invalid month"; break; } System.out.println(monthString); }
  • 39.
    9801 200 111| info@neosphere.com.np • The body of a switch statement is known as a switch block. • A statement in the switch block can be labeled with one or more case or default labels. • The switch statement evaluates its expression, then executes all statements that follow the matching case label.
  • 40.
    9801 200 111| info@neosphere.com.np The while and do-while Statements The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as: while (expression) { statement(s) }
  • 41.
    9801 200 111| info@neosphere.com.np The while statement evaluates expression, which must return a boolean value.
  • 42.
    9801 200 111| info@neosphere.com.np class WhileDemo { public static void main(String[] args){ int count = 1; while (count < 11) { System.out.println("Count is: " + count); count++; } } }
  • 43.
    9801 200 111| info@neosphere.com.np Do…while class DoWhileDemo { public static void main(String[] args){ int count = 1; do { System.out.println("Count is: " + count); count++; } while (count < 11); } }
  • 44.
    9801 200 111| info@neosphere.com.np The for Statement The for statement provides a compact way to iterate over a range of values. Programmers often refer to it as the "for loop" because of the way in which it repeatedly loops until a particular condition is satisfied.
  • 45.
    9801 200 111| info@neosphere.com.np for (initialization; termination; increment) { statement(s) }
  • 46.
    9801 200 111| info@neosphere.com.np class ForDemo { public static void main(String[] args){ for(int i=1; i<11; i++){ System.out.println("Count is: " + i); } } }
  • 47.
    9801 200 111| info@neosphere.com.np Enhanced for class EnhancedForDemo { public static void main(String[] args){ int[] numbers = {1,2,3,4,5,6,7,8,9,10}; for (int item : numbers) { System.out.println("Count is: " + item); } } }