Core-Java-by-Mahika-Tutor.9459891.powerpoint.pptx

NagarathnaRajur2 13 views 49 slides Sep 27, 2024
Slide 1
Slide 1 of 49
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49

About This Presentation

GFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


Slide Content

checked exception Core Java

[email protected] Programming Languages High Level Languages (Machine independent) Low-Level Languages (Machine dependent) Assembly language Machine(Binary) language

Java Java was created by James Gosling at Sun Microsystems (which is now acquired by Oracle Corporation) and released in 1995. Java is a high level , object-oriented programming language.

OOPs Concepts

Encapsulation Binding (or wrapping) code and data together into a single unit. A java class is the example of encapsulation.

Abstraction Hiding internal details and showing functionality only. With Abstraction WithoutAbstraction

Inheritance A mechanism by which a class acquires all the properties and behaviours of an existing class. Provides code reusability . Used to achieve runtime polymorphism.

Polymorphism Ability to take multiple forms. Example- int a=10,b=20,c; c=a+b; //addition String firstname=“Sachin”, lastname=“Tendulkar”, fullname; fullname=firstname+lastname;//concatenation

OOPLs (Four OOPs features) Partial OOPL Pure OOPL Fully OOPL Classes not mandatory. Data members and methods can be given outside class. e.g. C++ Classes mandatory. Data members and methods cannot be given outside class. e.g. Java Classes mandatory. Data members and methods cannot be given outside class. Primitive data types not supported. e.g. Smalltalk Java supports primitive data types , hence it is a fully OOPL but not pure OOPL. int i=20; //primitive type Integer a=new Integer(20); //Class type

Core Java

Java Version History JDK Alpha and Beta (1995) JDK 1.0 (23rd Jan, 1996) JDK 1.1 (19th Feb, 1997) J2SE 1.2 (8th Dec, 1998) J2SE 1.3 (8th May, 2000) J2SE 1.4 (6th Feb, 2002) J2SE 5.0 (30th Sep, 2004) Java SE 6 (11th Dec, 2006) Java SE 7 (28th July, 2011) Java SE 8 (18th March, 2014) Java SE 9 (September 2017)

Signature of main()

public static void main(String[] args) { ………….. ………….. }

returnType methodName(arguments) { …… } void m1() { ….. ….. } int m2() { ….. return 2; } int m3(int n) { ….. return n*n; }

public static void main(String[] args) { ………….. ………….. }

