Showing posts with label Testing Framework. Show all posts
Showing posts with label Testing Framework. Show all posts

Saturday, August 2, 2025

๐Ÿ” Tools and Technologies I Use for Digital Forensics Investigations


Digital forensics
 plays a critical role in modern cybersecurity — whether it’s responding to a data breach, investigating insider threats, or performing incident analysis after suspicious behavior. In my work as a security-minded engineer and DevSecOps practitioner, I’ve frequently had to identify, collect, and analyze digital evidence across endpoints, servers, and cloud environments.

In this blog post, I’ll walk you through the tools and technologies I rely on to conduct effective digital forensics investigations — categorized by use case.


๐Ÿง  What Is Digital Forensics?

At its core, digital forensics is about identifying, preserving, analyzing, and reporting on digital data in a way that’s legally sound and technically accurate. The goal is to reconstruct eventsidentify malicious activity, and support security incident response.


๐Ÿงฐ My Go-To Tools for Digital Forensics Investigations


๐Ÿ—‚️ Disk & File System Analysis

These tools help examine hard drives, deleted files, system metadata, and more:

  • Autopsy (The Sleuth Kit) – A GUI-based forensic suite for analyzing disk images, file recovery, and timelines.

  • FTK Imager – For creating and previewing forensic images without altering the original evidence.

  • dd / dc3dd – Command-line tools to create low-level forensic disk images in Linux environments.

  • EnCase (Basic familiarity) – A commercial powerhouse in forensic investigations, used primarily for legal-grade evidence analysis.


๐Ÿงฌ Memory Forensics

Memory (RAM) often holds short-lived but critical evidence, like injected malware, live sessions, or loaded processes.

  • Volatility Framework – Extracts details like running processes, DLLs, command history, network activity, and more from memory dumps.

  • Rekall – An alternative memory analysis framework focused on automation and deep system state inspection.

✅ I’ve used Volatility to trace injected PowerShell payloads and enumerate hidden processes in live incident simulations.


๐ŸŒ Network Forensics

Capturing and analyzing network traffic is essential for spotting data exfiltration, command-and-control activity, or lateral movement.

  • Wireshark – Industry standard for packet analysis and protocol dissection.

  • tcpdump – Lightweight CLI tool to capture traffic in headless environments or remote systems.

  • NetworkMiner – Parses PCAP files to extract files, sessions, and credentials automatically.


๐Ÿ“Š Log & Timeline Analysis

Understanding what happened — and when — is key to reconstructing incidents.

  • Timesketch – A timeline analysis tool for visualizing and collaborating on event data.

  • Log2Timeline (Plaso) – Converts log files, browser histories, and system events into structured timelines.

  • Sysinternals Suite – Includes gems like ProcmonPsExec, and Autoruns for Windows incident response.


๐Ÿงช Malware Analysis (Static & Dynamic)

Understanding what a file does — before or while it runs — helps detect advanced threats and APT tools.

  • Ghidra – Powerful open-source reverse engineering tool from the NSA for analyzing executables.

  • x64dbg / OllyDbg – Popular debuggers for inspecting Windows executables.

  • Hybrid Analysis / VirusTotal – Cloud-based tools to scan files and observe sandbox behavior.

  • Cuckoo Sandbox – An open-source automated sandbox for observing malware behavior in a VM.


☁️ Cloud & Endpoint Forensics

Modern investigations often span cloud platforms and remote endpoints:

  • AWS CloudTrail, GuardDuty – Audit user and API activity in cloud environments.

  • Microsoft Azure Defender – For cloud-native threat detection and log correlation.

  • CrowdStrike Falcon / SentinelOne – Endpoint Detection and Response (EDR) tools for retrieving artifacts, hunting threats, and isolating compromised machines.


๐Ÿงฐ Scripting & Automation

Scripting accelerates collection, triage, and analysis — especially in large-scale environments.

  • Python – I use it to build custom Volatility plugins, PCAP parsers, or automate alert triage.

  • Bash / PowerShell – For live memory dumps, log gathering, process inspection, and rapid automation.


๐Ÿงฉ MITRE ATT&CK & DFIR Methodology

