Posts

Showing posts from July, 2020

Class in Java

We can categorize java classes in several criteria criteria-1 1. Top Level class We can create any number of top level class, interfaces, enumerators, annotations inside the java file. But we can add only one public top level class in that & that class name must be the  name  of the java file. Top level class cant be static. public class AppInitializer {//file name: AppInitializer.java } class A{ } interface B{ } @interface C{ } enum D{ } 2.Nested Class    2.1  Static Class    2.2) Non-static Nested class(Inner Class)         2.2.1) Regular inner class         2.2.2) Local Inner Class               2.2.2.a) Anonymous Inner Class eg:-Nested class           class AppInitializer {     class C{     }     static class B{     } } Q-A)Can we create inner class inside the interface? //If we create a class in interface,it will be implicitly static.  interface A {     // Directly cant create inner class in  the interface(But can create indirectly).Class will be implicitly static class     //

Polymorphism Using JAVA

Image
Polymorphisam  Simply " One interface many forms " . Dispatcher decide which method will invoke in the program. If compiler dispatching(static) the method it will course to method overloading. If JVM dispatching(dynamic) the method it will course to method overriding.   (a)Method Overloading (Compile time Polymorphisam/Static Polymorphisam) Compiler is the Dispatcher in the  Same method name but different signatures. If two method of a class have the same name but signatures  not override equivalent ,then the method name is said to be overloaded. public class AppInitializer {     public static void myMethod(){         System.out.println("My method 1()");     }     public static void myMethod(int a){         System.out.println("My method 2(int)");     }     public static void myMethod(String a, int b){         System.out.println("My method 3(String, int)");     }     public static void main(String[] args) {         myMethod();// My method 1()    

Practical Agile Concept with Git

Image
Software development models used to develop software production efficient & effective manner.The Systems Development Life Cycle (SDLC) gives structure to the challenges of transitioning from the beginning to the end of your project without forgetting a step. 1. Waterfall Model:oldest and most straightforward 2. V-Shaped Model 3. Iterative Model 4. Spiral Model 5. Big Bang Model 6. Agile Model:By breaking the product into cycles, the Agile model quickly delivers a working product and is considered a very realistic development approach.This model emphasizes interaction, as the customers, developers and testers work together throughout the project. Manifesto for Agile Software Development introduce in 2000( https://agilemanifesto.org/ ) 12 Agile principles :These principles describe..        (1)Respect leadership in level     (2)Start with what you do     (3)Encourage Changes always.     (4)Respect current roles & responsibilities.   Framework(Methodology) Main contributor(s) Adap

Increase productivity in programming

Image
                                                                          (A)Short Cuts 1.windows Shortcutes Ctrl+tab>navigate across tabs 2.Short cuts in InteliJ Ctrl+Alt+Shift+l>Auto indentation & organize code Alt+Insert>automatically generate methods. Eg:-Setters,getters,Overrides. Ctrl+Q> quick documentation in the java editor Ctrl+Alt+Shift+T>Encapsulate fields & refactor Alt+Enter(on the SQL query)>can Inject the SQL statement  (B)Tips 1.Tips in InteliJ Copy module Go to show in Explorer  by right clicking  any module in  your project Copy & paste any where  inside your project or outside. Delete IML File (.iml) inside the module. Change variable name as bulk Right click the variable or Refactor(Ctrl+F6)->change. Change data type as bulk Right click variable name ->Type Migration(Ctrl+Shift+F6)->change. Ignore an error for testing purposes  Run->Edit Configuration Remove Build(Select & "-" Symbol) in Before lunch:Build,Acti

Serialization Using java

Image
  In computing, serialization is the process of translating data structures or object state into a format that can be stored or transmitted and reconstructed later is called as serialization. Simply,Java is  an object oriented programming language.Machines store files as byte stream in any file in digital world.Java have many object which include data , & it can convert to the byte stream & write to file.After write as byte  stream(Called Serialization ), we can  send or store that data any where. If you can convert that byte stream successfully as same as to the  the previous object it called as the De-Serialization .     Importance of Serialization Communication: If you have two machines that are running the same code, and they need to communicate, an easy way is for one machine to build an object with information that it would like to transmit, Persistence: If you want to store the state of a particular operation in a database, it can be easily serialized to a byte array, an

Using Properties file in java

Image
In the general case .properties file used to store project configuration & data configuration setting as special chunk of text. They are store as key value pairs. In java it also called as Resource Bundle. By default java java System class has properties & we can use that as internal & external file s also import java.io.File; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Paths; import java.util.Properties; public class AppInizializer {      public static void main(String[] args) {      //get all properties  in System class           Properties properties = System.getProperties();           for (Object key : properties.keySet()) {              System.out.println(key + "=" + properties.get(key));         } //(a)JVM invoking place using property file                 System.out.println(System.getProperty("user.dir")); //Cheack its validity of(a)         System.out.println(new File("").getAbsolutePath(

File Handling in Java

Image
Any file in the computer system stored as one dimensional byte array.So we want to read or write any file we want to read & write bits one by one.Bit this is very low level operation.So java introduced several Classes to achieve that easily. 1.Read File There are several method to read a file there are some Classes to achieve that. (a)FileInputStream extended method from java.io.Reader.Use to read bytes & convert that to Srring. import java.io.*; import java.nio.file.Files; import java.nio.file.Path;import java.nio.file.Paths; import java.util.List; public class AppInizailzer {      public static void main(String[] args) throws IOException {      File file;//pointer      file = new File("file path");      FileInputStream fileInputStream = new FileInputStream(file);      byte[] fileBytes = new byte[fileInputStream.available()];      fileInputStream.read(fileBytes);      fileInputStream.close();      String s = new String(fileBytes);   

Set Interface using Java

Image
Duplicate values cannot be stored in this data structure. 1)Hash Set: Stored values in random Manner without duplication.      Set<Integer> mySet=new HashSet<>();         mySet.add(10);         mySet.add(20);         mySet.add(30);         mySet.add(10);         System.out.println(mySet.size());//out 3         System.out.println(mySet);//out  [20, 10, 30]           System.out.println(mySet.contains(50));//out false Thre are 2 method to retrieve data from Hash set            //1.using  iterator           Iterator<Integer> iterator = mySet.iterator();          while(iterator.hasNext()){             System.out.println(iterator.next());            }          //2.using for each           for (Integer a:mySet) {             System.out.println(a);         }          //String           Set<String> mySet=new HashSet<>();         mySet.add("Jhone");         mySet.add("Ali");         mySet.add("Lisa");         mySet.add("Jhone"

Avoid Round-off error in large & Small numbers using BigDecimal Class in Java

Image
                    There are two types of primitive data types used for floating point representation in java called double & float.float is a 32 bit IEEE 754 single precision Floating Point Number & double is a 64 bit IEEE 754 double precision Floating Point Number.So that double has 2x more precision then float. double d1=.3; double d2=.2; double d3=d1-d2; System.out.println(d3);//IEEE754 Result is 0.09999999999999998 But there is a round-ff error in IEEE745 floating point representation in double.So when these data apply to large scale project it will possible to fail(GPS Systems,Banking Systems,Radar System,Air traffic controlling systems etc.) So avoid that drawback java introduce Class called BigDecimal.Big decimal avoid this problem(But it consumes more space & time complexity than decimal.) //using as String BigDecimal b1 = new BigDecimal(".3"); BigDecimal b2 = new BigDecimal(".2"); BigDecimal b3 = b1.subtract(b2); System.out.println(b3); //But

Map Interface using Java

Image
Represents a mapping between a key and a value. Eg:-Key          Value          😜          "Jhone"          😁              "Ann"          😜               "Leo" If you  want to get any Value you must know key regards to value. There are 3 types of  maps in Map interface in java,          1.HashMap-Store data random manner,Minimum time  time complexity.Speed map compare to the          other MAPs.  import java.util.HashMap; import java.util.Map;     public static void main(String[] args) { Map<Integer,String> myMap=new HashMap<>();//create Map type HashMap object         myMap.put(10,"Jhone");//key,value         myMap.put(20,"Smith");         myMap.put(30,"Ana");         //Key stored & show in random manner         System.out.println(myMap);         //Jhone         System.out.println(myMap.get(10));         myMap.put(10,"Lisa");         //Lisa         System.out.println(myMap.get(10)); //Replace la