class Test { public static void myStatic() { ----- ----- ----- } public void myNonStatic() { ----- } } class Sample { public void CallerFunction() { // Invoking static function Test.myStatic(); // Invoking non-static function Test t= new Test(); t.myNonStatic(); } } Invoking Member Funtions Of A Class

class Test { public static void main(String[] args ) { ----- ----- ----- } } // Incase of static main() Test.main(); Invoking main() Since the main method is static Java virtual Machine can call it without creating any instance of a class which contains the main method. // Incase of non-static main() Test t=new Test() t.main();

Thank You

Secured Java is secured because: No explicit pointer Java Programs run inside virtual machine sandbox Exception handling concept

Valid java main method signature public   static   void  main(String[]  args )   public   static   void  main(String [] args )   public   static   void  main(String  args [])   public   static   void  main(String...  args )   static   public   void  main(String[]  args )   public   static   final   void  main(String[]  args )   final   public   static   void  main(String[]  args )   final   strictfp   public   static   void  main(String[]  args )  

Java Code (.java) JAVAC Compiler Byte Code (.class) JVM JVM JVM Linux Mac Windows

JVM JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed. JVM is the engine that drives the java code The JVM performs following main tasks: Loads code Verifies code Executes code

JRE JRE is an acronym for Java Runtime Environment . JRE JVM Llibraries like rt.jar Other files

JRE JVM Llibraries like rt.jar Other files Development tools like javac, java etc. JDK JDK JDK is an acronym for Java Development Kit. Includes a complete JRE (Java Runtime Environment) plus tools for developing, debugging, and monitoring Java applications. 

Internal Architecture of JVM Java Runtime System Class Loader Class Area Heap Stack PC Register Native Method Stack Execution engine Native Method Interface Java Native Libraries Memory areas allocated by JVM

Internal Architecture of JVM Java Runtime System Class Loader Class Area Heap Stack PC Register Native Method Stack Execution engine Native Method Interface Java Native Libraries Memory areas allocated by JVM

Java Keywords Words that cannot be used as identifiers in programs. There are 50 java keywords. All keywords are in lower-case. Each keyword has special meaning for the compiler. Keywords that are not used in Java so far are called reserved words.

Category Keywords Access modifiers private, protected, public Class, method, variable modifiers abstract, class, extends, final, implements, interface, native,new, static,  strictfp, synchronized, transient, volatile Flow control break, case, continue, default, do, else, for, if, instanceof,return, switch, while Package control import, package Primitive types boolean, byte, char, double, float, int, long, short Exception handling assert, catch, finally, throw, throws, try Enumeration enum Others super, this, void Unused const, goto Points to remember const  and  goto   are resevered words. true ,  false  and  null  are literals, not keywords. List of Java Keywords

Rules for Naming Java Identifiers Allowed characters for identifiers are[A-Z], [a-z],[0-9], ‘$‘(dollar sign) and ‘_‘ (underscore). Should not start with digits(0-9). Case-sensitive, like id and ID are different. Java keyword cannot be used as an identifier. Java Identifiers Names given to programming elements like variables, methods, classes, packages and interfaces.

Java Naming conventions Name Convention class name should start with uppercase letter and be a noun e.g.Shape, String, Color, System, Thread etc. interface name should start with uppercase letter and be an adjective e.g. Runnable, Clonable etc. method name should start with lowercase letter and be a verb e.g. compute(), print(), println() etc. variable name should start with lowercase letter e.g. firstName, lastName etc. package name should be in lowercase letter e.g. java, lang, sql, util etc. constants name should be in uppercase letter . e.g. BLUE, MAX_PRIORITY etc.

Core Java

Class A template that describes the data and behavior. Object An entity that has state and behavior is known as an object e.g. chair, bike, table, car etc. state:  represents data (value) of an object. behavior:  represents the functionality of an object such as deposit, withdraw etc.

Student Data members id name Methods setId() setName() getId() getName() class

public class Student { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } Java class example

Instantiation/ Object Creation- Classname referenceVariable=new Classname(); e.g.- Student s=new Student(); Method Invocation/Call- Non-static method: referenceVariable.methodname(); e.g.- s.show(); static method: Classname.methodname(); e.g.- Sample.display();

Scanner class A class in java.util package Used for obtaining the input of the primitive types like int, double etc. and strings Breaks its input into tokens using a delimiter pattern, which by default matches whitespace.  To create an object of Scanner class, we usually pass the predefined object System.in, which represents the standard input stream. We may pass an object of class File if we want to read input from a file.

Creating instance of Scanner class To read from System.in: Scanner sc = new Scanner(System.in); To read from File: Scanner sc = new Scanner(new File("myFile"));

Commonly used methods of Scanner class Method Description public String next() it returns the next token from the scanner. public byte nextByte() it scans the next token as a byte. public short nextShort() it scans the next token as a short value. public int nextInt() it scans the next token as an int value. public long nextLong() it scans the next token as a long value. public float nextFloat() it scans the next token as a float value. public double nextDouble() it scans the next token as a double value.

Thank You

Types of Variable local instance static

public class Student { int rn; //instance variable String name; //instance variable static String college; //static variable void m1() { int l; //local variable …… } ………. }

i d=1 name= Hriday Stack Heap i d=2 name= Anil s1 s2 college=“SVC” ” Class Area class  Student{     int  id;     String name;  static String college=“SVC”;      ………   public   static   void  main(String args[]){      Student s1= new  Student();      Student s2= new  Student();   ………… } }

Thank You

class  Student{      int  id;     String name;        void   insertRecord ( int  i,  String n){  //method      id=i;       name=n;    }        void   displayInformation () {System.out.println(id+"  "+name);}//method        public   static   void  main(String  args []){      Student  s1= new  Student();       Student  s2= new  Student();          s1.insertRecord(1,“Hriday");       s2.insertRecord(2,“Anil");         s1.displayInformation();     s2.displayInformation();       }   }   i d=1 name= Hriday Stack Heap i d=2 name= Anil s1 s2

Data Type Default Value Default size boolean false 1 bit char '\u0000' 2 byte byte 1 byte short 2 byte int 4 byte long 0L 8 byte float 0.0f 4 byte double 0.0d 8 byte lowest unicode value: \u0000 highest unicode value: \ uFFFF

Operators Assignment Operator =   Arithmetic Operators - + * / % ++ --   Relational Operators > < >= <= == !=   Logical Operators && || ! Compound Assignment Operators += -= *= /= %=   Conditional Operator ?:

Control Structures Conditional Simple if if–else if-else-if ladder Nested if switch case Looping while loop for loop do while loop for each/enhanced for loop

if Statement: if (condition){   //code to be executed   }  

if –else Statement: if (condition){   //code if condition is true   } else {   //code if condition is false   }  
Tags