I map artifacts and behaviors to MITRE ATT&CK techniques (e.g., T1055 – Process Injection) to align with industry standards and communicate findings effectively.

I also follow established methodologies like:

  • SANS DFIR process

  • NIST 800-61 Incident Handling Guide

  • Custom playbooks for containment, eradication, and recovery

✅ Summary: Digital Forensics Tools I Use

๐Ÿ”น Disk & File System Analysis

  • Autopsy (Sleuth Kit) – GUI-based forensic suite

  • FTK Imager – Create and inspect forensic images

  • dd / dc3dd – Low-level disk imaging on Linux

  • EnCase – Commercial tool for deep disk investigations (basic familiarity)

๐Ÿ”น Memory Forensics

  • Volatility – Extract processes, DLLs, and sessions from RAM dumps

  • Rekall – Advanced volatile memory analysis

๐Ÿ”น Network Forensics

  • Wireshark – Protocol and packet analysis

  • tcpdump – Command-line traffic capture

  • NetworkMiner – Extracts files and sessions from PCAP files

๐Ÿ”น Log & Timeline Analysis

  • Timesketch – Timeline visualization and correlation

  • Plaso (log2timeline) – Converts raw logs into a forensic timeline

  • Sysinternals Suite – Live system inspection (Procmon, PsExec, Autoruns)

๐Ÿ”น Malware Analysis

  • Ghidra – Static reverse engineering

  • x64dbg / OllyDbg – Debuggers for binary inspection

  • Hybrid Analysis / VirusTotal – Behavioral analysis and threat intel

  • Cuckoo Sandbox – Automated dynamic malware analysis

๐Ÿ”น Cloud & Endpoint Forensics

  • AWS CloudTrail / GuardDuty – Monitor API and security activity

  • Microsoft Defender / Azure Logs – Cloud-native alerting and forensics

  • CrowdStrike Falcon / SentinelOne – EDR tools for endpoint activity and IOC collection

๐Ÿ”น Scripting & Automation

  • Python – For custom plugins, log parsers, automation

  • Bash / PowerShell – For system triage, memory dumps, and log collection

๐Ÿ”น Methodology

  • Align findings with MITRE ATT&CK

  • Follow structured DFIR frameworks like SANSNIST 800-61, and custom playbooks

๐ŸŽฏ Final Thoughts

Digital forensics isn’t just for breach responders — it’s a key skill for DevSecOps, SDETs, and any security-conscious engineer. Whether you’re building incident response workflows, simulating attacks, or validating your EDR, knowing how to collect and interpret evidence makes you far more effective.

Tuesday, July 29, 2025

๐Ÿ“ฑ Mobile App Testing: 10 Critical Test Scenarios You Can’t Miss (That Go Beyond Web UI Testing)


When it comes to testing mobile applications, the challenges go far beyond what typical web UI testing entails. Mobile apps must work flawlessly across a fragmented ecosystem of devices, screen sizes, OS versions, sensors, network conditions—and still deliver a high-performance experience. That’s why test engineers must design test cases that account for mobile-specific conditions that web-based apps don’t encounter.

In this post, we’ll break down the 10 critical mobile app test cases that every QA engineer should prioritize—and explain how they differ from traditional web UI testing.


✅ 1. Installation & Launch

Unlike web apps, mobile apps must be installed, upgraded, and uninstalled through OS-specific stores like Google Play or Apple App Store.

Test Cases:

  • App installs/uninstalls cleanly on all supported devices.

  • Launches successfully after a clean install or version upgrade.

  • First-launch behavior (onboarding, permission prompts) works without failure.


๐ŸŒ 2. Device & OS Compatibility

Mobile ecosystems are highly fragmented. You must ensure compatibility across OS versions, hardware specs, and screen dimensions.

Test Cases:

  • Verify app functionality on Android 10–14 and iOS 14–17.

  • Check responsiveness across tablets, foldables, and small-screen phones.

  • Test on low-RAM or budget devices (to catch memory issues).


๐Ÿ“ถ 3. Network Conditions

