1 / 28

CORE JAVA BY PSK TECHNOLOGIES PVT LTD NAGPUR

PSK Technologies is a training institute that provides best training on java course in Nagpur.<br>In PSK Technologies,candidates will be getting industrial level of training on java.Core and advanced java training are available at PSK Technologies.Real time examples with each and every topic of the classes will be provided.<br>To attend free demo classes, contact on 9970141466<br>else visit http://pskitservies.com for complete details on java training center in Nagpur

Download Presentation

CORE JAVA BY PSK TECHNOLOGIES PVT LTD NAGPUR

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CORE JAVA • PSK TECHNOLOGIES • An ISO 9001:2015 (QMS) Certified IT Company Computer Education | Software Development |Computer Sales & Services • Plot No-780, Near Durga Temple, • KatolRoad Chaoni, Nagpur-13 • Phone: 9975288300 / 9970141466 • Email: info@psktechnologies.co.in • website: www.pskitservices.com

  2. CONTENT • Constructor • Static variable • This Keywords • Inheritance • Abstraction & Interface Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  3. Constructor A constructor is a ‘special’ member function whose task is to initialize the objects of its class. It is special because its name is the same as the class name. The constructor is invoked whenever an object of its associated class is created. It is called constructor because it construct the values of data member of the class. A constructor is declared and defined as follows: //class with a constructor Class integer { intm,n; Public: integer (void); //constructor declared ……. ……. }; Integer:: integer (void) //constructor defined { m= 0; n= 0; } Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  4. When a class contains a constructor like the one defined above, it is guaranteed that an object created by the class will be initialized automatically. For example, the declaration Integer int1; // object int1 created. Not only created the object int1 of the integer but also initializes its data member’s m and n to zero. There is no need to write any statement to invoke. the constructor function (as we do with the normal member function). If a ‘normal’ member function is defined for zero initialization, we would need to invoke this function for each of the objects separately. This would be very inconvenient, if there are a larger number of objects. A constructor that accepts no parameters is called the default constructor. The default constructor for class A is A::A (). If no such constructor is defined, then the compiler supplies a default constructor. Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  5. Program: class Student4 { int id; String name; Student4(inti,String n) { id = i; name = n; } void display() { System.out.println("Id="+id+"\t"+"Name="+name); } public static void main(String args[]) { Student4 s1 = new Student4(111,"Karan"); Student4 s2 = new Student4(222,"Aryan"); s1.display(); s2.display(); } } Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  6. Program: Constructor overloading class Student5 { int id; String name; int age; Student5(inti,String n) { id = i; name = n; } Student5(inti,Stringn,int a) { id = i; name = n; age=a; } void display() { System.out.println(id+" "+name+" "+age); } public static void main(String args[]) { Student5 s1 = new Student5(111,"Karan"); Student5 s2 = new Student5(222,"Aryan",25); s1.display(); s2.display(); } } Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  7. Copy Constructor Java Copy Constructor There is no copy constructor in java. But, we can copy the values of one object to another like copy constructor in C++. There are many ways to copy the values of one object into another in java. They are: • By constructor • By assigning the values of one object into another • By clone() method of Object class*/ Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  8. Program: class Student6 { int id; String name; Student6(inti,String n) { id = i; name = n; } Student6(Student6 s) { id = s.id; name =s.name; } void display() { System.out.println(id+" "+name); } public static void main(String args[]) { Student6 s1 = new Student6(111,"Karan"); Student6 s2 = new Student6(s1); s1.display(); s2.display(); } } Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  9. STATIC VARIABLE • Static Member Function 1)Like static member variable we can also have static member function. 2) A static function can have access to only other static member (function or variable) declared in same class. 3) A static member function can be called using the class name. class_name :: function_name; When counter () function is called and gets destroyed each time when counter () function ends.But, if we makes it static, once initialized count will have a scope till the end of main () function and it will carry, its value through function calls too. If you don’t initialized a static variable, they are by default initialized to zero. Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  10. Program: class Counter2 { static int count; //will get memory only once and retain its value Counter2() { count++; System.out.println(count); } /*void display() { System.out.println("\n\n\n"+count); }*/ public static void main(String args[]) { Counter2 c1=new Counter2(); Counter2 c2=new Counter2(); Counter2 c3=new Counter2(); /*c1.display(); c2.display(); c3.display();*/ } } Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  11. Java static block: Is used to initialize the static data member. 2) It is executed before main method at the time of class loading class A2 { static { System.out.println("static block is invoked"); } public static void main(String args[]) { System.out.println("Hello main"); }} • Why Java Main Method Is Static? Because object is not required to call static method if it were non-static method, jvmcreate object first then call main() method that will lead the problem of extra memory allocation. Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  12. THIS KEYWORD • Definition of This To refer the current class instance variable to invoke the current class constructor to invoke the current class method to pass as an argument in the method call to pass as an argument in the constructor call to return the current class instance proving this keyword there can be a lot of usage of java this keyword. In java, this is a reference variable that refers to the current object. • Using ‘this ‘keyword Here is given the 6 usage of java this keyword. 1.this keyword can be used to refer current class instance variable. 2.this() can be used to invoke current class constructor. 3.this keyword can be used to invoke current class method (implicitly) 4.this can be passed as an argument in the method call. 5.this can be passed as argument in the constructor call. 6.this keyword can also be used to return the current class instance Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  13. Program: class This1 { int id; String name; This1(intid,String name) { this.id = id; this.name = name; } void display() { System.out.println(id+" "+name); } public static void main(String args[]) { This1 s1 = new This1(11,"Karan"); This1 s2 = new This1(22,"Aryan"); s1.display(); s2.display(); } } Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  14. Program: • class ThisCon • {intid; • String name; • ThisCon() • {System.out.println("default constructor • is invoked"); • ThisCon(intid,String name) • { • this (); • //it is used to invoked current class constructor. • this.id = id; • this.name = name; • } • void display() • { • System.out.println(id+" "+name); • } • public static void main(String args[]) • { • ThisCon e3 = new ThisCon(); • ThisCon e1 = new ThisCon(111,"karan"); • ThisCon e2 = new ThisCon(222,"Aryan"); • e1.display(); • e2.display(); • } • } • Constructor Call Using ‘This’ This() can be used to invoked current class constructor. The this() constructor call can be used to invoke the current class constructor (constructor chaining). This approach is better if you have many constructors in the class and want to reuse that constructor. Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  15. Program: This keyword refers to the current class instance variable. In this program, we are printing the reference variable and this, output of both variables are same class A5 { void m() { System.out.println(this);//prints same reference ID } public static void main(String args[]) { A5 obj=new A5(); //System.out.println(obj); //prints the reference ID obj. m(); } } Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  16. Inheritance Why multiple inheritance is not in java. • Program: class A { A() { System.out.println("A constructor called"); System.out.println("asd"); } } class B extends A { B() { System.out.println("B constructor called"); } } class Inh1 { public static void main(String[] args) { B b=new B(); } } Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  17. Program: class A { inta,b; void getA(intx,int y) { a=x; b=y; System.out.println("Super Add="+(a+b)); } } class B extends A { intm,n; void getB(intt,ints,intp,int q) { super.getA(t,s); m=p; n=q; System.out.println("Sub Add="+(m+n)); } } class Inh3 { public static void main(String[] args) { B b=new B(); b.getB(1,2,3,4); } } Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  18. Abstraction & Interface • Abstract class in Java A class that is declared with abstract keyword, is known as abstract class in java. It can have abstract and non-abstract methods (method with body).Before learning java abstract class, let's understand the abstraction in java first. • Abstraction in Java Abstraction is a process of hiding the implementation details and showing only functionality to the user. Another way, it shows only important things to the user and hides the internal details for example sending sms, you just type the text and send the message. You don't know the internal processing about the message delivery. Abstraction lets you focus on what the object does instead of how it does it. • Ways to achieve Abstraction There are two ways to achieve abstraction in java Abstract class (0 to 100%) Interface (100%) Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  19. Program: abstract class Bank { abstract intgetRateOfInterest(); } class SBI extends Bank { intgetRateOfInterest() { return 7; } } class PNB extends Bank { intgetRateOfInterest() { return 9; } } class TestBank { public static void main(String args[]) { Bank b=new SBI();//if object is PNB, method of PNB will be invoked int interest=b.getRateOfInterest(); System.out.println("Rate of Interest is: "+interest+" %"); } } Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  20. Program: • interface f1 • { • public void get(intx,int y); • } • interface f2 • { • public void show(); • } • class Myclass implements f1,f2 • { • inta,b; • public void get(intx,int y) • { • a=x; b=y; • } • public void show() • { • System.out.println("Add="+(a+b)); • } • } • class Intf1 • { • public static void main(String args[]) • { • Myclassob=new Myclass(); • ob.get(10,20); • ob.show(); • }} • Interface With Class An interface in java is a blueprint of a class.Ithas static constants and abstract methods only. The interface in java is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body. It is used to achieve fully abstraction and multiple inheritance in Java. Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  21. Program: import java.util.*; interface f1 { public void get(); final int c=5; } interface f2 { public void show(); } class Myclass implements f1,f2 { inta,b; Scanner sc=new Scanner(System.in); public void get() { System.out.println("Enter a and b="); a=sc.nextInt(); b=sc.nextInt(); } public void show() { System.out.println("Add="+(a+b+c)); }} class Intf2 { public static void main(String args[]) { Myclassob=new Myclass(); ob.get(); ob.show(); }} Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  22. OUR SOFTWARE COURSES Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  23. OUR HARDWARE COURSES MCITP NETWORKING HARDWARE CCNA LINUX CCNP Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  24. OUR SERVICES WEBSITE DESIGNING & DEVELOPMENT Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  25. IT TRAINING Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  26. DIGITAL MARKETING Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  27. LAPTOP SALES AND SERVICES Website: www.pskitservices.com Phone: 9975288300 / 9970141466

  28. PSK TECHNOLOGIES PVT. LTD. IT COMPANY Thank You! FOLLOW US ON: Address: Plot no-780, Near Durga Temple, Katol Road Chhaoni, Nagpur-13 https:/www.pskitservices.com Contact: 9975288300

More Related