December 24, 2018

Abstract class in java - explained in very simple way with an example

Abstract class in java

Abstract class as the name implies its an abstract.

The class which is not implemented, So we cannot create the object of that class.

Abstract class contains abstract as well as non abstract methods.

we can have abstract class with out abstract method.

you can even have abstract class with final method.

if you doesnt want to implement abstract method in sub class, make the sub class as abstract.

For Example let us consider animal as our abstract class. I wrote two funtion in it

lifeSpan();

isReproduce(); Let it be always "yes".


lifeSpan(); is an abstract method , which is different for each animals

now consider sub class as dog , cat and ant

these class extends that abstract class. The relation ship will come in this way like dog is an animal, cat is a animal ..."is - a" relation ship
since the sub class extends the base class animal.. we need to define lifespan() function in each subclass.

lifespan() is different for each animal

if i create an object Animal a = new dog();

a.isReproduce() ---->  "yes"
a.lifespan() -----> 13


Program



/**
 *  The study of behavior of animal is called ethology
 */
package com.cfed.oopsconcepts;

public abstract class Animal {

public String color;

    public abstract int lifeSpan();
 
    public void isReproduce() {
    System.out.println(" YES ");
    }

}



package com.cfed.oopsconcepts;

public class Dog extends Animal {

@Override
public int lifeSpan() {
// TODO Auto-generated method stub
return 13;
}
}


/**
 * 
 */
package com.cfed.oopsconcepts;

/**
 * @author Konzern
 *
 */
public class Cat extends Animal {

/* (non-Javadoc)
* @see com.cfed.oopsconcepts.Animal#lifeSpan()
*/
@Override
public int lifeSpan() {
// TODO Auto-generated method stub
return 16;
}
/**
* This method cannot access through super class
* as the method is not declared in the super class
*/
public void bark() {
System.out.println(" meow");
}

}


/**
 * 
 */
package com.cfed.oopsconcepts;

/**
 * @author konzern
 *
 */
public class MainClass {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Animal animal = new Dog();
System.out.println(" Dog ");
animal.isReproduce();
System.out.println(animal.lifeSpan());
animal = new Cat();
System.out.println(" Cat ");
animal.isReproduce();
System.out.println(animal.lifeSpan());
//animal.bark(); 

}

}


Output



 Dog
 YES
13
 Cat
 YES
16






Prepare for java certification



December 23, 2018

PipePuzzle in java

Solution for pipe puzzle in java


public class PipePuzzle {

private String [] pipes;
int x;
int y;
private boolean [][] filled = new boolean[20][20];
private int dirs[][] = {{-1,0},{0,1},{1,0},{0,-1}};
public int longest(String[] pipes){
this.pipes = pipes;
int[]values = findSource(this.pipes);
//System.out.println(java.util.Arrays.toString(values));
return maxflow(values[0],values[1],values[2]);
}

public int maxflow(int i, int j, int direction){
int ii = i + dirs[direction][0];
int jj = j + dirs[direction][1];
System.out.println(ii+" "+jj);
int sum = 0;
if(ii<0 || jj < 0 || ii >= x || jj >= y||(pipes[ii].charAt(jj) != '+' && filled[ii][jj]))
return 0;
filled[i][j] = true;
if(pipes[ii].charAt(jj) == '-' || pipes[ii].charAt(jj) == '+'){
sum = 1+maxflow(ii,jj,direction);
}
else{
int left = 1+maxflow(ii,jj,(direction+1)%4);
int right = 1+maxflow(ii,jj,(direction+3)%4);
sum = Math.max(left,right);
}
filled[i][j] = false;
return sum;
}

public int[] findSource(String[]pipes){
x = pipes.length;
y = pipes[0].length();
int [] values = new int[3];
for(int i = 0; i < x; i++){
for(int j = 0; j< y; j++){
if(pipes[i].charAt(j) == 'N'){
values[2] = 0;
values[0] = i;
values[1] = j;
break;
}
else if(pipes[i].charAt(j) == 'E'){
values[2] = 1;
values[0] = i;
values[1] = j;
break;
}
else if(pipes[i].charAt(j) == 'S'){
values[2] = 2;
values[0] = i;
values[1] = j;
break;
}
else if(pipes[i].charAt(j) == 'W'){
values[2] = 3;
values[0] = i;
values[1] = j;
break;
}

}
}
return values;
}

static String [] test1 = {"LL-L-",
"L+L+L",
"--NL-",
"L+--L",
"LL+L-"};
static String[]test2 = {"ELLL",
"LLLL",
"LLLL",
"LLLL"};
public static void main(String[] args) {
PipePuzzle p = new PipePuzzle();
System.out.println(p.longest(test1));

}

}