Mobile users are always switching between 5G, Wi-Fi, and even no network. Your app must handle this gracefully.

Test Cases:

  • App behaves predictably with no internet or low bandwidth.

  • Test auto-retries for failed API calls due to timeouts.

  • Switching from Wi-Fi to mobile data mid-session doesn’t break functionality.


๐Ÿ”„ 4. Background & Resume Behavior

A mobile app should maintain state and not crash when interrupted by a phone call or switching to another app.

Test Cases:

  • App resumes gracefully from background state.

  • Data entry is preserved when the user switches away and returns.

  • Proper behavior after a cold restart or after device reboot.


๐Ÿ”‹ 5. Battery & Performance

Performance testing on mobile goes beyond responsiveness—it’s also about battery and resource consumption.

Test Cases:

  • No excessive battery drain during idle or active use.

  • Monitor CPU/memory usage over time (watch for leaks).

  • Measure cold and warm start times.


๐Ÿ” 6. Permission Handling

Mobile apps rely on permissions to access hardware features. You must test both granting and denying permissions.

Test Cases:

  • App only requests necessary permissions.

  • Behavior is graceful when permissions are denied or revoked.

  • Scoped storage compliance (Android 11+) is in place.


๐Ÿ”” 7. Push Notifications

Push notifications are a core engagement channel and must work across all app states.

Test Cases:

  • Push received when app is in background or killed.

  • Tapping the notification leads to correct app screen.

  • Notifications respect user opt-in/opt-out settings.


๐Ÿ“ฒ 8. Gestures & UI Flexibility

Mobile users interact via gestures and virtual keyboards, making UX more dynamic than web.

Test Cases:

  • UI responds correctly to swipes, taps, long presses, and pinch-to-zoom.

  • Keyboard overlays don’t hide important input fields.

  • Smooth adaptation to dark mode, orientation changes (portrait ↔ landscape).


๐Ÿ” 9. Security Testing

Security is non-negotiable, especially with personal data or financial transactions involved.

Test Cases:

  • Secure storage for sensitive data (e.g., keystore/token vault).

  • No sensitive logs left in logcat or crash logs.

  • Behavior on rooted/jailbroken devices is safely restricted.


๐Ÿ“Š 10. Analytics & Store Compliance

Apps often embed SDKs for analytics and crash reporting, and must comply with store policies.

Test Cases:

  • Verify Firebase, GA, or Crashlytics events are firing correctly.

  • App follows Play Store / App Store policy (e.g., no deprecated APIs).

  • Correct versioning and metadata shown in store listing.


    ๐Ÿงช Final Thoughts

    If you’re only testing your mobile app like a web app, you’re missing half the picture. Mobile brings unique challenges and requires a deeper, device-aware test strategy. The 10 critical mobile test areas above should form the core of your test planning, especially for high-scale production apps used across a variety of devices and conditions.

Thursday, May 12, 2022

Appium Architecture - Core Concepts

What is Appium?

It’s a NodeJS based open-source tool for automating mobile applications. It supports native, mobile web, and hybrid applications on iOS mobile, Android mobile, and Windows desktop platforms.

Using Appium, you can run automated tests on physical devices or emulators, or both.



Let’s understand the above Appium architecture diagram.

  • Appium is a client-server architecture. The Appium server communicates with the client through the HTTP JSONWire Protocol using JSON objects.
  • Once it receives the request, it creates a session and returns the session ID, which will be used for communication so that all automation actions will be performed in the context of the created session.
  • Appium uses the UIAutomator test framework to execute commands on Android devices and emulators.
  • Appium uses the XCUITest test framework to execute commands on Apple mobile devices and simulators.
  • Appium uses WinAppDriver to execute commands for Windows Desktop apps. It is bundled with Appium and does not need to be installed separately.

Appium - Android visual interaction flow

Let’s understand the interaction flow between the code and the Android device via the Appium server.

  • The client sends the request to the Appium server through the HTTP JSONWire Protocol using JSON objects.
  • Appium sends the request to UIAutomator2.
  • UIAutomator2 communicates to a real device/simulator using bootstrap.jar which acts as a TCP server.
  • bootstrap.jar executes the command on the device and sends the response back.
  • Appium server sends back the command execution response to the client.

