Recursion: Method calling itself is known as recursion. Syntax: Ex 1: Factorial Output: 6 Ex 2: Sum of first 5 numbers Output: 15 Ex 3: Output: RRaRajRajiRajiiRajiRajRaR
Category Archives: Java
WRAPPER CLASS IN JAVA
WRAPPER CLASS: Java is an Object oriented programming language. So represent everything in the form of Objects. But java supports 8 – primitive data types, these are not objects. To represent 8 – primitive data types in the form of object, we required 8 java classes, these classes are called WRAPPER CLASS. So, Wrapper classContinue reading “WRAPPER CLASS IN JAVA”
LAMBDA EXPRESSIONS & FUNCTIONAL INTERFACE
Java – It supports OOPs & FP paradigm. Based on oops, Everything in java are objects, except primitive data types. We need object references to call any method. In Functional Programming, Purpose: Concise coding Do not need object creations. LAMBDA EXPRESSIONS: Lambda expression is a new feature which is introduced in Java 8. A lambdaContinue reading “LAMBDA EXPRESSIONS & FUNCTIONAL INTERFACE”
STRING IN JAVA
STRING: String is a sequence of characters surrounded by double quotes. String is a predefined class. In Java, all classes are considered as a non primitive data type. So, we can also consider a String as a non primitive data type. String is located in java.lang package. STRING IS A SPECIAL CLASS – WHY? String objectsContinue reading “STRING IN JAVA”
FREQUENCY OF EACH ELEMENT
Ex 1: OUTPUT: 10 occurs 2 times20 occurs 2 times30 occurs 2 times40 occurs 1 times50 occurs 1 times90 occurs 1 times Ex 2: Output: R occurs 1 timesa occurs 1 timesj occurs 1 timesi occurs 2 times
STRING METHODS
length( ) Length method is used to find total count of element in String. Output: India 5TamilNadu 9Tenkasi 7 isBlank( ) & isEmpty( ) If any method starts with is, then the method return data type is boolean. It returns true or false only. isBlank( ) return true: Inside the double quotation, Spaces are presentContinue reading “STRING METHODS”
TYPE CASTING IN JAVA
TYPE CASTING: Type casting is a way of converting data from one data type to another data type. This process of data conversion is also known as type conversion. Types: Widening or Implicit Up Casting Narrowing or Explicit down Casting Type casting is applicable for both primitive & non primitive data types. TYPE CASTING FORContinue reading “TYPE CASTING IN JAVA”
Who is winner in running competition? Players name in String array & Their running seconds in Integer array are given.
Output: Players Name & their running secondsGowsy – 50 secondsMehra – 40 secondsGokii – 25 secondsManju – 30 secondsLakshmi – 90 secondsNandhini – 75 seconds Winner:Gokii – 25 seconds First Runner Up:Manju – 30 seconds Second Runner Up:Mehra – 40 seconds
MATRIX IN JAVA
MATRIX ADDITION: Ex 1: Thinking level 1: Output: 10 12 1418 20 2220 12 24 Thinking level 2: Output: 10 12 1418 20 2220 12 24 Thinking level 3: final Output: 10 12 1418 20 2220 12 24 Ex 2: Using Scanner Class Output: Enter array size2Enter array1 value22334455Enter array2 value11213141Sum of array1 & array233Continue reading “MATRIX IN JAVA”
Basics – Two Dimensional Array in Java
INTRO: Click ARRAY to learn about that. A 2D array is an array of one-dimensional arrays. 2D array is a collection of data cells. 2D array is stored in the form of rows and columns and is represented in the form of a matrix. We can access it by row index and column index (likeContinue reading “Basics – Two Dimensional Array in Java”
BINARY SEARCH IN JAVA
BINARY SEARCH: Binary Search is one of the fastest searching algorithms. It is used for finding the location of an element in a linear array. It works on the principle of divide and conquer [கைப்பற்றும்] technique. Binary Search Algorithm can be applied only on Sorted arrays. To apply binary search on an unsorted array, First,Continue reading “BINARY SEARCH IN JAVA”
BUBBLE SORT IN JAVA
SORTING: Sorting is the process of arranging the elements of an array So that they can be placed in ascending or descending order. BUBBLE SORT: Bubble sort is a simple sorting algorithm. This sorting algorithm is comparison-based algorithm in which each pair of adjacent elements is compared and elements are swapped if they are notContinue reading “BUBBLE SORT IN JAVA”
DATA TYPES IN JAVA
What is data type? To store the data, we must allocate the space. Using data type, we can allocate the space. Data type defines the size and values that can be stored in the variable. Types: PRIMITIVE DATA TYPE Primitive data type is pre-defined by the programming language. There are 8 primitive data types suchContinue reading “DATA TYPES IN JAVA”
ARRAYS BASICS
ARRAYS: An array is a collection of similar data types. [Datatype -> Primitive & Non primitive] [We can create array for object class. Above line is not suitable for that. Will learn later about that]. Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. VariableContinue reading “ARRAYS BASICS”
toString( )
If we are trying to print the object, println method automatically called the toString method. toString( ) method is predefined method inside the Object class. Object class is the parent class of every class. toString( ) method returns String representation of hash code. packageName.className@hexaDecimalValueOfHashcode. Ex 1: OUTPUT: Print Sample Class Object1: SelfLearn.Sample@c2e1f26Print Sample Class Object2:Continue reading “toString( )”
HASHCODE
What is hashcode? hashCode method which is available in Object Class (In java, Object class is the parent class of every class). hashCode method returns unique integer for every objects. i.e., Human have unique aadhar number, Every object have unique hash code. hashCode method calling syntax: objectName.hashCode( ); Ex 1: Output: Print Hashcode for SampleContinue reading “HASHCODE”
Can we override static method?
Method Overriding: If the same method name is declared in both the superclass and the subclass, then the method of the sub class overrides the method of the superclass. This is known as method overriding. Ex 1: Output: Early Morning Study – Best Ex 2: Output: Group Study – Best Code Explanation: In Ex 1,Continue reading “Can we override static method?”
Private Constructor
PRIVATE CONSTRUCTOR: Private constructor is useful for restrict an object creation from outer class. Ex: If a class contain zero argument constructor as private, we can create zero argument object within the class. we can’t create zero argument object for that class from outside class. Ex 1: Without private constructor Output: Program1 – Constructor ExContinue reading “Private Constructor”
TeleApps Interview Qns – JAVA
1] Can We Overload main() method? A. Yes we can B. No we can’t ANSWER: A.YES WE CAN OUTPUT: We can overload the main method30SRajalakshmi 2] What is the output? A) -4,4B) -3,3C) -2,2D) -1,1 ANSWER: D) -1, 1 3] What is the output? A) 1020Hello Hello1020B) 30Hello Hello30C) 30Hello Hello1020D) 1020Hello Hello30 ANSWER: C)Continue reading “TeleApps Interview Qns – JAVA”
ARRAY SHIFTING
LEFT SIDE ARRAY SHIFT: Output: Before Left Shifting0 10 20 30 40 50 60 70 80 90 100After Left Shifting10 20 30 40 50 60 70 80 90 100 0 RIGHT SIDE ARRAY SHIFT: OUTPUT: Before Right Shifting0 10 20 30 40 50 60 70 80 90 100After Right Shifting100 0 10 20 30 40Continue reading “ARRAY SHIFTING”
LINEAR SEARCHING – ARRAY
What is searching? Searching is a process of finding a particular element among several given elements. The search is successful if the required element is found. Otherwise, the search is unsuccessful. Searching types: LINEAR SEARCH: Linear Search is the simplest searching algorithm. It searches the element by comparing it with each element of the arrayContinue reading “LINEAR SEARCHING – ARRAY”
Basics – Scanner, System.in, System.out.println()
SCANNER CLASS: Scanner class is used to get input from user. Scanner is a predefined class in java Scanner is a final class. We can’t inherited Scanner class. Import the scanner class: Scanner class presented in java.util package. We want to import the package, before using the scanner class. Create Scanner Object: Here, Scanner isContinue reading “Basics – Scanner, System.in, System.out.println()”
Print alphabet A to Z
Ex 1: Ex 2: Ex 3: Ex 4: Ex 5: Ex 6: Ex 7: Ex 8: Ex 9: Ex 10: Ex 11: Ex 12: Ex 13: Ex 14: Ex 15: Ex 16: Ex 17:
NUMBER PATTERN IN JAVA
EX 1: Ex 2: Ex 3: Ex 4: Ex 5: Ex 6: Ex 7: Ex 8: Ex 9: Ex 10: Ex 11: Ex 12: Ex 13: Ex 14: Ex 15: Ex 16: Ex 17: Ex 18:
For looping in java
Syntax: Explanation: For loop is another way of while loop. For loop process: Initialize the value (A) Check the condition (B) Print the statement (D) Increment or Decrement the value (C) Check the condition (B) Print the statement (D) Steps 4, 5, 6 are repeated. When the condition (B) is false, loop will be terminated.Continue reading “For looping in java”
ADAM NUMBER IN JAVA
Adam Number: Consider a number = 12. Reverse of a number = 21. Square of a number (12) = 144. Square of Reverse of number (21) = 441. Square of 12 & the square of its reverse 21 are reverse of each other. Therefore 12 is an adam number. STEPS: Initialize number(12) Find reverse ofContinue reading “ADAM NUMBER IN JAVA”
Pattern – Increasing left side triangle
Ex 1: Ex 2: Ex 3: Ex 4: Ex 5: Ex 6: Ex 7: Ex 8: Triangle shape_Increasing Number_Decreasing Star Ex 1: Ex 2: Ex 3: Ex 4: Ex 5:
NESTED LOOP IN JAVA
Nested Loop: If a loop placed inside the body of another loop, it’s called a nested loop. Syntax: for(int i = 1; i <= 5; i++) ==> Outer loop for(int j = 1; j <=2; j++) ==> Inner loop Above, we created for loop inside the for loop. We can create for loop inside theContinue reading “NESTED LOOP IN JAVA”
Basics of software testing
What is software? Software is a set of instructions or programs written by programmers/developers on various languages for machine to perform some specific task. What is software testing? Software Testing ensures that the developed software meets the customer expectations. The main purpose of software testing is to identify errors, missing requirements, and technical issues. WeContinue reading “Basics of software testing”
BASICS OF HTML
HTML: HYPER TEXT MARKUP LANGUAGE It is used for designing web pages. We can understand this language easily. Html consists of tags. By using tags we can design the web page. Basic Structure: NOTE: Save the file with extension name .html IMPORTANT NOTES: <!DOCTYPE html> This line denote “This is html version 5”. This lineContinue reading “BASICS OF HTML”
BASICS OF SQL
DATABASE: [DB] Used for storing the data. Variables are also data storage. But variables are temporary data storage. Database are permanent data storage. Database storing the data in the structure of TABLE (ROWS & COLUMNS). Rows are known as RECORDS Columns are known as FIELDS RDBMS: RELATIONAL DATABASE MANAGEMENT SYSTEM Relationship between data are knownContinue reading “BASICS OF SQL”
BASICS OF GIT
GIT: Git is a free and open-source distributed version control system. GIT is used for: Tracking code changes Tracking who made changes Coding collaboration with others WHO CREATED GIT? LINUS TROVALDUS He is responsible for the linux kernel. GITHUB: Github is a website/platform while git is a tool. Instagram:Camera :: Github:Git Git or Camera isContinue reading “BASICS OF GIT”
Basic – Object, Class, Method & Variable
What is object? Real world entity. It is instance of a class. It is memory reference of a class. It is a combination of state & behavior. State denotes Instance Variable. Behavior denotes Instance Methods. We can access these instance variable & instance methods by using object name. Using new keyword, we create an object.Continue reading “Basic – Object, Class, Method & Variable”
OPERATORS IN JAVA
Operators: It is a symbol that is used to perform operations. Types: Arithmetic Operator Unary Operator Assignment Operator Relational Operator Logical Operator Ternary Operator Bit-wise Operator Shift Operator ARITHMETIC OPERATORS: They are used to perform simple arithmetic operations. * : Multiplication / : Division % : Modulo + : Addition – : Subtraction Ex: ArithmeticContinue reading “OPERATORS IN JAVA”
INCREMENT & DECREMENT OPERATORS
INCREMENT OPERATORS It is used to incrementing the value 1. It have two types. Pre-Increment Operator Post-Increment Operator Pre-Increment Operator: Ex: ++a Before the variable, ++ is placed. Value is incremented first & then result is computed (Processed/Printed). Post-Increment Operator: Ex: a++ After the variable, ++ is placed. Value is computed first & then valueContinue reading “INCREMENT & DECREMENT OPERATORS”
While loop practice- Modulo & Divider
Scenario 1: while(purse>0) Output: 654321No of Digits: 6 Code Explanation: In while condition, we declare purse is greater than zero. So, purse gets executed till 1. Scenario 2: while(purse>1) Output: 65432No of Digits: 5 Code Explanation: In while condition, we declare purse is greater than one. So, purse gets executed till 2. Scenario 3: [System.out.println(purse%100);]Continue reading “While loop practice- Modulo & Divider”
CAN WE USE SWITCH STATEMENTS WITH STRING
Strings in switch: Beginning with JDK 7, we can use a string to control a switch statement, which is not possible in C/C++. Ex 1: Output: two Ex 2: Output: No of Month: 10 Ex 3: Same program – cases in same line: Output: This is boys name Ex 4: Output: Working Day Ex 5:Continue reading “CAN WE USE SWITCH STATEMENTS WITH STRING”
Swapping Variables
Ex 1: Swap two variables using third variable Output: a = 9b = 5 Ex 2: Swapping two variables without third variable Output: a = 99b = 89 Ex 3: Swapping three variables Output: a = 30b = 10c = 20 Ex 4: Swapping Four Variables Output: a = 20b = 30c = 40d =Continue reading “Swapping Variables”
SWITCH CASE STATEMENT
Switch Case Statement: Switch statement executes one statement from multiple conditions. It is like if-else-if ladder. The switch statement works with byte, short, int, long, enum types, String and some wrapper types like Byte, Short, Int, and Long (Datatype learn later). Syntax: break is optional. We can have any number of case statements Last oneContinue reading “SWITCH CASE STATEMENT”
DO WHILE LOOP IN JAVA
Do – While Loop: It is an exit control loop. The do-while check the condition at the end of loop body. The do-while loop is executed at least once because condition is checked after loop body. Syntax: Ex 1: Output: 10 Code Explanation: if a is above or equal to 100, then print a value.Continue reading “DO WHILE LOOP IN JAVA”
MOCK INTERVIEW
1] What is java? 2] What are the features of java? 3] JDK Vs JVM 4] What is JIT Compiler? 5] What is Object? 6] What is constructor? 7] What is Polymorphism? 8] What is Dynamic Binding? 9] HR round qn – SHARE ABOUT THE PROBLEM WHICH YOU FACED IT ALONE IN YOUR LIFE? WHATContinue reading “MOCK INTERVIEW”
First Mock Interview
Today i have received call from payilagam trainer for mock interview session. He asked me, shall i take mock interview now? I don’t know, why did i get that much of nervous. I said, i will call in two mins. After two mins, i called and said im ready for mock interview. But, inside myContinue reading “First Mock Interview”
WHILE LOOP – TASK
Ex 1: How many numbers from 1 to 100 are divisible by 3? Output: Divisors Count: 33 Ex 2: How many numbers from 1 to 100 are divisible by 3 & 5? Output: 15 : This number can divided by 3 & 530 : This number can divided by 3 & 545 : This numberContinue reading “WHILE LOOP – TASK”
WHILE LOOP – PRACTICE
Ex 1: Print : 767 495 359 291 257 240 232 228 Idea: 767 495 359 291 257 240 232 228 Diff between above numbers: 272 136 68 34 17 8 4 2 272/2 = 136 136/2 = 68 68/2 = 34………. Output: 767 495 359 291 257 240 232 228 Ex 2: Print: 7Continue reading “WHILE LOOP – PRACTICE”
If else statements without curly braces
It is also correct without braces, if there is only one statement under the if / else condition. but if you have to put multiple statement under the if / else condition then you must provide braces, without braces if / else condition will only read first statement and output will be different from asContinue reading “If else statements without curly braces”
GETTER & SETTER METHODS
Getter and Setter methods are used to protect the data and make the code more secure. private variables can access within the same class. An outside class can’t access the private variable. Using get & set methods, we can access the other class private variables. Get method returns the variable value Set method sets theContinue reading “GETTER & SETTER METHODS”
INTERFACE IN JAVA
Interface: Interface is a blueprint of a class. In other words, It is set of rules or contract. Interface Declaration: An interface is declared by using the interface keyword. Syntax: Interfaces have the following properties: An interface is implicitly abstract. do not need to use the abstract keyword while declaring an interface. Each method inContinue reading “INTERFACE IN JAVA”
WHILE LOOP IN JAVA
While loop: Syntax: While loop is used to repeatedly execute the code in between the braces as long as the specified condition is met. While loop is considered as repeating if statement. It saves time, reduce the code & error. Ex 1: 5 times Print the name “Rajalakshmi” Output: RajalakshmiRajalakshmiRajalakshmiRajalakshmiRajalakshmi Note: Program 9th line DoContinue reading “WHILE LOOP IN JAVA”
ASSESSMENT – 1
Scenario #1:Expected Understanding: Access Modifiers, Single Inheritance, getter methods, Constructor Overloading 1) Create a Class named “Trainer”.– Have default instance variables String dept, institute– Have private instance variable int salary– Assign 10000 as value for salary.– Create getter method for salary.– Assign values – “Java”, “Payilagam” to them– Have instance method training() with void asContinue reading “ASSESSMENT – 1”
Java If-else Statement
If-else statements are defined as Control Statements which controls the statements to be executed on the basis of some condition. 4 types are there. if statement nested if statement if-else statement if-else-if statement IF STATEMENT: Java if statement tests the condition. It executes the if block, if condition is true. Syntax: Ex:1 Output: a isContinue reading “Java If-else Statement”
STATIC IN JAVA
STATIC: Keyword: static Static can be: Variable Method Block Nested Class (Learn later) Static means class level Static members are associated with class. Static members are common to all the objects. We can access the static members without object creation. STATIC VARIABLE Static variable is a class level variable. It is common to all theContinue reading “STATIC IN JAVA”
Abstraction in java
Abstraction: The process of showing only essential things & hiding the background details / inner details. Ex: We can handle TV, Washing machine, AC, Vehicles & ATM card yet we don’t have the knowledge of their inner operations. Abstract Class: A class which contains the abstract keyword in its declaration is known as abstract class.Continue reading “Abstraction in java”
super( ) keyword in java
super( ): super( ) keyword is used to calling a super class constructor from the sub class constructor. super( ) super –> it denotes super class constructor ( ) we can give super class constructor’s input or sub class constructor’s parameter inside this brackets. (Refer below scenario) Parent class constructors are called by this bracketContinue reading “super( ) keyword in java”
this( ) keyword in java
this( ): this( ) keyword is used to calling a current class constructor from the current class another constructor. this( ) this –> it denotes current class constructor ( ) we can give nothing or constructor’s input inside this brackets. Current class constructors are called by this bracket content. this( ) –> zero argument constructorContinue reading “this( ) keyword in java”
NON ACCESS MODIFIERS – FINAL
What is non access modifiers? Access Modifiers provides Access Control. Non-Access Modifiers have nothing to do with accessibility. But it is used to restricts the modification of class/variable/methods. Below are the Non Access Modifiers available in Java. Final Abstract Static FINAL – Non Access Modifier Keyword : final Applicability: Variable Methods Class FINAL VARIABLE WhenContinue reading “NON ACCESS MODIFIERS – FINAL”
METHOD OVERRIDING & DYNAMIC BINDING IN JAVA
What is method overriding? If the same method name is declared in both the superclass and the subclass, then the method of the sub class overrides the method of the superclass. This is known as method overriding. Overriding Rule: It required atleast two classes. They must be IS-A relationship.(Inheritance) Both the superclass and the subclassContinue reading “METHOD OVERRIDING & DYNAMIC BINDING IN JAVA”
Protected Modifier in Java
PROTECTED MODIFIER: The access level of a protected modifier is within the package and outside the package through child class. If you do not make the child class, it cannot be accessed from outside the package. The protected access modifier can be applied on the data variable, method and constructor. It provides more accessibility thanContinue reading “Protected Modifier in Java”
INHERITANCE
WHAT IS INHERITANCE? An object of one class behaving as an object of another class is known as inheritance. In java, a class can inherit all the properties & behaviors of another class. The class which inherits from other class properties is known as child class, sub class, derived class. The class whose properties areContinue reading “INHERITANCE”
Constructor in Java
CONSTRUCTOR: Constructor is a special method. It is used for initializing an object variables. It is called automatically when we create an object or when the class is initialized. Constructor cannot be static When a method as static, it means the method belongs to the class and not to a specific object. But the constructorContinue reading “Constructor in Java”
Default Access Modifier in Java:
Package: Packages are folder structure. Packages as the name suggests, is for packing related classes into one group. we write at the beginning of any class file to indicate where exactly that class has to be created. It helps organize our classes into a folder structure and make it easy to locate and use them.Continue reading “Default Access Modifier in Java:”
Basic Concept from Object Oriented Analysis & Design
Modularity: In modular programming, the code is divided into different ‘modules’ which are responsible for a particular functionality in the entire project. This helps in development, debugging and maintenance of the code. Typically, modules should be as independent of each other as possible, where independence means that changes to a module leads to minimal changeContinue reading “Basic Concept from Object Oriented Analysis & Design”
Static & Non Static Block in java
Statement : Statement is a complete unit of execution. Block: A block is a group of statements (zero or more) that is enclosed in curly braces { }. Diff b/w method & block: METHOD BLOCK A method is set of instructions grouped together to perform specified task in the class Block is a group ofContinue reading “Static & Non Static Block in java”
Anonymous Object in Java
Anonymous Object: Anonymous meaning not identified by name / nameless. An object which has no reference variable is called anonymous object in Java. If you want to create only one object in a class then the anonymous object is a good approach. Syntax: If you want to call a method through the anonymous object thenContinue reading “Anonymous Object in Java”
Private & Public Access Modifiers
Access Modifiers: The access modifiers in Java specifies the accessibility or scope of a variable, method, constructor, or class. We can change the access level of variables, constructors, methods, and class by applying the access modifier on it. There are four types of Java access modifiers: private public default protected Private: The access level ofContinue reading “Private & Public Access Modifiers”
Method Overloading in Java
Method Overloading: Two or more methods can have the same name inside the same class if they accept different arguments. This feature is known as method overloading. Method overloading is achieved by either: different number of arguments. or different data type of arguments. Method overloading is not associated with return types. Overloaded methods may haveContinue reading “Method Overloading in Java”
Return keyword in java
Return keyword: return is a reserved keyword. It is used to exit from a method with or without a value. return statement must be last statement to get executed in a method. Return keyword in void method: void methods cannot return a value. return keyword not required for void type methods. But we can useContinue reading “Return keyword in java”
Variables in Java
Java program: Output: Variables: Variables are containers that hold data. They are assigned with a datatype. Variable is a name of memory location. It is a combination of “vary + able” which means its value can be changed. Ex: int a = 10; Scope of variable: Variables can be declared & defined inside a classContinue reading “Variables in Java”
Java Basic Structure
Java Program : public: public keyword is an access modifier that represents visibility. It means it is visible to all. class: We use class keyword to define the class. Class is a template or blueprint that describes the state & behavior of the object. Collection of object is known as class. It allocates memory forContinue reading “Java Basic Structure”
OOPs Basic Concept :
Programming: Programming is a way of giving instructions to computer about what they should do next. These instructions are known as code & programmers write the code to solve the problems or perform a task. So, we can control the machine by programming. Trial & Error is possible in programming. Paradigm: Paradigm means Idea. SomeContinue reading “OOPs Basic Concept :”