The Girl in the room 105 - Book by chetan bhagat Buy!!!

December 22, 2018

String Manipulation - input : String str = "aabbccA" -Output : a2A1b2c2

String logical programs in java

/**
 *
 * Regional office kozhikode
 *
 * input : String str = "aabbccA";
 *
 * Output : a2A1b2c2
 *
 */
package com.cfed.javaTricks;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Consumerfed I T Section
 *
 * 8281808029
 *
 */
public class StringManipulation {

/**
* @param args
*/
public static void main(String[] args) {
String str = "aabbccA";

Map<Character,Integer> map = new HashMap<>();

for(int i=0;i<str.length();i++) {
char chr = str.charAt(i);
if(map.containsKey(chr)) {
int val = map.get(chr);
val = val + 1;
map.put(chr, val);
}else {
map.put(chr, 1);
}
}

for(Character key: map.keySet()) {
System.out.print(key);
System.out.print(map.get(key));
}


}

}

Ouptut


a2A1b2c2

Buy a key board guard






Low cost key board guard which will protect your computer from dust... Buy now... Price below 100

December 21, 2018

Bought a Circle cutter for creating miniatures tools

Circle cutter

Hi

We bought a circle cutter for creating miniature arts, Nice product and worth for price. you can view miniature works on the link

miniature works



Buy Now...... Hurry






Java program to rotate a matrix to 90 degree - amazon interview questions

/**
 * Amazon interview question rotating a matrix to 90 degree
 */
package com.cfed.amazon;

/**
 * @author Konzernties
 *
 */
public class RotateMatrix {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

int ar[][] = new int[3][3];
int val = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
ar[i][j] = ++val;
}
}

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(ar[i][j]+" ");
}
System.out.println();
}

System.out.println(" Rotated 90 degree to left ");

for (int j = 2; j >= 0; j--) {
for (int i = 0; i < 3; i++) {
System.out.print(ar[i][j]+" ");
}
System.out.println();
}
}
}


Output

1 2 3 
4 5 6 
7 8 9 

 Rotated 90 degree to left 

3 6 9 
2 5 8 
1 4 7

Buy a pendrive




Creating a randum number in java with out using java libraries ( Random class in java)

/**
 * To print a random number between 1 to 100
 *
 *
 */
package com.cfed.regionaloffice;

/**
 * @author konzerntechies
 *
 */
public class RandomNumberGenerator {

/**
* @param args
*/
public static void main(String[] args) {

long value = System.currentTimeMillis();
System.out.println(value % 100);

}

}


Output

54

The Girl in the Room 105 has been nominated for Amazon's most popular books of 2018

- from chetan bhagat instagram post



December 20, 2018

Mi Band 3 (Black) 9,526 customer reviews Warranty Details: 1 year

Additional Information
ASINB07HCXQZ4P
Customer Reviews4.1 out of 5 stars   9,525 customer reviews
Best Sellers Rank#6 in Computers & Accessories (See top 100)
Date First Available28 September 2018

Product information

Technical Details
BrandMi
ColourBlack
Item Height12 Millimeters
Item Width47 Millimeters
Screen Size0.78 Inches
Item Weight18.1 g
Product Dimensions1.8 x 4.7 x 1.2 cm
Batteries:1 Lithium ion batteries required. (included)
Item model numberXMSH05HM
Wireless TypeBluetooth
Voltage5 Volts
Lithium Battery Energy Content0.42 Watt Hours
Number of Lithium Ion Cells1
Included Components1 MI Band, 1 Strap, 1 Charging Cable, 1 User Guide