Appium - iOS visual interaction flow

Let’s understand the interaction flow between the code and the iOS device via the Appium server.

  • The client sends the request to the Appium server through the HTTP JSONWire Protocol using JSON objects.
  • Appium sends the request to XCUITest.
  • XCUITest communicates to a real device/simulator using bootstrap.js which acts as a TCP server.
  • bootstrap.js executes the command on the device and sends the response back.
  • The Appium server sends the command execution response to the client.

Whiteboard Sessions
  • IOS flow architecture

  • Android flow architecture

  • Drivers which appium supports
    • UI Automator2 (Android)
    • Espresso (Android)
    • WinApp (Windows)
    • MAC Driver (Mac OS)
    • XCUITest (IOS above 9.3 version)
    • UI Automation (IOS below 9.3 version)
    • Tizen (for samsung)


Happy Learning :) 

Thursday, October 17, 2019

Framework Evaluation & Selection

Framework Evaluation Criteria

  1. Support automation integration testing for UI (real/headless browser/device), API,  performance in cross platforms.

    • For the integration test, we don’t test the front-end or back-end individually. We need to verify the data with the integration between system, front-end & back-end. So the framework needs to be able to support all testing type and especially crossing browser, device & system.
  2. Support CI integration with parallel execution.

    • The testing framework needs to be able to integrate with our current CI/CD. Parallel execution will help reduce the build time, so we will be able to deploy quickly and have faster turnaround times for bugs and features.
  3. Supports the concept of executable documentation for BDD (behavior-driven development)& DDT (data-driven testing) in modularization, maintainable and understandable test suites.

    • BDD will help the test case & test suite easy to maintaining and understanding. It also helps communication between business and development is extremely focused as a result of common language.
    • One of the most important concepts for effective test automation is modularization, it will help to create a sequence of test case only one and reuse as often as required in test script without rewriting the test all the time.

BDD Testing Framework Selection


GaugeCucumber
LanguageMarkdownGherkin
IDE & plugin supportYesYes
Easy to integrate with CI/CDYesYes
Easy to use, quick to learnNoNo
Reusable, easy to maintainYesYes
Parallel executionBuilt-in3rd party plugin
Customize reportingYesYes
PriceOpen source & free Open source & free 

Winner - Gauge:

  • An open source lightweight cross-platform test automation tool with the ability to author test cases in the business language and have built-in parallel execution feature.
  • Support BDD (Behavior-Driven Development) & CI(Continuous Integration) & report customization.

API Testing Framework Selection


REST AssuredPostman
Support BDDYes3rd third party
Support DDTYesLimit
Easy to integrate with CI/CDYesYes
Easy to use, quick to learnNoYes
Reusable, easy to maintainYesNo
Customize reportingCan be used with any customized/open source reporting tool.No
PriceOpen source & free 8-21$ per user/month for professional collaboration  & advanced features
  

Winner - REST Assured:

  • An open source Java-based Domain-Specific Language (DSL) that allows writing powerful, readable, and maintainable automated tests for RESTful APIs. 
  • Support testing and validating REST services in BDD (Behavior-Driven Development) / Gherkin format.

API Performance Testing Framework  Selection


Apache JMeterLoadrunner
Support DDTYesYes
Easy to integrate with CI/CDYesYes
Easy to use, quick to learnYesNo
Cross-platformYesWindows, Linux
Reusable, easy to maintainYesNo
Customize reportingYesYes
PriceOpen source & free Free for first 50 virtual User

Winner - Apache JMeter : 

  • Open source performance test runner & management framework may be used to test performance both on static and dynamic resources.
  • Support load test functional behavior and measure performance. It can be used to simulate a heavy load on a server, group of servers, network or object to test its strength or to analyze overall performance under different load types.

Test Runner & Test Suite Management Framework Selection


