Java – Introduction
Introduction: Java distributions: Java is a platform independent language: Java is an Object-Oriented language: Multithreading:
Introduction: Java distributions: Java is a platform independent language: Java is an Object-Oriented language: Multithreading:
JDK Components to Edit, Compile and Run Java Application: IDE: (Integrated Development Environment)
Installing JDK: Click on run button once download completes:
Java API Documentation: Search “java api” in Google: The Website providing complete information of java library about packages, classes, interface, methods, variables etc.,
Java application structure: How to Compile and Run Java program from command Prompt? Code.java: public class Code{ public static void main(String[] args) { System.out.println(“Hello World!”); }} Command Prompt as follows:
Naming conventions: Class: Every word in identity starts with capital letter. Spaces not allowed StringPrintStreamNullPointerExceptionFileNotFoundExceptionArrayIndexOutOfBoundsException Method: First word starts with Lower Case and From Second word, every word starts with capital letters. No spaces allowed. main( )getName( )getAccountHolderNumber( ) Variable: First word starts with Lower Case and From Second word, every word starts with capital …
Variable: Definition1: Variable is an identity given to memory location. Definition2: Variable is a named memory location Syntax:datatype identity = value; Examples: String name = “Amar”; int age = 23; char gender = ‘M’; boolean married = false; double salary = 35000.00; Declaration, Assignment, Update and Initialization of Variable: Identifier rules: Rules to create identifier:
Data type: Syntax: Example: Data types classified into Primitive and Non-Primitive types. Limits: Integer types: We have 4 integer types among eight available primitive types in java. Type Size(bytes) Limits byte 1 -128(-2^7) to +127(2^7-1) short 2 -32,768(-2^15) to 32,767(2^15-1) int 4 -2,147,483,648(-2^31) to 2,147,483,647(2^31-1) long 8 -9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807(2^63-1) Note: Program to print sizes …
Find the average of two numbers: public class Practice{ public static void main(String[] args) { int num1= 5 , num2 = 3; int avg = (num1+num2)/2; System.out.println(“Average : ” + avg); }} Find the Sum of Square and Cube of a Number: public class Practice{ public static void main(String[] args) { int a = 5; …
Type casting: Convert Character to Integer: this conversion happens implicitly when we assign character to integer type. class Code{ public static void main(String[] args) { char ch = ‘A’ ; int x = ch ; System.out.println(“x value : ” + x); }} Convert Integer to Character: this conversion must be done manually class Code{ public …