December 19, 2018

Low cost sun glasses - Raymond - free delivery

Low cost sun glasses - Raymond - free delivery


December 18, 2018

Solution for Amazon interview question - Java developer

/**
 * find all element that satisfies
 *
 * square of a = square of b + square of c
 *
 */
package com.cfed.amazon;

public class SampleClass {

public static void main(String[] args) {
// TODO Auto-generated method stub

int ar[] = {1,2,3,4,5};

for(int i=0;i<ar.length;i++) {

for(int j=0;j<ar.length;j++) {

for(int k=0;k<ar.length;k++) {
// System.out.println(i+" -"+j+" - "+k);

int a = ar[i] * ar[i];
int b = ar[j] * ar[j];
int c = ar[k] * ar[k];

if(a==(b+c)) {
System.out.println(a +" = "+ b + " + "+c);
}
}
}
}

}

}

Output

25=9 + 16
25=16 + 9




December 14, 2018

Things you should buy - a power bank with maximum capacity 20000 mah

Things you should buy


Battery drowning in a nightmare for most of the travellers, Travelling is an inevitable part of our day to day life. We must use GPS, internet etc while travelling we cant avoid these apps, as these apps are battery consuming , an alternate power is needed. Either you should buy an additional battery for your phone. No its not an good idea, as the capacity for the battery will be low, you have to switch off and switch on the phone to remove the battery. In case of inbuilt battery its again a big problem.

So i suggest you to buy a power bank having a capacity of atleast 20000mah or above.

Here is a good option. for 1500 rupees

You can buy this through amazon.


Cash on Delivery is available

If you buy alternative with the same capacity you have to spend around 2000 rupees + GST.

December 13, 2018

Pair Sum - Data structure example in java

package com.cfed.datastructures;
/**
 * You have been given an integer array A and a number K. Now, you need to find out whether any two different elements of the array A sum to the number K. Two elements are considered to be different if they lie at different positions in the array. If there exists such a pair of numbers, print "YES" (without quotes), else print "NO" without quotes.

Input Format:

The first line consists of two integers N, denoting the size of array A and K. The next line consists of N space separated integers denoting the elements of the array A.

Output Format:

Print the required answer on a single line.


 * @author  Consumerfed IT Section kozhikode
 *
 */

public class PairSum {

public static void main(String[] args) {
// TODO Auto-generated method stub
int n = 5;
int v = 6;
int[] ar = {1,2,3,4,5};
boolean isFound = false;
for(int i=0;i<n;i++) {
for(int j=i+1;j<n;j++) {

if((ar[i]+ar[j])==v) {
isFound = true;
break;
}

}

}
if(isFound) {
System.out.println("YES");
}else {
System.out.println("NO");
}

}

}


Output

YES

Learning Data Structure is simple !!!

December 10, 2018

Enthiran 2.0 3D Movie Backcover for iphone 6 and Redmi for less price

Enthiran 2 Back Cover for iphone

 


Enthiran 2 Back Cover for Redmi 

Price below 400 INR

 

December 09, 2018

December 08, 2018

Machine learning - Artificial Intelligence

If you're too lazy or don't have time to read some of the top notch AI research papers this year. Then check out this blog post, they've summarized 10 important papers from 2018. The list is a small but fine one. Papers cover topics like NLP (ULMFiT, BERT), adversarial attack but also recent progresses into GANs. Definitely check it out! hashtagdeeplearning hashtagmachinelearning Article: https://lnkd.in/d7dSupe

December 07, 2018

Bubble Sort Algorithm in java

/**
 *  How to implement Bubble sort algorithm
 */
package com.cfed.algorithms;

/**
 * @author Konzern
 * 
 * The complexity is n square
 *
 */
