Sunday, February 23, 2020

Writing Classes in Java - Part 1

In this post we will be learning about the concepts of Accessor-Mutator and Constructors in Java.

Accessor and Mutator
      Accessor and Mutator are basically Getter and Setter methods. This is a way of implementing Encapsulation which is a key feature of Object Oriented Programming.
An Accessor method is used to return the value of a private member of the class. Similarly a Mutator method is used to set a value of a private member.
An instance of an object is created using the new keyword. The private member values are initialised using the Mutator method.

Constructor
The constructor can be said to be a special method that has the same name as the class name.
The constructor is used to initialise the values of the attributes of an object. The constructor is implicitly invoked when an object is created. If a constructor is not defined for a particular class the compiler provides a default constructor. It calls the default parent constructor and initializes all instance variables to default values ie. zero for numeric values, false for boolean values, etc. There is no return type or return statement in the body of a constructor. Constructors can be overloaded.
Given below is an example of a constructor.
class Student
{
//data members
private int GR_no;
private CPI;

//default Constructor
public Student()
{
  GR_no = 1;
  CPI = 0;
}

//parametrized Constructor
public Student(int n,int c)
{
  GR_no = n;
  CPI = c;
}
public static void main(String args[])
{
  Student s1 = new Student();  //no argument constructor will be called.
  Student s2 = new Student(1710,9.5);  //Parameterized Constructor
}
}

The example shows the use of default and parametrised constructor in Java.

Smruti Khire
K-38


Sunday, February 16, 2020

Introduction to Java Class


Basically, java class is group of objects and that all objects have same properties. It defines the shape and nature of an object. In java for implementation of any concept we must encapsulate that concept within a class. for create a class we have to decide a structure, once we decide the structure then it will be easy to write a class.
When we create a class that defines a new data type, this new type can be used to create object of that data type. thus, class is a template for an object and object is an instance of a class.
Every class is the combination of variables and methods. The data or variables defined within a class are called instance variable because each instance of the class contains its own copy of these variables. methods and variables defined within a class is called member of the class
In class declaration these components can include:
1.Modifier: A class can be public or has default access
2.Class name: The name should begin with capitalize letter
3. Body: The class body containing variables and methods, surrounded by braces { }.
structure of class
public class Dog {
public string breed;
public string color;
public string size;
public void run() {
system.out.println(I am running);
}
Public void bark() {
System.out.println(Wooh! Wooh!);
}
}
Public class main {
Public static void main(string[ ]args){
Dog dog1=new dog();
Dog1.breed=Beagle;
Dog1.size=40;
Dog1.color=Brownish White;
Dog1.run();
Dog1.bark();
}
}


Amarja Chede
K-10
















Sunday, February 9, 2020

Key Concepts in OOP using Java


OOP concept in JAVA is main objective behind Java Object Oriented Programming. 
The main four concepts are
1.     Abstraction
2.     Encapsulation
3.     Polymorphism
4.     Inheritance


Each concept is explained below in detail-
1.     Abstraction –Abstraction means representing complexity using simple terms. It means, show the relevant data and hide the unnecessary data of object from user. We all know turning ON television but how it operates internally according to our wish list we don’t know same is related to abstraction. Hides the internal working. Objects, classes and variables are simple terms in Java which represent complex codes and data. Use of this, helps to avoid repeated use of same lines multiple times.
2.     Encapsulation –Encapsulation is the practice of keeping the fields i.e data in private class, then giving access via public call methods. It is basically used for protecting the data and code safe within class itself .It’s a protective barrier. Using this we can reuse objects of code without giving open access system-wide.\
Characteristics required for encapsulated code-
 1. Everyone knows how to access it.
 2. Can be easily used regardless of implementation details.
 3. There should not be any side effect of code, to rest of application.
3.     Inheritance- It is special feature of OOP in Java .It allows to create new classes that share some attributes of existing classes. This helps to build on previous work without recreation of new procedure. Inheritance also means acquiring properties of another objects. It supports hierarchal classification. JAVA swing and AWT classes are best examples of inheritance.
4.     Polymorphism- Using polymorphism same word to mean different context can be used. Two forms of polymorphism are present in Java , those are method overloading and method overriding.
Method Overloading means different meanings implied by same code itself.
Method Overriding means different meanings implied by values of supplied variables.

Diksha Avhad
K-03




Tuesday, February 4, 2020

History of Java

The history of Java is quite interesting. It was developed by James Gosling in 1995. He and his team members started the project in the early '90s and were called as Green team. It was originally designed for small, embedded systems in electronic appliances like set-top boxes. However, at that time it was too advanced technology for television industry. Simple, robust, portable, platform independent, secured, high performance, multithreaded, architecture neutral, object-oriented, interpreted, and dynamic were some of the principles for creating Java programming.
James Gosling and his team called their project “Greentalk” and its file extension was .gt and later became to be known as “OAK” and was developed as a part of green project. Oak was renamed as "Java" in 1995 as it was already a trademark by Oak Technologies. James Gosling renamed it Java while having coffee near his office. The coffee was called Java coffee, the coffee from Indonesia.
The Time magazine, in 1995, called Java one of the Ten Best Products of 1995.
JDK 1.0 released in (January 23, 1996). Since the first release of Java, many additional features have been added to the language. Now Java is being used in Windows applications, Web applications, enterprise applications, mobile applications, cards, games, e-business solutions, etc. New features are added in Java with each new version. The latest versions of Java are JAVA SE 11  (September 2018) and JAVA SE 12 (March 2019).    

Rishita Jaiswal
K28