To learn about the basic concepts of Object Oriented Programming and Inheritance plus different Inheritance Models and interview questions will be covered.
The document discusses Java wrapper classes. Wrapper classes wrap primitive data types like int, double, boolean in objects. This allows primitive types to be used like objects. The main wrapper classes are Byte, Short, Integer, Long, Character, Boolean, Double, Float. They provide methods to convert between primitive types and their wrapper objects. Constructors take primitive values or strings to create wrapper objects. Methods like parseInt() convert strings to primitive types.
The document discusses Java AWT and Swing GUI programming. It provides details on commonly used AWT and Swing components like Frame, Button, Label, Textfield. It explains the hierarchy and differences between AWT and Swing. Examples are provided to demonstrate creating a simple GUI using various components like Buttons, Labels and adding them to a Frame. The document also covers other Swing components like Checkboxes, Scrollpanes and containers like Frame, Dialog, Panel.
This document discusses polymorphism and inheritance concepts in Java. It defines polymorphism as an object taking on many forms, and describes method overloading and overriding. Method overloading allows classes to have multiple methods with the same name but different parameters. Method overriding allows subclasses to provide a specific implementation of a method in the parent class. The document also discusses abstract classes and interfaces for abstraction in Java, and explains access modifiers like public, private, protected, and default.
The document discusses String handling in Java. It describes how Strings are implemented as objects in Java rather than character arrays. It also summarizes various methods available in the String and StringBuffer classes for string concatenation, character extraction, comparison, modification, and value conversion. These methods allow extracting characters, comparing strings, modifying strings, and converting between string and other data types.
The document discusses lambda expressions in Java 8. It provides background on the lambda calculus and functional programming. Lambda expressions allow anonymous functions and are implemented using functional interfaces in Java 8. This enables a more functional style of programming. Lambda expressions can access variables from their enclosing scope and method references provide a concise way to pass existing methods. The streams API allows functional-style operations on collections and supports sequential and parallel processing.
The document discusses the super keyword, final keyword, and interfaces in Java.
- The super keyword is used to refer to the immediate parent class and can be used with variables, methods, and constructors. It allows accessing members of the parent class from the child class.
- The final keyword can be used with variables, methods, and classes. It makes variables constant and prevents overriding of methods and inheritance of classes.
- Interfaces in Java allow achieving abstraction and multiple inheritance. They can contain only abstract methods and variables declared with default access modifiers. Classes implement interfaces to provide method definitions.
The document discusses arrays in Java, including how to declare and initialize one-dimensional and two-dimensional arrays, access array elements, pass arrays as parameters, and sort and search arrays. It also covers arrays of objects and examples of using arrays to store student data and daily temperature readings from multiple cities over multiple days.
This document discusses arrays in Java programming. It covers defining and creating single and multi-dimensional arrays, accessing array elements using indexes and loops, and performing operations like sorting and finding maximum/minimum values. Examples are provided for different array types like integer, string and character arrays, and operations like input/output, break/continue statements, and star patterns. Homework involves writing a program to produce a given output pattern.
This document discusses polymorphism in Java programs. Polymorphism refers to the ability of an object to take on multiple forms. In Java, polymorphism allows a reference variable to change behavior based on the object it is holding. There are three forms of polymorphism in Java: method overriding, overriding abstract methods of an abstract class, and implementing interface methods. Polymorphism provides benefits like simplicity and extensibility in code.
Conditional statements in Java include if-else statements, nested if-else statements, and switch statements. If-else statements execute code based on a boolean condition, while switch statements allow testing multiple conditions. Type conversion in Java includes widening (automatic) conversions between compatible types like int to double, and narrowing (manual) conversions between incompatible types using explicit casting like double to int. Methods like parseInt() allow converting between types like String to int.
Operator overloading and type conversion in cpprajshreemuthiah
This document discusses operator overloading and type conversion in C++. It defines operator overloading as providing new definitions for most C++ operators in relation to a class. It covers overloading unary operators like minus and binary operators like addition. Friend functions can also be used to overload binary operators. Rules for operator overloading include only existing operators can be overloaded and some operators cannot be overloaded. Type conversion automatically converts the type on the right side of an assignment to the type on the left. Constructors can be used to convert basic types to class types.
This document discusses inheritance in Java. It defines inheritance as allowing new classes to reuse properties of existing classes. There are different types of inheritance including single, multilevel, and hierarchical. Key concepts covered include defining subclasses using the extends keyword, using the super keyword to call parent constructors and access parent members, overriding methods, abstract classes and methods, and using the final keyword to prevent overriding or inheritance.
- Arrays allow storing multiple values in a single variable. They are useful for problems that require working with several variables at once, like calculating exam averages for 100 students.
- Arrays are initialized with a size and values can be stored and retrieved using indexes. Common issues include accessing indexes outside the array bounds or failing to initialize arrays properly.
- Command line arguments provide a way to pass user input to a program via the command line when it is launched. The arguments are stored in a String array that is initialized for the program.
Dynamic method dispatch allows the determination of which version of an overridden method to execute at runtime based on the object's type. Abstract classes cannot be instantiated and can contain both abstract and concrete methods. Final methods and classes prevent inheritance and overriding.
The document discusses methods in Java programming. It explains that methods can be used to divide large blocks of code into smaller, more manageable pieces by grouping related lines of code into reusable functions. This improves readability and maintainability of programs. The document provides examples of using methods without and with parameters and return values. It also covers defining your own methods and using methods from Java library classes.
Polymorphism refers to an object's ability to take on multiple forms. In object-oriented programming, polymorphism occurs when an entity such as a variable, function, or object can have more than one form. There are two main types of polymorphism: compile-time polymorphism (such as function and operator overloading) and runtime polymorphism (using virtual functions). Polymorphism allows programmers to work with general classes and let the runtime system handle the specific types, providing flexibility.
Packages in Java allow grouping of related classes and interfaces to avoid naming collisions. Some key points about packages include:
- Packages allow for code reusability and easy location of files. The Java API uses packages to organize core classes.
- Custom packages can be created by specifying the package name at the beginning of a Java file. The class files are then compiled to the corresponding directory structure.
- The import statement and fully qualified names can be used to access classes from other packages. The classpath variable specifies locations of package directories and classes.
This document discusses implementation of inheritance in Java and C#. It covers key inheritance concepts like simple, multilevel, and hierarchical inheritance. It provides examples of inheritance in Java using keywords like extends, super, this. Interfaces are discussed as a way to achieve multiple inheritance in Java. The document also discusses implementation of inheritance in C# using concepts like calling base class constructors and defining virtual methods.
Multithreading allows programs to have multiple threads that can run concurrently. Each thread defines a separate path of execution. Processes are programs that are executing, while threads exist within a process and share its resources. Creating a new thread requires fewer resources than creating a new process. There are two main ways to define a thread - by implementing the Runnable interface or by extending the Thread class.
This document discusses methods in Java. It defines a method as a collection of instructions that performs a specific task and provides code reusability. There are two types of methods in Java: predefined methods and user-defined methods. Predefined methods are methods already defined in Java class libraries that can be directly called, while user-defined methods are written by programmers according to their needs. Examples of both types of methods are provided.
This document provides an introduction to Java programming concepts including:
- Java is both a programming language and platform that is simple, architecture neutral, object-oriented, and portable.
- Java source code is written in .java files and compiled into .class files by javac before being executed by the Java Virtual Machine (JVM).
- The JVM allows Java programs to run on any platform without recompilation, providing platform independence.
- Key Java concepts covered include objects, classes, methods, variables, data types, operators, control flow, and arrays.
- Examples demonstrate how to write, compile, and run simple Java programs to illustrate these core programming concepts.
In this core java training session, you will learn Collections – Lists, Sets. Topics covered in this session are:
• List – ArrayList, LinkedList
• Set – HashSet, LinkedHashSet, TreeSet
For more information about this course visit on this link: https://www.mindsmapped.com/courses/software-development/learn-java-fundamentals-hands-on-training-on-core-java-concepts/
Arrays in Python can hold multiple values and each element has a numeric index. Arrays can be one-dimensional (1D), two-dimensional (2D), or multi-dimensional. Common operations on arrays include accessing elements, adding/removing elements, concatenating arrays, slicing arrays, looping through elements, and sorting arrays. The NumPy library provides powerful capabilities to work with n-dimensional arrays and matrices.
Abstraction is a process by which concepts are derived from the usage and classification of literal ("real" or "concrete") concepts.
Abstraction is a concept that acts as a super-categorical noun for all subordinate concepts, and connects any related concepts as a group, field, or category.
SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. It is often used for local/client storage in applications. Key points:
- Created by D. Richard Hipp, it provides a lightweight disk-based database that doesn't require a separate server process and allows accessing the database using SQL queries.
- The entire database is stored in a single cross-platform file and can be as small as 0.5MB, making it suitable for embedded and mobile applications.
- It supports common data types like NULL, INTEGER, REAL, TEXT, and BLOB and is used in standalone apps, local
The document discusses key concepts in object-oriented programming including objects, classes, messages, and requirements for object-oriented languages. An object is a bundle of related variables and methods that can model real-world things. A class defines common variables and methods for objects of a certain kind. Objects communicate by sending messages to each other specifying a method name and parameters. For a language to be object-oriented, it must support encapsulation, inheritance, and dynamic binding.
Static members in Java include static variables, static blocks, and static methods.
Static variables and blocks are initialized when the class is loaded, while static methods can be accessed without creating an object. Overloading static methods is allowed by having multiple methods with the same name but different parameters. The order of execution is that static variables and blocks are initialized in the order they are declared, followed by the main method.
This document discusses polymorphism in Java programs. Polymorphism refers to the ability of an object to take on multiple forms. In Java, polymorphism allows a reference variable to change behavior based on the object it is holding. There are three forms of polymorphism in Java: method overriding, overriding abstract methods of an abstract class, and implementing interface methods. Polymorphism provides benefits like simplicity and extensibility in code.
Conditional statements in Java include if-else statements, nested if-else statements, and switch statements. If-else statements execute code based on a boolean condition, while switch statements allow testing multiple conditions. Type conversion in Java includes widening (automatic) conversions between compatible types like int to double, and narrowing (manual) conversions between incompatible types using explicit casting like double to int. Methods like parseInt() allow converting between types like String to int.
Operator overloading and type conversion in cpprajshreemuthiah
This document discusses operator overloading and type conversion in C++. It defines operator overloading as providing new definitions for most C++ operators in relation to a class. It covers overloading unary operators like minus and binary operators like addition. Friend functions can also be used to overload binary operators. Rules for operator overloading include only existing operators can be overloaded and some operators cannot be overloaded. Type conversion automatically converts the type on the right side of an assignment to the type on the left. Constructors can be used to convert basic types to class types.
This document discusses inheritance in Java. It defines inheritance as allowing new classes to reuse properties of existing classes. There are different types of inheritance including single, multilevel, and hierarchical. Key concepts covered include defining subclasses using the extends keyword, using the super keyword to call parent constructors and access parent members, overriding methods, abstract classes and methods, and using the final keyword to prevent overriding or inheritance.
- Arrays allow storing multiple values in a single variable. They are useful for problems that require working with several variables at once, like calculating exam averages for 100 students.
- Arrays are initialized with a size and values can be stored and retrieved using indexes. Common issues include accessing indexes outside the array bounds or failing to initialize arrays properly.
- Command line arguments provide a way to pass user input to a program via the command line when it is launched. The arguments are stored in a String array that is initialized for the program.
Dynamic method dispatch allows the determination of which version of an overridden method to execute at runtime based on the object's type. Abstract classes cannot be instantiated and can contain both abstract and concrete methods. Final methods and classes prevent inheritance and overriding.
The document discusses methods in Java programming. It explains that methods can be used to divide large blocks of code into smaller, more manageable pieces by grouping related lines of code into reusable functions. This improves readability and maintainability of programs. The document provides examples of using methods without and with parameters and return values. It also covers defining your own methods and using methods from Java library classes.
Polymorphism refers to an object's ability to take on multiple forms. In object-oriented programming, polymorphism occurs when an entity such as a variable, function, or object can have more than one form. There are two main types of polymorphism: compile-time polymorphism (such as function and operator overloading) and runtime polymorphism (using virtual functions). Polymorphism allows programmers to work with general classes and let the runtime system handle the specific types, providing flexibility.
Packages in Java allow grouping of related classes and interfaces to avoid naming collisions. Some key points about packages include:
- Packages allow for code reusability and easy location of files. The Java API uses packages to organize core classes.
- Custom packages can be created by specifying the package name at the beginning of a Java file. The class files are then compiled to the corresponding directory structure.
- The import statement and fully qualified names can be used to access classes from other packages. The classpath variable specifies locations of package directories and classes.
This document discusses implementation of inheritance in Java and C#. It covers key inheritance concepts like simple, multilevel, and hierarchical inheritance. It provides examples of inheritance in Java using keywords like extends, super, this. Interfaces are discussed as a way to achieve multiple inheritance in Java. The document also discusses implementation of inheritance in C# using concepts like calling base class constructors and defining virtual methods.
Multithreading allows programs to have multiple threads that can run concurrently. Each thread defines a separate path of execution. Processes are programs that are executing, while threads exist within a process and share its resources. Creating a new thread requires fewer resources than creating a new process. There are two main ways to define a thread - by implementing the Runnable interface or by extending the Thread class.
This document discusses methods in Java. It defines a method as a collection of instructions that performs a specific task and provides code reusability. There are two types of methods in Java: predefined methods and user-defined methods. Predefined methods are methods already defined in Java class libraries that can be directly called, while user-defined methods are written by programmers according to their needs. Examples of both types of methods are provided.
This document provides an introduction to Java programming concepts including:
- Java is both a programming language and platform that is simple, architecture neutral, object-oriented, and portable.
- Java source code is written in .java files and compiled into .class files by javac before being executed by the Java Virtual Machine (JVM).
- The JVM allows Java programs to run on any platform without recompilation, providing platform independence.
- Key Java concepts covered include objects, classes, methods, variables, data types, operators, control flow, and arrays.
- Examples demonstrate how to write, compile, and run simple Java programs to illustrate these core programming concepts.
In this core java training session, you will learn Collections – Lists, Sets. Topics covered in this session are:
• List – ArrayList, LinkedList
• Set – HashSet, LinkedHashSet, TreeSet
For more information about this course visit on this link: https://www.mindsmapped.com/courses/software-development/learn-java-fundamentals-hands-on-training-on-core-java-concepts/
Arrays in Python can hold multiple values and each element has a numeric index. Arrays can be one-dimensional (1D), two-dimensional (2D), or multi-dimensional. Common operations on arrays include accessing elements, adding/removing elements, concatenating arrays, slicing arrays, looping through elements, and sorting arrays. The NumPy library provides powerful capabilities to work with n-dimensional arrays and matrices.
Abstraction is a process by which concepts are derived from the usage and classification of literal ("real" or "concrete") concepts.
Abstraction is a concept that acts as a super-categorical noun for all subordinate concepts, and connects any related concepts as a group, field, or category.
SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. It is often used for local/client storage in applications. Key points:
- Created by D. Richard Hipp, it provides a lightweight disk-based database that doesn't require a separate server process and allows accessing the database using SQL queries.
- The entire database is stored in a single cross-platform file and can be as small as 0.5MB, making it suitable for embedded and mobile applications.
- It supports common data types like NULL, INTEGER, REAL, TEXT, and BLOB and is used in standalone apps, local
The document discusses key concepts in object-oriented programming including objects, classes, messages, and requirements for object-oriented languages. An object is a bundle of related variables and methods that can model real-world things. A class defines common variables and methods for objects of a certain kind. Objects communicate by sending messages to each other specifying a method name and parameters. For a language to be object-oriented, it must support encapsulation, inheritance, and dynamic binding.
Static members in Java include static variables, static blocks, and static methods.
Static variables and blocks are initialized when the class is loaded, while static methods can be accessed without creating an object. Overloading static methods is allowed by having multiple methods with the same name but different parameters. The order of execution is that static variables and blocks are initialized in the order they are declared, followed by the main method.
The document discusses the static keyword in Java and its uses for variables, methods, blocks and nested classes. It explains that static members belong to the class rather than instances, and provides examples of static variables, methods, blocks and how they work. Key points include static variables having only one copy in memory and being shared across instances, static methods that can be called without an instance, and static blocks that initialize static fields when the class loads.
Java tutorial for Beginners and Entry LevelRamrao Desai
This document provides an overview of key Java concepts including classes, objects, inheritance, interfaces, exceptions, and more. It begins with a roadmap and definitions of object-oriented concepts like class and object. It then covers class variables and methods, visibility, static vs non-static, constructors, and the this keyword. The document also discusses inheritance, polymorphism, interfaces, exceptions, and error handling in Java.
This 5-day Java workshop covers object-oriented programming (OOP) concepts like encapsulation, abstraction, inheritance, and polymorphism. It discusses the four principles of OOP and how to achieve abstraction through classes, objects, and inheritance. The document provides examples of using objects, constructors, and the this keyword. It also covers access modifiers, static methods, and encapsulation to control access to object attributes through getters and setters.
The document discusses defining classes and objects in Java. It covers defining simple classes, class elements like fields and methods, constructors, properties, static members, and using classes by creating instances and calling methods. Key points include classes define the structure of objects, constructors initialize object state, properties encapsulate fields, and static members are associated with a class not individual objects.
This document discusses classes, methods, objects, constructors and other object-oriented programming concepts in Java. Some key points:
- Classes are templates that define objects, while objects are instances of classes that have state and behavior.
- Methods are collections of code that perform specific tasks and provide reusability. The main() method is important as it is executed first.
- Constructors initialize objects and are automatically called when objects are created. There can be default and parameterized constructors.
- Objects are created using the new keyword and access class members like methods using the dot operator. Arrays can store multiple objects.
- Methods and constructors can be overloaded when they have the same name but different parameters
The static keyword in Java is used for memory management. It allows variables and methods to belong to the class rather than instances of the class. Static variables and methods are associated with the class, not objects, so they can be accessed without creating an object of the class. Static variables only have one copy in memory and static methods can access static variables and change their values without creating an object. Examples demonstrate how to declare static variables and methods and how they differ from non-static variables and methods.
The document discusses key concepts in Object Oriented Programming (OOP) in Java including classes, objects, references, constructors, inheritance, abstraction, polymorphism, and generics. It defines classes as blueprints for objects, and objects as instances of classes that have state and behavior. Constructors are used to initialize new objects. Inheritance and abstraction allow classes to extend and implement other classes and interfaces. Polymorphism enables different classes to implement the same methods in different ways. Generics provide type safety for collections of objects.
This document discusses object-oriented programming concepts in Java including objects, classes, constructors, inheritance, polymorphism, and access modifiers.
The key points are:
1) An object represents an entity with a unique identity, state, and behaviors. A class defines common properties and behaviors of objects.
2) Constructors initialize new objects, while methods define object behaviors. Inheritance allows subclasses to inherit properties and behaviors from parent classes.
3) Access modifiers like public, private, and protected control the visibility and accessibility of classes, variables, and methods. Final and abstract modifiers are also used to restrict or require subclassing.
This document provides an overview of Java fundamentals including classes, objects, encapsulation, abstraction, inheritance, polymorphism and other core OOP concepts. Key points covered include:
- Classes contain variable declarations and method definitions while objects have state, behavior and identity.
- Encapsulation is achieved by declaring class variables as private and providing public get and set methods.
- Abstraction hides certain details and shows only essential information to the user using abstract classes and interfaces.
- Inheritance allows classes to extend functionality from other classes in a hierarchical manner to achieve code reuse.
- Polymorphism allows a single action to be performed in different ways depending on the object used.
The document discusses object-oriented programming concepts in Java including classes, objects, methods, constructors, inheritance, and more. It includes examples of defining a Box class with attributes like width, height, and length, as well as methods to set dimensions and calculate volume. Constructors are demonstrated for initializing object attributes. Later sections cover topics like static members, method overloading, argument passing by value vs reference, and returning objects from methods.
This document summarizes key concepts in object-oriented programming (OOP) in Java, including static keyword, instance member, class member, inheritance, encapsulation, polymorphism, object, class, constructor, and more. It provides examples to illustrate static variables and methods, the this keyword, super keyword, final keyword, abstract classes vs interfaces, and method overloading as a form of compile-time polymorphism.
The program defines a class Counter that maintains a static variable count to track the number of objects created. It initializes count to 0. The constructor increments count and prints the updated count. The main method creates three Counter objects to test the functionality.
The document provides instructions for completing a Java lab assignment involving classes for drawing shapes and colors. It describes the required classes - ColorHolder, ColorButton, CircleButton, SquareButton, and SimpleDraw - and their relationships. ColorHolder stores and sets the current color. ColorButton defines a buttonPressed method. CircleButton and SquareButton add shapes to the Window when pressed and reference the single Window object. SimpleDraw initializes instances of these classes and adds them to the Window.
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
The lecture was condcuted by Tushar B Kute at YCMOU, Nashik through VLC orgnanized by MSBTE. The contents can be found in book "Core Java Programming - A Practical Approach' by Laxmi Publications.
This document summarizes an email service that can meet the email needs of companies without requiring an IT department, allows instant communication between employees through Cliq messaging groups, and connects and enables teams through a bundle of apps including email, documents, presentations, and chat on a single platform. It offers various plans including Lite with email, Standard with additional docs and office apps, and Professional with meeting, project management, and other collaboration tools.
C Pointers & File Handling covered various topics that are important w.r.t exam point of view and has basic concept of Pointers, Functions, Recursion, Structures, Union, Conditional Compilations, C Preprocessor, Stack, Queue and Linked List data structure plus various important theory based questions.
It has important MCQ's and programs that are asked in almost every company placement test repeatedly. It also has various different c programs like Fibonacci, Prime, Armstrong and other programs related to Strings.
It is very helpful in learning all the basics concepts of DBMS starting from Introduction: An Overview of Database Management System to Data Modeling using the Entity-Relationship Model, PL/SQL, Transaction Processing Concept, and Concurrency Control Techniques plus important numerals in exam point of view can be learned.
It consists of important different concepts related to PL/SQL that are covered like the Basic structure of PL/SQL block, Variables and Constants in PL/SQL, Control Structures i.e., Conditional, Iterative, and Sequential Control, Procedure and Function, Cursors and its Types, Applications of implicit and explicit cursors, Triggers and its Types and Exception Handling.
The document appears to be a scanned collection of pages from a book or manual. It contains images of many pages with text and diagrams but no clear overall narrative or topic. As it is a scan of pages from another source, it is difficult to provide an informative high-level summary in 3 sentences or less.
It consists of full operating system notes which cover Introduction, Processes, CPU Scheduling, Process Synchronization, Classical Problem in Concurrency, Deadlock, Memory Management, Virtual memory concepts, I/O Management and Disk Scheduling, File System.
It includes all notes of the Computer Network for CSE students and consists of Introduction Concepts, Medium Access sublayer, Data Link Layer, Network Layer, Transport Layer, Session Layer, Presentation Layer, Application Layer.
To learn important concept of Collection and its handling plus its advantages and different class & child class of Collection and their implementations. Important interview questions of the collection.
Learn about the basic fundamentals of java and important for the different company's interview. Topics like JRE, JDK, Java Keywords, Primitive DataTypes, Types of Variables, Logical, Shift and Bitwise Operator working, Command Line Argument, Handling Arrays, Array Copy, and different programs and output based programs.
Important & Basics Notes for Unified Modeling Language, Object-Oriented Concepts, UML Building Blocks & its Component, Use Cases, State Transition Diagram Examples, Structural Diagrams like Class Diagram/ Object Diagram/ Component Diagram/ Deployment Diagram, Behavioural Diagrams like Use Case Diagram/ Sequence Diagram/ State Chart Diagram/ Collaboration Diagram/ Activity Diagrams with Examples, Models & its Types, Hospital Management System, Book Store class Diagram & Sequence Diagram.
Abstract Window Toolkit, Swings & its Hierarchy, Applets & its Life Cycle, Servlets & its Life Cycle, Steps to connect Java Application to Database, Servlet Application Working, Steps to create Servlet, HTTP Session & its Working, Remote Method Invocation, Steps to create RMI, Marshaling & Unmarshaling, Enterprise Java Beans, Java Beans & its Use,Elements of Java Beans,Bean Development Kit,Steps to Develop User-defined Java Beans,Web Services its Types and features,Restful Web Service, Java Cryptography & Security & its Services, Architecture of Cryptography.
Structural Health and Factors affecting.pptxgunjalsachin
Structural Health- Factors affecting Health of Structures,
Causes of deterioration in RC structures-Permeability of concrete, capillary porosity, air voids, Micro cracks and macro cracks, corrosion of reinforcing bars, sulphate attack, alkali silica reaction
Causes of deterioration in Steel Structures: corrosion, Uniform deterioration, pitting, crevice, galvanic, laminar, Erosion, cavitations, fretting, Exfoliation, Stress, causes of defects in connection
Maintenance and inspection of structures.
Electrical and Electronics Engineering: An International Journal (ELELIJ)elelijjournal653
Call For Papers...!!!
Electrical and Electronics Engineering: An International Journal (ELELIJ)
Web page link: https://wireilla.com/engg/eeeij/index.html
Submission Deadline: June 08, 2025
Submission link: [email protected]
Contact Us: [email protected]
Tesia Dobrydnia brings her many talents to her career as a chemical engineer in the oil and gas industry. With the same enthusiasm she puts into her work, she engages in hobbies and activities including watching movies and television shows, reading, backpacking, and snowboarding. She is a Relief Senior Engineer for Chevron and has been employed by the company since 2007. Tesia is considered a leader in her industry and is known to for her grasp of relief design standards.
Bituminous binders are sticky, black substances derived from the refining of crude oil. They are used to bind and coat aggregate materials in asphalt mixes, providing cohesion and strength to the pavement.
This presentation provides a comprehensive overview of a specialized test rig designed in accordance with ISO 4548-7, the international standard for evaluating the vibration fatigue resistance of full-flow lubricating oil filters used in internal combustion engines.
Key features include:
"The Enigmas of the Riemann Hypothesis" by Julio ChaiJulio Chai
In the vast tapestry of the history of mathematics, where the brightest minds have woven with threads of logical reasoning and flash-es of intuition, the Riemann Hypothesis emerges as a mystery that chal-lenges the limits of human understanding. To grasp its origin and signif-icance, it is necessary to return to the dawn of a discipline that, like an incomplete map, sought to decipher the hidden patterns in numbers. This journey, comparable to an exploration into the unknown, takes us to a time when mathematicians were just beginning to glimpse order in the apparent chaos of prime numbers.
Centuries ago, when the ancient Greeks contemplated the stars and sought answers to the deepest questions in the sky, they also turned their attention to the mysteries of numbers. Pythagoras and his followers revered numbers as if they were divine entities, bearers of a universal harmony. Among them, prime numbers stood out as the cornerstones of an infinite cathedral—indivisible and enigmatic—hiding their ar-rangement beneath a veil of apparent randomness. Yet, their importance in building the edifice of number theory was already evident.
The Middle Ages, a period in which the light of knowledge flick-ered in rhythm with the storms of history, did not significantly advance this quest. It was the Renaissance that restored lost splendor to mathe-matical thought. In this context, great thinkers like Pierre de Fermat and Leonhard Euler took up the torch, illuminating the path toward a deeper understanding of prime numbers. Fermat, with his sharp intuition and ability to find patterns where others saw disorder, and Euler, whose overflowing genius connected number theory with other branches of mathematics, were the architects of a new era of exploration. Like build-ers designing a bridge over an unknown abyss, their contributions laid the groundwork for later discoveries.
UNIT-4-PPT UNIT COMMITMENT AND ECONOMIC DISPATCHSridhar191373
Statement of unit commitment problem-constraints: spinning reserve, thermal unit constraints, hydro constraints, fuel constraints and other constraints. Solution methods: priority list methods, forward dynamic programming approach. Numerical problems only in priority list method using full load average production cost. Statement of economic dispatch problem-cost of generation-incremental cost curve –co-ordination equations without loss and with loss- solution by direct method and lamda iteration method (No derivation of loss coefficients)
UNIT-5-PPT Computer Control Power of Power SystemSridhar191373
Introduction
Conceptual Model of the EMS
EMS Functions and SCADA Applications.
Time decomposition of the power system operation.
Open Distributed system in EMS
OOPS
This research presents a machine learning (ML) based model to estimate the axial strength of corroded RC columns reinforced with fiber-reinforced polymer (FRP) composites. Estimating the axial strength of corroded columns is complex due to the intricate interplay between corrosion and FRP reinforcement. To address this, a dataset of 102 samples from various literature sources was compiled. Subsequently, this dataset was employed to create and train the ML models. The parameters influencing axial strength included the geometry of the column, properties of the FRP material, degree of corrosion, and properties of the concrete. Considering the scarcity of reliable design guidelines for estimating the axial strength of RC columns considering corrosion effects, artificial neural network (ANN), Gaussian process regression (GPR), and support vector machine (SVM) techniques were employed. These techniques were used to predict the axial strength of corroded RC columns reinforced with FRP. When comparing the results of the proposed ML models with existing design guidelines, the ANN model demonstrated higher predictive accuracy. The ANN model achieved an R-value of 98.08% and an RMSE value of 132.69 kN which is the lowest among all other models. This model fills the existing gap in knowledge and provides a precise means of assessment. This model can be used in the scientific community by researchers and practitioners to predict the axial strength of FRP-strengthened corroded columns. In addition, the GPR and SVM models obtained an accuracy of 98.26% and 97.99%, respectively.
This presentation provides a comprehensive overview of air filter testing equipment and solutions based on ISO 5011, the globally recognized standard for performance testing of air cleaning devices used in internal combustion engines and compressors.
Key content includes:
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdfMedicoz Clinic
Kevin Corke, a respected American journalist known for his work with Fox News, has always kept his personal life away from the spotlight. Despite his public presence, details about his spouse remain mostly private. Fans have long speculated about his marital status, but Corke chooses to maintain a clear boundary between his professional and personal life. While he occasionally shares glimpses of his family on social media, he has not publicly disclosed his wife’s identity. This deep dive into his private life reveals a man who values discretion, keeping his loved ones shielded from media attention.
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...gerogepatton
The International Journal of Artificial Intelligence & Applications (IJAIA) is a bi monthly open access peer-reviewed journal that publishes articles which contribute new results in all areas of the Artificial Intelligence & Applications (IJAIA). It is an international journal intended for professionals and researchers in all fields of AI for researchers, programmers, and software and hardware manufacturers. The journal also aims to publish new attempts in the form of special issues on emerging areas in Artificial Intelligence and applications.
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...ManiMaran230751
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – Investigation Methods for
Collecting Digital Evidence – International Cooperation to Collect Digital Evidence.
Pruebas y Solucion de problemas empresariales en redes de Fibra OpticaOmarAlfredoDelCastil
OOPs & Inheritance Notes
1. By- Shalabh Chaudhary [GLAU]
OOPs + INHERITANCE
OOP Object Oriented Programming is a programming paradigm which
uses "Objects" consisting of data fields and methods together with their
interactions.
Classes and Objects
A class contains variable declarations and method definitions.
Variable declared inside method – Local Variable.
Variable declared inside class & outside method – Instance Variable.
Variables with method declarations - parameters or arguments. Mthd(int var/arg){}.
Class Variable – Can be static.
Local Variable – Can’t be static.
Objects and References
All other types, except 8 primitive data type, refers to objects.
Variables that refers to objects are reference variables.
Once class is defined, you can declare a variable(object reference) of type class.
Student stud1;
Employee emp1;
NOTE: Both stud1 and emp1 are objects or reference var but not object of
Student/Employee class, it only holds reference of new object created.
The new operator is used to create an object of that reference type
Employee emp = new Employee(); // Employee() – object.
Object references are used to store objects.
The new operator,
Dynamically allocates memory for an object
Creates the object on the heap
Returns a reference to it - The reference is then stored in the variable.
Constructors
Constructor is automatically invoked whenever an object of the class is created.
Used to initialize instance variables.
Rules to Define Constructor -
A constructor has the same name as the class name.
Should not have a return type.
Can be defined with any access specifier (like private, public).
A class can contain more than one constructor, So it can be overloaded.
2. By- Shalabh Chaudhary [GLAU]
Eg.:
public class Sample {
private int id;
Sample() {
id = 101;
System.out.println("Default constructor,with ID: "+id);
}
Sample(int no){
id = no;
System.out.println("One arg constructor,withID: "+ id);
}
}
public class ConstDemo{
public static void main(String[] args) {
Sample s1 = new Sample();
Sample s2 = new Sample(102);
}
}
Output - Default constructor,with ID: 101
One argument constructor,with ID: 102
this reference keyword
Each class member funct contains an implicit reference of its class type, named this.
this reference is created automatically by compiler.
It contains the address of the object through which the function is invoked.
Use of this keyword.
To refer instance var when there is clash with local var or method arguments.
Used to call overloaded constructors from another constructor of same class.
Use this.variableName to explicitly refer to instance variable.
The this reference is implicitly used to refer to instance variables and methods.
It CANNOT be used in a static method.
Ex1: void setId(intid) {
this.id = id;
}
Ex2: class Sample{
Sample(){
this("Java"); // calls overloaded constructor
System.out.println("Default constructor ");
}
Sample(String str){
System.out.println("One argument constructor "+ str);
}
}
3. By- Shalabh Chaudhary [GLAU]
Static Class Members
Static class members are members of class that don’t belong to instance of a class.
We can access static members directly by prefixing the members with class name
ClassName.staticVariable
ClassName.staticMethod(...)
Static variables:
Shared among all objects of the class.
Only one copy exists for the entire class to use.
Static methods :
Static methods can only access directly the static members and manipulate a
class’s static variables.
Static methods cannot access non-static members(instance variables or
instance methods) of the class.
Static method can’t access this and super references.
Eg.:
class StaticDemo {
private static inta = 0;
private int b;
public void set ( int i, int j) {
a = i; b = j;
}
public void show() {
System.out.println("This is static a: " + a );
System.out.println( "This is non-static b: " + b );
}
public static void main(String args[]) {
StaticDemox = new StaticDemo();
StaticDemoy = new StaticDemo();
x.set(1,1);
x.show();
y.set(2,2);
y.sow();
x.show();
}
}
Output: This is static a: 1
This is non-static b: 1
This is static a: 2
This is non-static b: 2
This is static a: 2
This is non-static b: 1
QQ. Why is main() method static ?
4. By- Shalabh Chaudhary [GLAU]
OUTPUT BASED
class Sample{
int i_val;
public static void main(String[] xyz){
System.out.println("i_val is :"+ this.i_val);
}
}
>> Error: non-static variable this cannot be referenced from a static context
class Sample {
int i_val=10;
Sample(int i_val){
this.i_val=i_val;
System.out.println("inside Sample i_val: "+this.i_val);
}
public static void main(String[] xyz){
Sample o = new Sample();
}
}
>> Error: No default constructor created.
“static” Block
A block of code enclosed in braces, preceded by the keyword static.
Eg.:
static {
System.out.println(“Within static block”);
}
The statements within the static block are executed automatically when the class is
loaded into JVM.
They are executed in the order of their appearance in the class.
JVM combines all static blocks in a class as single static block and executes them.
class Sample{
public static void main(String[] xyz){
System.out.println("Inside main method line1");
}
static {
System.out.println("Inside class line1");
}
}
>> Inside class line1
Inside main method line1
5. By- Shalabh Chaudhary [GLAU]
***Create object of First class in Second class using new opr & run Second class print
something.
public class DefaultConstruct {
String name;
int roll;
void detail() {
System.out.println(name); // initialize null by default.
System.out.println(roll); // initialize to 0 by default.
}
public static void main(String[] args) {
DefaultConstruct d = new DefaultConstruct();
d.detail();
}
}
// >> constructor not defined then default constructor is created.
// >> Default constructor has no parameter it initializes instance var
to default values.
// >> // Can Define Constructor like –
DefaultConstruct (){ initialize values; }
Constructor v/s Method
Doesn’t have return type but Method has return type.
Called using new operator & Method called using (.) operator.
By default Method return type is private.
#1. Create a class Box that uses a parameterized method to initialize
the dimensions of a box.(dimensions are width, height, depth of double
type). The class should have a method that can return volume. Obtain
an object and print the corresponding volume in main() function.
>> Run as BoxVol.java
import java.util.Scanner;
class Box{
double width,height,depth; // Instance Variables
Box(double w,double h,double d) { // Constructor
width=w;
height=h;
6. By- Shalabh Chaudhary [GLAU]
depth=d;
}
double volume() { // Method-Volume
return width*depth*height;
}
}
public class BoxVol { // Main Class
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
double w=scan.nextInt();
double h=scan.nextInt();
double d=scan.nextInt();
Box b= new Box(w,h,d);
System.out.println("Volume is:"+b.volume());
}
}
#2. Create a new class called “Calculator” which contains the
following:
1. A static method called powerInt(int num1,int num2) that accepts two
integers and returns num1 to the power of num2 (num1 power num2).
2. A static method called powerDouble(double num1,int num2) that
accepts one double and one integer and returns num1 to the power of
num2 (num1 power num2).
3. Call your method from another class without instantiating the class
(i.e. call it like Calculator.powerInt(12,10) since your methods are
defined to be static)
Hint: Use Math.pow(double,double) to calculate the power.
>> Run As CalcPower.java
class Calculator{
static double powerInt(int num1,int num2) {
return Math.pow(num1,num2);
7. By- Shalabh Chaudhary [GLAU]
}
static double powerDouble(double num1,int num2) {
return Math.pow(num1,num2);
}
}
public class CalcPower {
public static void main(String[] args) {
System.out.println(Calculator.powerInt(12,10));
System.out.println(Calculator.powerDouble(12.5,10));
}
}
#3. Design a class that can be used by a health care professional to
keep track of a patient’s vital statistics. Here’s what the class
should do:
1. Construct a class called Patient
2. Store a String name for the patient
3. Store weight and height for patient as doubles
4. Construct a new patient using these values
5. Write a method called BMI which returns the patient’s BMI as a
double. BMI can be calculated as BMI = ( Weight in Pounds / ( Height
in inches x Height in inches ) ) x 703
6. Next, construct a class called “Patients” and create a main method.
Create a Patient object and assign some height and weight to that
object. Display the BMI of that patient.
>> Run as Patients.java
class Patient {
String name;
double weight,height;
Patient(double w,double h){
8. By- Shalabh Chaudhary [GLAU]
weight=w;
height=h;
}
double BMI() {
return (weight/(height*height))*703;
}
}
public class Patients{
public static void main(String[] args) {
Patient p=new Patient(75,156);
System.out.println("BMI is:"+p.BMI());
}
}
Encapsulation & Abstraction
Encapsulation = hiding implementation level details.
Abstraction = exposing only interface.
Access Specifiers
Access specifiers help implement:
Encapsulation by hiding implementation-level details in a class.
Abstraction by exposing only the interface of the class to the external world.
Implementation of Encapsulation & Abstraction -
class Point {
private int x;
private int y;
void setX( int x)
{
x = (x > 79 ? 79 : (x < 0 ? 0 :x)); // this.x=
}
void setY(int y)
{
y = (y > 24 ? 24 : (y < 0 ? 0 : y)); // this.y=
}
int getX()
9. By- Shalabh Chaudhary [GLAU]
{
return x;
}
int getY()
{
return y;
}
}
class PointDemo {
public static void main(String args[]) {
int a, b;
Point p = new Point();
p.setX(22);
p.setY(44);
System.out.println("The value of a is "+p.getX());
System.out.println("The value of b is "+p.getY());
}
}
>> Output: The value of a is 0
The value of b is 0
Use this.x & this.y in setX and setY mthd to get 22,44 as o/p.
#1. Create a class called Author is designed as follows:
It contains:
• Three private instance variables: name (String), email (String), and
gender (char of either ‘m’ or ‘f’).
• One constructor to initialize the name, email and gender with the
given values.
And, a class called Book is designed as follows:
It contains:
• Four private instance variables: name (String), author (of the class
Author you have just created), price (double), and qtyInStock (int).
Assuming that each book is written by one author.
• One constructor which constructs an instance with the values given.
• Getters and setters: getName(), getAuthor(), getPrice(), setPrice(),
getQtyInStock(), setQtyInStock(). Again there is no setter for name
and author.
Write the class Book (which uses the Author class written earlier).
Try:
10. By- Shalabh Chaudhary [GLAU]
1. Printing the book name, price and qtyInStock from a Book instance.
(Hint: aBook.getName())
2. After obtaining the “Author” object, print the Author (name, email
& gender) of the book.
>>
class Author {
public static String name,email;
public static char gender;
Author(String n,String e, char g){
name=n;
email=e;
gender=g;
}
}
class Book{
String name1,author;
double price;
int qtyInStock;
Book(String n1){
name1=n1;
}
void setQtyInStock() {
qtyInStock=10;
}
void setPrice() {
price=100.0;
}
double getPrice() {
return price;
}
11. By- Shalabh Chaudhary [GLAU]
int getQtyInStock() {
return qtyInStock;
}
String getName() {
return name1;
}
void getAuthor() {
System.out.println("Author is:"+Author.name);
System.out.println("Mail id is:"+Author.email);
System.out.println("Gender is:"+Author.gender);
}
}
public class Books{
public static void main(String args[]) {
Book b=new Book("Computer Networks");
Author a=new Author("amy","[email protected]",'f');
b.setPrice();
b.setQtyInStock();
System.out.println("The name of the book is :"+b.getName());
System.out.println("The price of the book is :"+b.getPrice());
System.out.println("The stock is :"+b.getQtyInStock());
b.getAuthor();
}
}
12. By- Shalabh Chaudhary [GLAU]
Inheritance
It allows for the creation of hierarchical classifications.
Each of these classes will add only those attributes & behaviors that are unique to it.
Super Class = class that is inherited. [ Base Class / Parent Class ]
Sub Class = class that does the inheriting. [ Derived Class / Extended Class / child class ]
Sub class inherits all properties of its superclass.
Basic building blocks of OOPs
Association = Relationship between two objects.
The association could be -
1. one-to-one
2. one-to-many
3. many-to-one
4. many-to-many
Types of Association –
Aggregation = A directional association between objects.
Also called a “Has-a” relationship.
Example: College has a Student Object.
Composition [Restricted Aggregation] = When an object contains other object,
if contained obj. can’t exist without existence of container obj, => compos
Example: A class contains students.
>> Student can’t exist without class.There exists composition b/w class & students.
Containership = Means using instance variables that refer to other objects.
Inheritance Model
Java uses Single inheritance model.
Single Inheritance
In single inheritance, a subclass can inherit from one(and only one) super class.
Syntax:
class derived-class-name extends base-class-name {
//code goes here
}
Eg.:
class A {
int m, n;
void display1( ) { System.out.println("m and n are:"+m+" "+n); }
}
class B extends A {
int c;
void display2() { System.out.println("c :"+ c); }
void sum() { System.out.println("m+n+c= "+ (m+n+c)); }
}
class Main {
13. By- Shalabh Chaudhary [GLAU]
public static void main(String args[ ]) {
A s1= new A(); // creating objects
B s2= new B();
s1.m= 10; s1.n= 20;
System.out.println("State of object A:");
s1.display1();
s2.m= 7;
s2.n= 8;
s2.c= 9;
System.out.println("State of object B:");
s2.display1();
s2.display2();
System.out.println("sum of m, n and c in object B is:");
s2.sum();
}
}
Accessing Superclass Members from a Subclass Object
A sub class includes all of the members of its super class.
But, it cannot directly access those members of the super class that
have been declared as private.
Eg.:
class A {
int money;
private int pocketMoney;
void fill(int money,int pocketMoney) {
this.money=money;
this.pocketMoney= pocketMoney;
}
}
class B extends A {
int total;
void sum( ) {
total = money + pocketMoney;
}
}
class AccessDemo { public static void main(String args[ ]) {
B subob= new B();
subob.fill(10,12);
subob.sum();
System.out.println("Total: " + subob.total);
}
}
14. By- Shalabh Chaudhary [GLAU]
Using super
When a subclass object is created, It creates the super class object.
The constructors of the super class are never inherited by the subclass.
super keyword is used ->
1. To differentiate the members of superclass from the members of subclass, if
they have same names.
2. To invoke the superclass constructor from subclass.
Eg.:
package mypack;
class Employee{
int Employeeno;
String Empname;
Employee() {
System.out.println(" Employee No-argConstructor Begins");
Employeeno=0;
Empname= null;
System.out.println(" Employee No-argConstructor Ends");
}
Employee(int Employeeno) {
System.out.println(" Employee 1-arg Constructor Begins");
this.Employeeno=Employeeno;
this.Empname= "UNKNOWN";
System.out.println(" Employee 1-arg Constructor Ends");
}
Employee(int Employeeno, String s) {
System.out.println(" Employee 2-arg Constr Begins");
this.Employeeno= Employeeno;
this.Empname= s;System.out.println("Emp 2-arg Constr Ends");
}
void display(){
System.out.println(" Employee Number = "+Employeeno);
System.out.println(" Employee Name = "+Empname);
}
}
class Manager extends Employee {
String deptname;
Manager(int Employeeno, String name, String deptname){
super(Employeeno, name);
System.out.println(" Manager 3-arg Constr Begins");
this.deptname= deptname;
System.out.println(" Manager 3-arg Construct Ends");
}
void display(){
super.display();
System.out.println(" Deptname= "+deptname);
}
15. By- Shalabh Chaudhary [GLAU]
public static void main( String a[]) {
System.out.println(" [Main function Begins---] ");
System.out.println("Creating object for manager class");
Manager mm = new Manager(10,"Gandhi","Banking");
System.out.println(" Printintthe manager details: ");
mm.display();
System.out.println(" [Main function Ends----]");
}
}
Using super to Call Superclass Constructors
super() - Always be the first statement executed inside a subclass constructor.
- Tells order of invocation of constructors in a class hierarchy.
Constructors in a class hierarchy are invoked in the order of their derivation.
Using this() in a constructor
this(arg_ list) stmt invokes the constructor of the same class.
First line of a constructor must EITHER be a super(call on the super class
constructor) OR a this(call on the constructor of same class).
If the first statement within a constructor is NEITHER super() NOR this(), then
compiler will automatically insert a super(). [ i.e., invocation to the super class no
argument constructor].
OUTPUT BASED
class A1 {
A1() {
System.out.println("A1's no arg constructor");
}
A1(int a) {
System.out.println("A1's constructor "+ a);
}
}
class B1 extends A1 {
B1(){
System.out.println("B1's no arg constructor");
}
B1(int b){
super(1000);
System.out.println("B1's constructor "+ b);
}
}
class C1 extends B1{
C1() {
16. By- Shalabh Chaudhary [GLAU]
System.out.println("C1's no arg constructor");
}
C1(int c){
super(100);
System.out.println("C1's constructor "+ c);
}
}
class TestingInheritance{
public static void main(String args[]){
C1 ca = new C1();
}
}
>> Output:
A1's no arg constructor
B1's no arg constructor
C1's no arg constructor
class A1 {
A1(){
System.out.println("A1's no arg constructor");
}
A1(int a) {
System.out.println("A1's constructor "+ a);
}
}
class B1 extends A1{
B1(){
System.out.println("B1's no arg constructor");
}
B1(int b){
super(1000);
System.out.println("B1's constructor "+ b);
}
}
class C1 extends B1{
C1() {
System.out.println("C1's no arg constructor");
}
C1(int c){
super(100);
System.out.println("C1's constructor "+ c);
}
}
class TestingInheritance {
public static void main(String args[]){
C1 ca = new C1(10);
17. By- Shalabh Chaudhary [GLAU]
}
}
>> Output:
A1's constructor 1000
B1's constructor 100
C1's constructor 10
class A1 {
A1(){
System.out.println("A1's no arg constructor");
}
A1(int a){
System.out.println("A1's constructor "+ a);
}
}
class B1 extends A1{
B1(){
System.out.println("B1's no arg constructor");
}
B1(int b){
super(1000);
System.out.println("B1‘s constructor "+ b);
}
}
class C1 extends B1{
C1() {
System.out.println("C1's no arg constructor");
}
C1(int c){
System.out.println("C1's constructor "+ c);
}
}
class TestingInheritance{
public static void main(String args[]){
C1 ca = new C1(10);
}
}
>> Output- A1's no arg constructor
B1's no arg constructor
C1's constructor 10
class A1 {
A1(){
System.out.println("A1's no arg constructor");
}
A1(int a){
18. By- Shalabh Chaudhary [GLAU]
System.out.println("A1's constructor "+ a);
}
}
class B1 extends A1{
B1(){
System.out.println("B1's no arg constructor");
}
B1(int b){
System.out.println("B1‘s constructor "+ b);
}
}
class C1 extends B1{
C1() {
super(100);System.out.println("C1's no arg constructor");
}
C1(int c){
System.out.println("C1's constructor "+ c);
}
}
class TestingInheritance{
public static void main(String args[]){
C1 ca = new C1(10);
}
}
>> Output: A1's no arg constructor
B1's no arg constructor
C1's constructor 10
class A1 {
A1(){
System.out.println("A1's no arg constructor");
}
A1(int a){
System.out.println("A1's constructor "+ a);
}
}
class B1 extends A1{
B1(){
super(50);
System.out.println("B1's no arg constructor");
}
B1(int b){
super(1000);
System.out.println("B1‘s constructor "+ b);
}
19. By- Shalabh Chaudhary [GLAU]
}
class C1 extends B1{
C1() {
System.out.println("C1's no arg constructor");
}
C1(int c){
System.out.println("C1's constructor "+ c);
}
}
class TestingInheritance{
public static void main(String args[]){
C1 ca = new C1(10);
}
}
>> Output- A1's constructor 50
B1's no arg constructor
C1's constructor 10
class A1 {
A1(){
System.out.println("A1's no arg constructor");
}
A1(int a){
System.out.println("A1's constructor "+ a);
}
}
class B1 extends A1{
B1(){
System.out.println("B1's no arg constructor");
}
B1(int b){
this("x");
System.out.println("B1's constructor "+ b);
}
B1(String b){
super(1000);
System.out.println("B1's constructor "+ b);
}
}
class C1 extends B1{
C1() {
System.out.println("C1's no arg constructor");
}
C1(int c){
super(100);
System.out.println("C1's constructor "+ c);
20. By- Shalabh Chaudhary [GLAU]
}
}
class TestingInheritance {
public static void main(String args[]){
C1 ca = new C1(10);
}
}
>> Output: A1's constructor 1000
B1's constructor x
B1's constructor 100
C1's constructor 10
Multilevel Hierarchy
A derived class will be inheriting a base class and as well as the derived class also
act as the base class to other class.
class student
{
int rollno;
String name;
student(int r, String n)
{
rollno = r;
name = n;
}
void dispdatas()
{
System.out.println("Rollno = " + rollno);
System.out.println("Name = " + name);
}
}
class marks extends student
{
int total;
marks(int r, String n, int t)
{
super(r,n); //call super class (student) constructor
total = t;
}
21. By- Shalabh Chaudhary [GLAU]
void dispdatam()
{
dispdatas(); // call dispdatap of student class
System.out.println("Total = " + total);
}
}
class percentage extends marks
{
int per;
percentage(int r, String n, int t, int p)
{
super(r,n,t); //call super class(marks) constructor
per = p;
}
void dispdatap()
{
dispdatam(); // call dispdatap of marks class
System.out.println("Percentage = " + per);
}
}
class Multi_Inhe
{
public static void main(String args[])
{
percentage stu = new percentage(102689, "VINEETH", 350, 70); //call
constructor percentage
stu.dispdatap(); // call dispdatap of percentage class
}
}
22. By- Shalabh Chaudhary [GLAU]
Hierarchical Inheritance
one class serves as a superclass (base class) for more than one sub class.In below
image, the class A serves as a base class for the derived class B,C and D.
class A {
public void methodA() {
System.out.println("Class A Mthd");
}
}
class B extends A {
public void methodB(){
System.out.println("Class B Mthd");
} }
class C extends A {
public void methodC() {
System.out.println("method of Class C");
}
}
class D extends A {
public void methodD() {
System.out.println("method of Class D");
}
}
class HierarchInheritance {
public static void main(String args[]) {
B obj1 = new B();
C obj2 = new C();
D obj3 = new D();
//All classes can access the method of class A
obj1.methodA();
obj2.methodA();
obj3.methodA();
}
}
Java does NOT Support Multiple Inheritance with classes.
23. By- Shalabh Chaudhary [GLAU]
Multiple Inheritance [Through Interfaces]
One class can have more than one superclass and inherit features from all parent
classes.
interface PI1 {
// default method
default void show() {
System.out.println("Default PI1");
}
}
interface PI2 {
// Default method
default void show() {
System.out.println("Default PI2");
}
}
// Implementation class code
class TestClass implements PI1, PI2 {
// Overriding default show method
public void show() {
// use super keyword to call the show
// method of PI1 interface
PI1.super.show();
// use super keyword to call the show
// method of PI2 interface
PI2.super.show();
}
public static void main(String args[]) {
TestClass d = new TestClass();
d.show();
}
}
Hybrid Inheritance [Through Interfaces]
It is a mix of two or more of the above types of inheritance.
public class ClassA {
public void dispA(){
System.out.println("Class A Mthd");
}
}
public interface InterfaceB {
public void show();
}
24. By- Shalabh Chaudhary [GLAU]
public interface InterfaceC {
public void show();
}
public class ClassD implements InterfaceB,InterfaceC {
public void show() {
System.out.println("show() method implementation");
}
public void dispD() {
System.out.println("disp() method of ClassD");
}
public static void main(String args[]) {
ClassD d = new ClassD();
d.dispD();
d.show();
}
}
#1. Create a class named ‘Animal’ which includes methods like eat()
and sleep().
Create a child class of Animal named ‘Bird’ and override the parent
class methods. Add a new method named fly().
Create an instance of Animal class and invoke the eat and sleep
methods using this object. Create an instance of Bird class and invoke
the eat, sleep and fly methods using this object.
>>
class Animal {
void eat() {
System.out.println("eat Mthd");
}
void sleep() {
System.out.println("sleep Mthd");
}
}
class Bird extends Animal{
@Override
void eat() {
System.out.println("Override eat Mthd");
25. By- Shalabh Chaudhary [GLAU]
}
void sleep() {
System.out.println("Override sleep Mthd");
}
void fly() {
System.out.println("fly method");
}
}
class AnimalsDemo{
public static void main(String args[]) {
Animal a = new Animal();
Bird b= new Bird();
a.eat();
a.sleep();
b.eat();
b.sleep();
b.fly();
}
}
#2. Create class called Person with a member variable name. Save it in
file called Person.java
Create a class called Employee who will inherit the Person class.The
other data members of the employee class are annual salary (double),
the year the employee started to work, and the national insurance
number which is a String. Save this in a file called Employee.java
Your class should have a reasonable number of constructors and
accessor methods.
Write another class called TestEmployee, containing a main method to
fully test your class definition.
>> Person.java
public class Person {
private String name;
26. By- Shalabh Chaudhary [GLAU]
public Person(String n){
name=n;
}
public void setName(String n) {
name=n;
}
public String getName() {
return name;
}
public String toString(){
return name;
}
}
----x----x----x----
Employee.java
public class Employee extends Person {
private double annual_salary;
private int emp_yr;
private String insurance_no;
public Employee(String n,double a, int y, String i){
super(n);
annual_salary=a;
emp_yr=y;
insurance_no=i;
}
public void setSalary(double a) {
annual_salary=a;
}
public void setYear(int y) {
27. By- Shalabh Chaudhary [GLAU]
emp_yr=y;
}
public void setInsurance_no(String i) {
insurance_no=i;
}
public double getSalary() {
return annual_salary;
}
public int getYear() {
return emp_yr;
}
public String getInsurance_no() {
return insurance_no;
}
public String toString() {
return super.toString()+" "+annual_salary+" "+emp_yr+"
"+insurance_no;
}
}
----x----x----x----
TestEmployee.java
public class TestEmployee {
public static void main(String[] args) {
Person p= new Person("Anil");
Employee e=new Employee("Jim",10000, 2015, "abcd");
System.out.println(p);
System.out.println(e);
}
}
28. By- Shalabh Chaudhary [GLAU]
Method Overriding [ Polymorphism ]
When a method in a subclass has the same prototype as a method in the
superclass, then the method in the subclass is said to override the method in the
super class.
Same prototype - Means has the same name, type signature (the same type,
sequence and number of parameters), and the same return type as the method
in its super class.
class A {
int a,b;
A(int m, int n) {
a = m;
b = n;
}
void display() {
System.out.println("a and b are: "+a+" "+b);
}
}
class B extends A {
int c;
B(int m, int n, int o) {
super(m,n);
c = o;
}
void display() {
System.out.println("c :" + c);
}
}
class OverrideDemo {
public static void main(String args[]) {
B subOb= new B(4,5,6);
subOb.display();
}
}
>> Output- c:6
// display() inside B overrides display declared in its superclass, i.e., class A.
29. By- Shalabh Chaudhary [GLAU]
Using super to Call an Overridden Method
class A {
int a,b;
A(int m, int n) {
a = m;
b = n;
}
void display() {
System.out.println("a and b are :"+a+" "+b);
}
}
class B extends A {
int c;
B(int m, int n, int o) {
super(m,n);
c = o;
}
void display() {
super.display();
System.out.println("c :" + c);
}
}
class OverridewithSuper {
public static void main(String args[]) {
B subOb= new B(4,5,6);
subOb.display();
}
}
>> Output- a and b are: 4 5
c: 6
// Method overriding occurs only when the names and the type signatures of two
methods across atleast two classes (i.e., a superclass and a subclass) in a class
hierarchy are identical.
If they are not, then the two methods are simply overloaded.
30. By- Shalabh Chaudhary [GLAU]
Superclass Reference Variable
A reference variable of type superclass can be assigned a reference to any subclass
object derived from that super class.
class A1{ }
class A2 extends A1{ }
class A3 {
public static void main(String[]args) {
A1 x;
A2 z=newA2();
x=new A2(); //valid
z=new A1(); //invalid
}
}
Superclass Reference Variable Can Reference a Subclass Object
Method calls in java are resolved dynamically at runtime.
Rules for Method Overriding
Must have the same argument list.
Must have the same return type.
Must not have a more restrictive access modifier
May have a less restrictive access modifier
Must not throw new or broader checked exceptions
May throw fewer or narrower checked exceptions or any unchecked exceptions.
Final methods cannot be overridden.
Constructors cannot be overridden.
OUTPUT BASED
class A1 {
void m1() {
System.out.println("In method m1 of A1");
}
}
class A2 extends A1 {
int m1() {
return 100;
}
public static void main(String[] args) {
A2 x = new A2();
x.m1();
}
}
// Error: m1() in A2 cannot override m1() in A1.
31. By- Shalabh Chaudhary [GLAU]
QQ. Why Overridden Methods ?
Ans: So, that subclass will override the method in superclass.
Dynamic Method Dispatch [ Runtime Polymorphism ]
Occurs when the Java language resolves a call to an overridden method at
runtime, and, in turn, implements runtime polymorphism.
Mechanism by which a call to an overridden method is resolved at run time,
rather than compile time.
Run time polymorphism possible in class hierarchy with the help of its features:
1. Overridden Methods.
2. Super class Reference variables. - Can hold reference to subclass object.
When an overridden method is called through a super class reference, Java
determines which method to call based upon the type of the object being referred
to at the time the call occurs.
class Figure{
double dimension1; double dimension2;
Figure(double x,double y){
dimension1=x; dimension2=y;
}
double area(){
System.out.println("Area of Figure is undefined");
return 0;
}
}
class Rectangle extends Figure{
Rectangle(double x,double y){
super(x,y);
}
double area() { //method overriding
System.out.print("Area of rectangle is :");
return dimension1 * dimension2;
}
}
class Triangle extends Figure {
Triangle(double x, double y) {
super(x,y);
}
double area() { //method overriding
System.out.print("Area for triangle is :");
return dimension1 * dimension2 / 2;
}
}
class FindArea {
public static void main(String args[]) {
32. By- Shalabh Chaudhary [GLAU]
Figure f=new Figure(10,10);
Rectangle r= new Rectangle(9,5);
Triangle t= new Triangle(10,8);
Figure fig; //reference variable
fig=r;
System.out.println("Area of rect is:"+fig.area());
fig=t;
System.out.println("Area of triangle is:"+fig.area());
fig=f;
System.out.println(fig.area());
}
}
instanceof Operator
Use of instance of operator :
Allows to determine the type of an object.
Compares an object with a specified type.
Takes an object and a type and returns true if object belongs to that type &
returns false otherwise.
Used to test if an object is an instanceof a class, an instanceof a subclass, or an
instanceof a class that implements an interface.
class A { int i, j;
}
class B extends A {
int a, b;
}
class C extends A {
int m, n;
}
class instanceOf{
public static void main(String args[]) {
A a= new A( );
B b= new B( );
C c= new C( );
A ob=b;
if (ob instanceof B)
System.out.println("ob now refers to B");
else
System.out.println("Ob is not instance of B");
if (ob instanceof A)
System.out.println("ob is also instance of A");
else
System.out.println("Ob is not instance of A");
if (ob instanceof C)
33. By- Shalabh Chaudhary [GLAU]
System.out.println("ob now refers to C");
else
System.out.println("Ob is not instance of C");
}
}
The Cosmic Class – The Object Class
Available in java.lang package
Object is superclass of all other classes; i.e., Java’s own classes, as well as
user-defined classes.
This means that a reference variable of type Object can refer to an object of any
other class.
#1. Create a base class Fruit which has name ,taste and size as its
attributes. A method called eat() is created which describes the name
of the fruit and its taste. Inherit the same in 2 other class Apple
and Orange and override the eat() method to represent each fruit
taste.
>>
class Fruit {
String name,taste,size;
Fruit(String n,String t,String s) {
name=n;
taste=t;
size=s;
}
void eat() {
System.out.println(name+" "+taste);
}
}
class Apple extends Fruit{
Apple(String n, String t, String s) {
super(n, t, s);
}
@Override
34. By- Shalabh Chaudhary [GLAU]
void eat() {
System.out.println(name+" "+taste);
}
}
class Orange extends Fruit{
Orange(String n, String t, String s) {
super(n, t, s);
}
@Override
void eat() {
System.out.println(name+" "+taste);
}
}
public class FruitCheck{
public static void main(String args[]) {
Apple a= new Apple("Apple","Sweet","Heart");
Orange o=new Orange("Orange","Sour","Round");
a.eat();
o.eat();
}
}
#2. Write a program to create a class named shape. It should contain 2
methods- draw() and erase() which should print “Drawing Shape” and
“Erasing Shape” respectively.
For this class we have three sub classes- Circle, Triangle and Square
and each class override the parent class functions- draw() & erase().
The draw() method should print “Drawing Circle”, “Drawing Triangle”,
“Drawing Square” respectively.
The erase() method should print “Erasing Circle”, “Erasing Triangle”,
“Erasing Square” respectively.
35. By- Shalabh Chaudhary [GLAU]
Create objects of Circle, Triangle and Square in the following way and
observe the polymorphic nature of the class by calling draw() and
erase() method using each object.
Shape c=new Circle();
Shape t=new Triangle();
Shape s=new Square();
>>
class Shape {
void draw() {
System.out.println("Drawing Shape");
}
void erase() {
System.out.println("Erasing Shape");
}
}
class Circle extends Shape{
@Override
void draw() {
System.out.println("Drawing Circle");
}
void erase() {
System.out.println("Erasing Circle");
}
}
class Triangle extends Shape{
@Override
void draw() {
System.out.println("Drawing Triangle");
}
void erase() {
System.out.println("Erasing Triangle");
37. By- Shalabh Chaudhary [GLAU]
Garbage Collection
Once the program completes, These objects become garbage...
Java’s Cleanup Mechanism – The Garbage Collector :
Java has its own Garbage Collector
Test test=new Test(); // Obj. test created & memory allocated for this obj.
test=null; When you execute this, the reference is deleted but the memory
occupied by the object is not released.
To release the memory occupied by the ‘test ’object -
Objects on the heap must be deallocated or destroyed, and their memory
released for later reallocation.
Java handles object deallocation automatically through garbage collection.
The Garbage Collection is done automatically by JVM.
To manually do the garbage collection, Use method:
Runtime rs= Runtime.getRuntime();
rs.gc();
>> gc() method is used to manually run the garbage collection.
The rs.freeMemory() method - Give free memory available in the system.
The finalize() Method
Using finalization, can define specific actions that will occur when an object is just
about to be reclaimed by the garbage collector.
Inside finalize() method, specify actions that must be performed before object is
destroyed.
Java runtime calls this method whenever it’s about to recycle an object of class.
Eg.:
public class CounterTest{
public static int count;
public CounterTest( ) {
count++;
}
public static void main(String args[ ]) {
CounterTest ob1 = new CounterTest( ) ;
System.out.println("Number of objects :" + CounterTest.count) ;
CounterTest ob2 = new CounterTest( );
Runtime r = Runtime.getRuntime( );
ob1 = null;
ob2 = null;
r.gc( );
38. By- Shalabh Chaudhary [GLAU]
}
protected void finalize( ) {
System.out.println("Program about to terminate");
CounterTest.count--;
System.out.println("Number of objects :" + CounterTest.count) ;
}
}
>> Output: Number of objects: 1
Number of objects: 2
Program about to terminate
Number of objects: 1
Program about to terminate
Number of objects: 0
The class A3 cannot be subclass of the final class A2.
Cannot override the final method from parent class A1.
String and StringBuffer
String is a group of characters.They are objects of type String
Strings are Immutable – Once obj. created CAN’T be changed.
To get changeable strings use the class called StringBuffer.
String and StringBuffer classes are declared as final,
So, there CAN NOT be sub classes of these classes.
The default constructor creates an empty string.
String s=new String();
Handling Strings:
String str = "abc"; // Empty String String str = "";
Is equivalent to:
char data[] = {'a', 'b', 'c'};
>> If data array in the above is modified after the string object str is created, then str
remains unchanged.
String Creation using new Keyword:
String str1 = new String("abc");
String str2 = new String("abc");
If(str1==str2) // true same String objects reference are not same.
String class Methods:
str.length() – System.out.println("shalabh".length() ) // Prints 7
or int len = str.length();
str1+str2 operator – Concatenate 2 or more Strings.
39. By- Shalabh Chaudhary [GLAU]
System.ot.println(str1+str2); // str1 and str2 are 2 strings.
str.charAt(i) - Retrieve Character in a String.
char c = str.charAt(1); // Prints b if str = "abc";
str1.equals(str2) – Returns true if 2 strings are same.
or
>> str1==str2 – Returns true if both string matched. str obj. reference is same
str1.equalsIgnoreCase(str2) – Returns true if 2 string are same even case not
matched in both strings.
str1.startsWith(str2) – Tests if string start with specified prefix.
"January".startsWith("Jan"); // true
str1.endsWith(str2) – Tests if string ends with specified suffix.
"December".endsWith("ber"); // true
str1.compaerTo(str2) – Checks string is bigger or smaller.
returns -ve integer if str1 < str2
returns +ve integer if str1 > str2
returns 0 if str1 = str2
Eg.: "Hel".compareToIgnoreCase("hello") // Prints -2 (differ by strings)
"Hel".compare("hello") // Prints -32 (H to h differ by -32)
str1.indexOf(str2) – Searches for first Occurrence of character or substring.
"Hello".indexOf("l") // Prints 2 i.e., 2nd
index.
returns -1 if character or string not occurs.
str1.indexOf(str2, fromIndex) – Search character ch within string & return
index of first occurrence of this character start from pos fromIndex.
Eg.: String str="How was your day today?";
str.indexOf('a',6); // Prints 14 (at 14th
index a prsnt)
str.indexOf("was", 2); // Prints 4 (from 4th
index “was” starts)
str1.lastIndexOf(str2) - Searches last occurrence of particular string or character
str1.substring(beginIndex, endIndex) – Returns new string which is substring
of string str1
Eg.: "Unhappy".substring(2) // Prints happy.
"Smiles".substring(1,5) // Prints mile [ endIndex=5 i.e.,5-1= till 4th
]
str1.concat(str2) – Concatenate specified string(str2) to end of string.
"to".concat("get").concat("her") // Prints “together”
40. By- Shalabh Chaudhary [GLAU]
str1.replace(oldChar, newChar) – Return new string - replace oldChar with new
"Wipra Technalagies".replace('a', 'o')
>> Prints Wipro Technologies.
valueOf(ar) – Convert character array into string.
Result is string representation of argument passed as char array.
str1.toLoweCase() - "HELLO WORLD".toLowerCase();
str1.toUpperCase() - "hello world".toUpperCase();
StringBuffer
String Buffer class objects are mutable, so they can be modified.
StringBuffer sb = new StringBufer();
String Buffer class defines three constructors:
1. StringBuffer() //empty object
2. StringBuffer(int capacity) //creates empty obj with capacity for storing string
3. StringBuffer(String str) //createStringBufferobjectbyusingastring
StringBuffer Operations:
1. sb.append(str) - adds specified characters at end of StringBuffer object.
StringBuffer append(int index, char ch) // indx- pt. where str insrt.
2. sb.insert(indx, str) - To insert characters at specified index location.
StringBuffer insert(int index, String str)
>> Both methods are overloaded so they can accept any type of data.
3. sb.delete(startIndex, endIndex) - Delete specified substring in StringBuffer.
StringBuffer delete(int start, int end)
4. sb.replace() - Replace part of StringBuffer(substring) with another substring.
StringBuffer replace(int start, int end, String str)
5. sb.substring(startIndx, endIndx) - Return new string i.e., StringBuffer’s substr
String substring(int start) // prints endIndx-1
>> It extracts characters starting from the specified index till the end of the StringBuffer.
6. sb.reverse() - Character sequence is reversed.
7. sb.length() – To find length of StringBuffer.
8. sb.capacity() – To find capacity of StringBuffer.
>> Capacity - Amount of storage available for characters that have just been inserted.
41. By- Shalabh Chaudhary [GLAU]
9. sb.charAt(indx) – Find character at particular index position.
10. sb.deletecharAt(indx) – delete character at particular index.
Eg.: StringBuffer sb= new StringBuffer("Wipro Technologies");
String result = sb.substring(6); // only startIndex prst
System.out.println(result); // Prints Technologies
#1. Write a Program that will check whether a given String is
Palindrome or not
>>
import java.util.Scanner;
public class PalindromeString {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
String s=scan.nextLine();
StringBuffer sb=new StringBuffer(s);
sb.reverse();
if(s.equalsIgnoreCase(sb.toString()))
System.out.println("Palindrome");
else
System.out.println("Not Palindrome");
}
}
#2. Given two strings, append them together (known as "concatenation")
and return the result. However, if the concatenation creates a double-
char, then omit one of the chars. If the inputs are “Mark” and “Kate”
then the ouput should be “markate”. (The output should be in
lowercase)
>>
import java.util.Scanner;
public class AppendString {
42. By- Shalabh Chaudhary [GLAU]
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
String s1=scan.nextLine();
String s2=scan.nextLine();
if(s1.substring(s1.length()-1).equalsIgnoreCase( s2.substring(0,1)))
System.out.println(s1.concat(s2.substring(1,s2.length())));
else
System.out.println(s1.concat(s2).toLowerCase()); } }
#3. Given string, return new string made of n copies of first 2 chars
of the original string where n is the length of the string. The string
may be any length. If there are fewer than 2 chars, use whatever is
there.
If input is "Wipro" then output should be "WiWiWiWiWi".
>>
public class Copy2Chars{
static String charCopy(String s,int n) {
String res="";
if(n<2)
return s;
else {
s=s.substring(0,2);
while(n!=0) {
res=res.concat(s);
n--;
}
return res;
}
}
public static void main(String args[]) {
String s="Wipro";
int n=s.length();
43. By- Shalabh Chaudhary [GLAU]
System.out.print(charCopy(s,n));
}
}
#4. Given a string, if the first or last chars are 'x', return the
string without those 'x' chars, and otherwise return the string
unchanged. If the input is "xHix", then output is "Hi".
>>
public class Trimxx{
static String trim(String s,int n) {
if (n==1){
if (s.charAt(0) == 'x')
return "";
else
return s;
}
if(s.charAt(0)=='x' && s.charAt(n-1)=='x')
s=s.substring(1,n-1);
return s;
}
public static void main(String args[]) {
String s="xHix";
int n=s.length();
System.out.print(trim(s,n));
}
}
44. By- Shalabh Chaudhary [GLAU]
#5. Given two strings, word and a separator, return a big string made
of count occurrences of the word, separated by the separator string.
if the inputs are "Wipro","X" and 3 then the output is
"WiproXWiproXWipro".
>>
public class StringtillCount{
static String strCount(String s,int sep) {
String res="";
while(sep>0) {
res+=s.concat("X");
sep--;
}
res=res.substring(0,res.length()-1);
return res;
}
public static void main(String args[]) {
String s="Wipro";
int sep=3;
System.out.print(strCount(s,sep));
}
}
#6. Return a version of the given string, where for every star (*) in
the string the star and the chars immediately to its left and right
are gone. So "ab*cd" yields "ad" and "ab**cd" also yields "ad".
>>
public class RemoveStar{
static String rmvStr(String s) {
StringBuffer sb=new StringBuffer(s);
int i=s.indexOf('*');
int l=s.lastIndexOf('*');
return new String(sb.delete(i-1,l+2));
}
45. By- Shalabh Chaudhary [GLAU]
public static void main(String args[]) {
String s="ab**cd";
System.out.print(rmvStr(s));
}
}
#7. Given two strings, a and b, create a bigger string made of the
first char of a, the first char of b, the second char of a, the second
char of b, and so on. Any leftover chars go at the end of the result.
If the inputs are "Hello" and "World", then the output is
"HWeolrllod".
>>
public class AlternatePrint{
static String alter(String a,String b) {
String res="";
int alen=a.length();
int blen=b.length();
int len=Math.min(alen,blen);
int i=0;
while(i<len) {
res+=a.substring(i,i+1)+b.substring(i,i+1);
i++;
}
if(alen!=blen)
res+=b.substring(len);
if(blen!=alen)
res+=a.substring(len);
return res;
}
public static void main(String args[]) {
String a="Hello";
String b="World";
46. By- Shalabh Chaudhary [GLAU]
System.out.print(alter(a,b));
}
}
#8. Given a string and a non-empty word string, return a string made
of each char just before and just after every appearance of the word
in the string. Ignore cases where there is no char before or after the
word, and a char may be included twice if it is between two words.
If inputs are "abcXY123XYijk" and "XY", output should be "c13i".
If inputs are "XY123XY" and "XY", output should be "13".
If inputs are "XY1XY" and "XY", output should be "11".
>>
public class WordEnds {
static String wordAppear(String s, String w) {
int slen=s.length();
int wlen=w.length();
String res="";
for (int i=0;i<slen-wlen+1;i++) {
String tmp=s.substring(i,i+wlen);
if (i>0 && tmp.equals(w))
res+=s.substring(i-1,i);
if (i<slen-wlen && tmp.equals(w))
res+=s.substring(i+wlen,i+wlen+1);
}
return res;
}
public static void main(String args[]) {
String s="abcXY123XYijk";
String w="XY";
System.out.print(wordAppear(s,w));
}
}
47. By- Shalabh Chaudhary [GLAU]
INTERVIEW QUESTIONS
Q: Explain carefully what null means in Java, and why this special value is necessary.
Q: When do we declare a method or class as final explain with example?
Q: When do we declare the members of the class as static explain with example?
Q: Explain about inner classes with an example?
Q: Explain how super keyword is used in overriding the methods?
Q: Explain the use of super() method in invoking a constructor?
Q: When does a base class variable get hidden, Give reasons?
Q: Explain with an example how we can access a hidden base class variable?