TestNGJUnit
Support DDTYesYes
Easy to integrate with CI/CDYesYes
Easy to use, quick to learnNoNo
Reusable, easy to maintainYesYes
Parallel executionYesYes
PriceOpen source & free Open source & free 
Annotation supportYesLimit
Suite TestYesYes
Ignore TestYesYes
Exception TestYesYes
TimeoutYesYes
Parameterized TestYesYes
Dependency TestYesNo
Support executing before & after all tests in the suiteYesNo
Support executing  before & after a test runsYesNo
Support executing  before the first & last test method
is invoked that belongs to any of these groups is invoked
YesNo

Winner - TestNG :

  • Open source test runner framework which helps to run your tests in arbitrarily big thread pools with various policies available and flexible test configuration.
  • Support DDT(Data-driven testing) & Test suite management.

Build Tool & Dependency ManagementFramework Selection


Apache MavenGrandle
Easy to integrate with CI/CDYesYes
Easy to use, quick to learnYesNo
Build Script LanguageXMLGroovy
Reusable, easy to maintainYesYes
Dependency ManagementYesYes
Dependency ScopesBuilt-inCustom
IDE & plugin supportManyA little
PriceOpen source & free Open source & free 

Winner - Apache Maven 

  • The leading open source dependency management and build tool. It standardizes the software build process by articulating a project’s constitution.
  • Software project management and comprehension tool in the concept of a project object model (POM), Maven can manage a project's build, reporting, and documentation from a central piece of information.

Monday, April 4, 2016

Passing data to DataProvider from Excel sheet

In this example we will see how to pass the data to Dataproviders by reading the data from excel sheet. DataProvider helps to send multiple sets of data to a test method. But here we need to make sure that the array returned by the dataprovider should match with the test method parameters.
We will write a simple program in which we will validate login screen by taking multiple usernames and passwords. The annotated method must return object[][] where each object[] can be assigned to the test method one as username and the other parameter as password.
Step 1: First create a method to read excel data and return string array.
Step 2: Create before class and after class methods which helps in getting the browser and closing them when done.
Step 3: Create a data provider which actually gets the values by reading the excel.
Step 4: Create a Test which takes two parameters username and password.
Step 5: Add dataprovider name for @Test method to receive data from dataprovider.
package com.pack;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.testng.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;


import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ReadExcelDataProvider {
 public WebDriver driver;
 public WebDriverWait wait;
 String appURL = "https://www.linkedin.com/";
 
 //Locators
 private By byEmail = By.id("session_key-login");
 private By byPassword = By.id("session_password-login");
 private By bySubmit = By.id("signin");
 private By byError = By.id("global-alert-queue");
 
 @BeforeClass
 public void testSetup() {
  driver=new FirefoxDriver();
  driver.manage().window().maximize();
  wait = new WebDriverWait(driver, 5);
 }
 

 @Test(dataProvider="empLogin")
 public void VerifyInvalidLogin(String userName, String password) {
  driver.navigate().to(appURL);
  driver.findElement(byEmail).sendKeys(userName);
  driver.findElement(byPassword).sendKeys(password);
  //wait for element to be visible and perform click
  wait.until(ExpectedConditions.visibilityOfElementLocated(bySubmit));
  driver.findElement(bySubmit).click();
  
  //Check for error message
  wait.until(ExpectedConditions.presenceOfElementLocated(byError));
  String actualErrorDisplayed = driver.findElement(byError).getText();
  String requiredErrorMessage = "Please correct the marked field(s) below.";
  Assert.assertEquals(requiredErrorMessage, actualErrorDisplayed);
  
 }
 
 @DataProvider(name="empLogin")
 public Object[][] loginData() {
  Object[][] arrayObject = getExcelData("D:/sampledoc.xls","Sheet1");
  return arrayObject;
 }

 /**
  * @param File Name
  * @param Sheet Name
  * @return
  */
 public String[][] getExcelData(String fileName, String sheetName) {
  String[][] arrayExcelData = null;
  try {
   FileInputStream fs = new FileInputStream(fileName);
   Workbook wb = Workbook.getWorkbook(fs);
   Sheet sh = wb.getSheet(sheetName);

   int totalNoOfCols = sh.getColumns();
   int totalNoOfRows = sh.getRows();
   
   arrayExcelData = new String[totalNoOfRows-1][totalNoOfCols];
   
   for (int i= 1 ; i < totalNoOfRows; i++) {

    for (int j=0; j < totalNoOfCols; j++) {
     arrayExcelData[i-1][j] = sh.getCell(j, i).getContents();
    }

   }
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
   e.printStackTrace();
  } catch (BiffException e) {
   e.printStackTrace();
  }
  return arrayExcelData;
 }

 @Test
 public void tearDown() {
  driver.quit();
 }
}
After clicking on login button, we are using WebdriverWaits to Check for error message and validate.
The output should look like below:
[TestNG] Running:
  C:\Users\easy\AppData\Local\Temp\testng-eclipse-583753747\testng-customsuite.xml