public class BubbleSortAlgorithm {

/**
* @param args
*/
public static void main(String[] args) {

int[] arr = { 4, 5, 7, 1 };

int len = arr.length;

for (int j = 0; j < len - 1; j++) {

for (int i = 0; i < len - 1; i++) {
if (arr[i] > arr[i + 1]) {
int temp = arr[i + 1];
arr[i + 1] = arr[i];
arr[i] = temp;
}
}
}

for (int i = 0; i < len; i++) {
System.out.print(arr[i] + " ");
}

}

}

December 03, 2018

To Find Non Repeat characters in a string and test using junits

/**
 * To Find the K th non repeated value in a String
 *
 * input hello 3
 * output o
 */
package com.cfed.tutorials;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author KonzernTechies
 *
 *         Vishnu prasad varma
 *
 */
public class NonRepeatedElements {

public char findNonRepeatElement(String inputStr, int k) {


// Scanner sc = new Scanner(System.in);
// String inputStr = "hello";
// int k = 3;

Map<Character, Integer> varCountMap = new HashMap<>();
List<Character> nonRepeatChar = new ArrayList<>();

int len = inputStr.length();

for (int i = 0; i < len; i++) {
Character thisChar = inputStr.charAt(i);
int count = 1;
if (varCountMap.get(thisChar) != null) {
count = varCountMap.get(thisChar);
count = count + 1;
varCountMap.put(thisChar, count);
if (nonRepeatChar.contains(thisChar))
nonRepeatChar.remove(thisChar);

} else {
varCountMap.put(thisChar, count);
nonRepeatChar.add(thisChar);
}
}

System.out.println(nonRepeatChar.get(k - 1));

return nonRepeatChar.get(k - 1);
}


}


Test Class

/**
 * 
 */
package com.cfed.tutorials;

import static org.junit.Assert.assertEquals;

import org.junit.jupiter.api.Test;

/**
 * @author Ranjini Raj
 *
 */
public class NonRepeatElementsTest {

  @Test
    public void multiplicationOfZeroIntegersShouldReturnZero() {
        
        NonRepeatedElements tester = new NonRepeatedElements();

        // assert statements
        assertEquals('o', tester.findNonRepeatElement("hello", 3));
        assertEquals('d', tester.findNonRepeatElement("aabbccd", 1));
    }

}


To Find the K th non repeated value in a String

/**
 * To Find the K th non repeated value in a String
 *
 * input hello 3
 * output o
 */
package com.sreejith.tutorials;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * @author KonzernTech
 *
 * Murali Krishanan
 *
 */
public class NonRepeatedElements {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner sc = new Scanner(System.in);
String inputStr = "hello";
int k = 3;

Map<Character, Integer> varCountMap = new HashMap<>();
List<Character> nonRepeatChar = new ArrayList<>();

int len = inputStr.length();


for(int i=0;i<len;i++) {
Character thisChar = inputStr.charAt(i);
int count = 1;
if(varCountMap.get(thisChar)!=null) {
count = varCountMap.get(thisChar);
count = count + 1;
varCountMap.put(thisChar, count);
if(nonRepeatChar.contains(thisChar))
nonRepeatChar.remove(thisChar);

}else {
varCountMap.put(thisChar, count);
nonRepeatChar.add(thisChar);
}
}

System.out.println(nonRepeatChar.get(k-1));

}

}

Output

o

Description


 * To Find the Kth non repeated value in a String
 * 
 * input hello 3
 * output o

List nonRepeatChar = new ArrayList<>();

Why i used List here is add() and remove() works in the order

This question was asked from interview at https://infrrd.ai/

The time complexity of the program is n

December 02, 2018

Generating Classical Music with Neural Networks

Generating classical music with neural networks - Nice interview with Christine McLeavey Payne on how she trained a LSTM neural network to generate piano and chamber music. The best part is where she explained how she did the feature encoding. Nice tricks used and also nice explanation on chordwise vs notewise encoding and also on how she ended up using notewise encoding. Code is also provided. Check it out!


hashtagdeeplearning hashtagmachinelearning


Interview: https://lnkd.in/dTfTsUc Github: https://lnkd.in/ddxNWB9

Facebook comments