PASSED: VerifyInvalidLogin("testuser1", "testpassword1")
PASSED: VerifyInvalidLogin("testuser2", "testpassword2")
PASSED: VerifyInvalidLogin("testuser3", "testpassword3")
PASSED: VerifyInvalidLogin("testuser4", "testpassword4")
PASSED: VerifyInvalidLogin("testuser5", "testpassword5")

===============================================
    Default test
    Tests run: 5, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 5, Failures: 0, Skips: 0
===============================================

DataProvider in TestNG

Marks a method as supplying data for a test method. The annotated method must return an Object[][] where each Object[] can be assigned the parameter list of the test method.
The @Test method that wants to receive data from this DataProvider needs to use a dataProvider name equals to the name of this annotation.
The name of this data provider. If it's not supplied, the name of this data provider will automatically be set to the name of the method.
In the below example we will pass the data from getData() method to data provider. We will send 3 rows and 2 columns ie. we will pass three different usernames and passwords.
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class DataProviderExample{
 
 //This test method declares that its data should be supplied by the Data Provider
 // "getdata" is the function name which is passing the data
       // Number of columns should match the number of input parameters
 @Test(dataProvider="getData")
 public void setData(String username, String password)
 {
  System.out.println("you have provided username as::"+username);
  System.out.println("you have provided password as::"+password);
 }

 @DataProvider
 public Object[][] getData()
 {
 //Rows - Number of times your test has to be repeated.
 //Columns - Number of parameters in test data.
 Object[][] data = new Object[3][2];

 // 1st row
 data[0][0] ="sampleuser1";
 data[0][1] = "abcdef";

 // 2nd row
 data[1][0] ="testuser2";
 data[1][1] = "zxcvb";
 
 // 3rd row
 data[2][0] ="guestuser3";
 data[2][1] = "pass123";

 return data;
 }
}
When we execute the above example, we will the get the output as below:
Each data set that we pass will be considered as a test method. As we passed three set of data to the data provider, it will display result as below:
Default suite
Total tests run: 3, Failures: 0, Skips: 0
Output of the Above Program
you have provided username as::sampleuser1
you have provided password as::sampleuser1
you have provided username as::testuser2
you have provided password as::testuser2
you have provided username as::guestuser3
you have provided password as::guestuser3
PASSED: testdata("sampleuser1", "abcdef")
PASSED: testdata("testuser2", "zxcvb")
PASSED: testdata("guestuser3", "password123")

Tuesday, June 30, 2015

Some interesting Java Facts

Creation of an Object:

Following steps are completed while creating a new object of any class :-
1. Bind Constructor parameters.
2. If explicit this(),call recursively and skip to step 5.
3. Call recursively the implicit and explicit super(...),except for their Object class
because it has no parent class.
4. Execute the explicit instance variable initializers. // it refers to initialisation of instance variables at the time of their declaration.
5.  Execute the body of the current constructor.

Exceptions

1.finally clause is always executed regardless of the fact that exception is caused or not.
2.only way that finally will not be executed is virtual machine shutdown or execution of "System.exit(0)" method.
3.If return statement is embedded inside the try block then finally clause executes before return.
4. Exception must be thrown in same line where its object is created because it contains line no. information.

Accessing Members of "super base" Class

Suppose class B extends class A and class C further extends class B.
Now Suppose we want to access the members of class A directly through C class.
This can be either accomplished by using super twice once in C and once in B.
Or other way is to use super in Class C and if members with same name are not
present in B then this super will directly refer to member in super base class A.
example of a such a program.

class A
{
 static
 {
  System.out.println("static initializer of A");
 }
 {
  System.out.println("initializer of A");
 }
 A()
 {
  System.out.println("Constructor class A");
 }
 A(int a)
 {
  System.out.println("Constructor class A parameter");
 }
 void hello()
 {
  System.out.println("Hello in c");
 }
 void quality()
 {
  System.out.println("Quality Method Class A");
 }
}
class B extends A
{
 static
 {
  System.out.println("static initializer of B");
 }
 {
  System.out.println("initializer of B");
 }
 B()
 {
  System.out.println("Constructor class B");
 }
 B(int b)
 {
  System.out.println("Constructor class B parameter");
 }
 void show()
 {
  System.out.println("I m in class B");
 }
}
class C extends B
{
 static
 {
  System.out.println("static initializer of C");
 }
 {
  System.out.println("initializer of C");
 }
 C()
 {
  System.out.println("Constructor class C");
 }
 C(int c)
 {
  //super.show();
  System.out.println("Constructor class C parameter");
 }
 void show()
 {
  System.out.println("I m in class C");
 }
 void quality()
 {
  super.quality();
  System.out.println("Quality Method Class C");
 }
}
public class inh
{
 public static void main(String ...args)
 {
  A a=new C(3);
  a.quality();
 }
}

Polymorphic Arguments in Polymorphism

Suppose a method in a class uses reference of some base class as its argument to perform certain calculations. Now it can also intake the object of child class as its argument because child is also a type of base class object. Bu important point is that this method can only access the members of parent class and not child specific features.

Referring members of a base class in Polymorphism

If we create reference of base class then we can access child class methods which are overridden but child class specific methods are not accessible as accomplished by following program:
class base
{
 base()
 {
  System.out.println("base class");
 }
 void show()
 {
  System.out.println("Show method base class");
 }
}
class child extends base
{
 child()
 {
  System.out.println("child class");
 }
 void show()
 {
  System.out.println("Show method child class");
 }
 void specific()
 {
  System.out.println("Specific Method of Child class not present in base");
 }
 public static void main(String args[])
 {
  base b=new child();
  b.specific();//illegal will not compile
  b.show();//child class method executes
 }
}

Encapsulation

Encapsulation is one of the four fundamental OOP concepts. 
Grouping functions and corresponding data into a single capsule is called Encapsulation
Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding.
Encapsulation can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class. Access to the data and code is tightly controlled by an interface.
The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature Encapsulation gives maintainability, flexibility and extensibility to our code.

Encapsulation =Datahiding + Abstraction

Example:

Let us look at an example that depicts encapsulation:
/* File name : EncapTest.java */
public class EncapTest{

   private String name;
   private String idNum;
   private int age;

   public int getAge(){
      return age;
   }

   public String getName(){
      return name;
   }

   public String getIdNum(){
      return idNum;
   }

   public void setAge( int newAge){
      age = newAge;
   }

   public void setName(String newName){
      name = newName;
   }

   public void setIdNum( String newId){
      idNum = newId;
   }
}
The public methods are the access points to this class's fields from the outside java world. Normally these methods are referred as getters and setters. Therefore any class that wants to access the variables should access them through these getters and setters.
The variables of the EncapTest class can be access as below::
/* File name : RunEncap.java */
public class RunEncap{

   public static void main(String args[]){
      EncapTest encap = new EncapTest();
      encap.setName("James");
      encap.setAge(20);
      encap.setIdNum("12343ms");

      System.out.print("Name : " + encap.getName()+ 
                             " Age : "+ encap.getAge());
    }
}
This would produce following result:
Name : James Age : 20

Benefits of Encapsulation:

  • The fields of a class can be made read-only or write-only.
  • A class can have total control over what is stored in its fields.
  • The users of a class do not know how the class stores its data. A class can change the data type of a field, and users of the class do not need to change any of their code.

My Profile

My photo
can be reached at 09916017317