Wednesday, April 4, 2018

Quick look


SPRING BOOT                    

  • It is a way to ease to create stand-alone application with minimal or zero configurations.
  •  It is approach to develop spring based application with very less configuration. 
  • It provides defaults for code and annotation configuration to quick start new spring projects within no time. 
  • It leverages existing spring projects as well as Third party projects to develop production ready applications.
  •  It provides a set of Starter Pom’s or gradle build files which one can use to add required dependencies and also facilitate auto configuration.
  • – Spring Boot parent and starters make it much easier
  • Spring Boot works with Maven, Gradle, Ant/Ivy
  • Embedded container is just one feature of Spring Boot
  •  Traditional WAR also benefits a lot from Spring Boot
  • – Automatic Spring MVC setup, including DispatcherServlet
  • – Sensible defaults based on the classpath content
  • – Embedded container can be used during development
  • Tomcat, Jetty, 

@Configuration
@ComponentScan
@EnableAutoConfiguration  = @SpringBootApplication
public class MyAppConfig { public static void main(String[] args) { SpringApplication.run(MyAppConfig.class, args); } }

JAVA 8                         


STREAM
INTSTREAM
LONGSTREAM
DOUBLESTREAM
OF
Stream.Of(array)
Stream.of("str1","str2")
LIMIT OPERATION

Stream.Generate()
Stream.iterate()
DISTINCT OPERATION
(list/set).stream.distinct().foreach(x-'>'t;ysout(x);)
(list/set).stream.distinct().collect(toSet());
(list/set).stream.distinct().collect(toList());

CONCAT OPERATION 
Stream.concat(l1.stream(), l2.stream()).collect(Collectors.toList());

FOREACH OPERATION 
(list/set).stream.distinct().foreach()
COUNT OPERATION
(list/set).stream.count()
(list/set).stream.distinct().count()


MATCH OPERATION

(list/set).stream.(anyMatch()|allMatch()|noneMatch())
(list/set).stream.count()
(list/set).stream.distinct().count()
(list/set).stream.(anyMatch()|allMatch()|noneMatch())


FIND OPERATION

(list/set).stream.findAny()
(list/set).stream.findAll()
list.stream().filter(u -> u.getName().endsWith("sh"))
    .findFirst().orElse(null)


FILTER

(list/set).stream.filter(x->x%2).collect(toList()|toSet
list.stream().filter(u -> u.getName().endsWith("sh"))
    .findFirst().orElse(null);
list.stream().filter(u -> u.getName().endsWith("sh"))
    .forEach(u -> System.out.println(u.getName()));
FLATMAP


SORT

NATURAL ORDER :list.stream().sorted() 
REVERSE ORDER : list.stream().sorted(Comparator.reverseOrder()) 
BASED OF A PARTICULAR ATTRIBUTE
list.stream().sorted(Comparator.comparing(Student::getAge))
BASED OF A PARTICULAR ATTRIBUTE REVERSE ORDER


list.stream().sorted(Comparator.comparing(Student::getAge).reversed())
list.stream().max(Comparator.comparing(String::valueOf)).get();
list.stream().min(Comparator.comparing(String::valueOf)).get();
list.stream().sorted(Comparator.reverseOrder())


UI
  • JAVASCRIPT
  • JQUERY
  • REACT
  • ECHMA SCRIPT
  • ANGULAR JS
  • ANGULAR
  • FONTAWESOME
  • BOOTSTRAP
  • 1.   CONTAINER, CONTAINER-FLUID
    2.   GRID DESIGN/RESPONSIVE DESIGN
    3.   TYPOGRAPGHY
    4.   NAVIGATION


MESSAGING
JMS
Purpose:Establish communication between two different systems
connectionFactory.createConnection();
connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();  
session.createConsumer((Destination) 
consumer.setMessageListener(msgHandler); 
session.createProducer((Destination) 

Connectionfactory

  • QueueConnectionFactory|TopicConnectionFactory
  • QueueConnection|TopicConnection
  • QueueSession|TopicSession
  • QueueSender|TopicPublisher
  • QueueReceiver|TopicSubscriber
  • Queue|Topic
  • MessageProducer: Produces messages to be send.
  • MessageConsumer :
    session.createConsumer((Destination)
  • Destination 
     
  • DurableConsumer
    MessageListener :TextListener|JSONListener
  • Session.AUTOACKNOWLEDGE

SPRING JMS
  • BASE CLASS :JMSACCESSOR,
  • CONNECTIONFACTORIES

  • AbstractConnectionFactory
    AbstractRoutingConnectionFactory
    CachingConnectionFactory
  • ActiveMQConnectionFactory 
  • MESSAGECONVERTER :

    Strategy interface that specifies a converter between Java objects and JMS messages.
  • MappingJackson2MessageConverter
    MarshallingMessageConverterMessagingMessageConverterSimpleMessageConverter
  • DESTINATION
  • JMSTEMPLATE
  • destination :

  • MESSAGECreator :

  •  variables, and functions.
  • MESSAGEselector

  • AbstractMessageProcessingSelectorAbstractXPathMessageSelectorBooleanTestXPathMessageSelector

    ExpressionEvaluatingSelector



Message listener container, used for invoking messageReceiver.onMessage on message reception.
CACHE
  • GUAVA CACHE

CacheBuilder.newBuilder() .maximumSize(100) .expireAfterAccess(30, TimeUnit.MINUTES).build(new CacheLoader(),personid)

  • EHCACHE
  • LRU
  • SPRING CACHE

SECURITY
  •   DATA INTEGRITY  : JCE
  •   AUTHENTICATION AND AUTHORIZATION : JAAS| SPRING SECURITY
  •   CONFIDENTIALITY : SSL/ NO -SSL/ 
  •   NON REPUDIATION : DIGITAL CERTIFICATES
  • OUTH2 
BATCH PROCESSING 

  •   SPRING BATCH

JOB SCHEDULING 
  •   QUARTZ 
  •   SPRINGQUARTZ

WEB SERVICES
  • JAX-RS
  • JERSY 
  • APACHE CXF 
  • SPRING REST
  • SPRING HATEOS
  • SPRING REST OUTH2 
  • AWS

MACHINE LEARNING 
MACHINE LEARNING                  
  • PYTHON
 Defining functions
2.     In bulit Functions
1.     print()
2.     str()
3.     len()
4.     slice()  slice_me[2:5]|sliceme[2:]
5.     integer//integer2
6.     input("",""),input()
7.     int()
8.     slice()  slice_me[2:5]|sliceme[2:]
9.      https://www.programiz.com/python-programming/methods/built-in
3.      Conditionals
1.       if(): elif:
2.      str()
 4.      Arrays
1.     num=['a','b','c','d']
2.     num.remove('c')
5.      Dictionary
       1. performances = {'Ventriloquism':'9:00am', 
    'Snake Charmer': '12:00pm'}
 2.      del performaces['Ventriloquism']
 6.      Looping
 1.       random.randint(1,53)
 2.      for items in menu_prices
 3.      for name,price in menu_prices.items()
 4.      for items in menu_prices
 5.      while guess != num:
 7.      Packages
             1.       random.randint(1,53)
 8.      Functions
              1.      def lotto_numbers():
              2.      
  9.      Reading/Writing Files
             1.      open()
             2.      file.write()
             3.      file.read()
  10.      Exceptions
             1.      open()
             2.      file.write()
             3.      file.read()  
  10.      Modules
             1.      open()
             2.      file.write()
             3.      file.read()
  •  
  • R expressions, variables, and functions.
  • Vectors: Grouping values into vectors, then doing arithmetic and graphs with them.
    Matrices :Creating and graphing two-dimensional data sets.
    Summary Statistics :Calculating and plotting some basic statistics: mean, median, and standard deviation.
    Factors :Creating and plotting categorized data.
    Data Frames :Organizing values into data frames, loading frames from files and merging them.
    Real-World Data :Testing for correlation between data sets, linear models, and extending R with additional libraries
    .

DATA                             
  • JAXB :JAXBCONTEXT,MARSHALLER,UNMARSHALLER,JAXBEXCEPTION.

  • JACKSON
  • OBJECTMAPPER.READVALUE(),WRITEVALUE
  • JSONFACTORY,JSONGENERATOR
  • JsonGenerator generator = factory.createGenerator(
    new File("data/output.json"), JsonEncoding.UTF8)
    ;
  • JSONFACTORY,JSONPARSER,JSONTOKEN 
  • JsonFactory factory = new JsonFactory();
  • JsonParser  parser  = factory.createParser(carJson);

  • SPRING OXM
  • MARSHALLER|STREAMSOURCE
  • UNMARSHALLER|STREAMRESULT
  • CASTORMARSHALLER
  •  @Bean
     public CastorMarshaller getCastorMarshaller() {
       CastorMarshaller castorMarshaller = new CastorMarshaller();
       Resource resource = new ClassPathResource("mapping.xml");
       castorMarshaller.setMappingLocation(resource);
       return castorMarshaller;
     }
  • MARSHALLING
    fis = new FileInputStream(fileName);
                return unmarshaller.unmarshal(new StreamSource(fis));
    UNMARSHALLING
    fos = new FileOutputStream(fileName);
    marshaller.marshal(graph, new StreamResult(fos))
PERSISTENCE 

  • JDBC
  • SPRING JDBC
  • org.springframework.jdbc.core.JdbcTemplate 
  • return jdbcTemplate.update(query): will take insert|update|delete query
  •  return jdbcTemplate.execute(query,new PreparedStatementCallback()
  • return template.query("select * from employee",new ResultSetExtractor>(){  
  • NamedParameterJdbcTemplate :Creating and plotting categorized data
  • SimpleJdbcTemplate
    PreparedStatement using given arguments. :Creating and graphing two-dimensional data sets.
  • public List query(String sql, RowMapper rse)
    ResultSetExtractor 
  • DataAccessException

UNIT TESTING: MOCKITO             
TO DOS 2018: GO_OVER MOCKITO,EASYMOCK,JMOCKIT,POWERMOCK
  • JUNIT4
  • BDDMOCKITO
  • MOCKITO
  • WHEN.THEN INTERACTION 
  • VERIFY 
  • @Mock, @Spy, @Captor and @InjectMocks

  • Mockito.spy() – to spy on a real object.
List spyList = Mockito.spy(list)
OR @Spy
List spyList = new ArrayList();
Stubbing a spy
Mockito.doReturn(100).when(spyList).size();
assertEquals(100, spyList.size());
mock vs spy

@Test
public void whenCreateMock_thenCreated() {
    List mockedList = Mockito.mock(ArrayList.class); 
    mockedList.add("one"); // It mocked ,didnt actually add
    Mockito.verify(mockedList).add("one"); 
    assertEquals(0, mockedList.size());
}
@Test
public void whenCreateSpy_thenCreate() {
    List spyList = Mockito.spy(new ArrayList()); 
    spyList.add("one");  // It actually add
    Mockito.verify(spyList).add("one"); 
    assertEquals(1, spyList.size());
}
MyList listMock = Mockito.mock(MyList.class);

WHEN ..THEN
  • when(listMock.add("aaa")).thenReturn(false);
  • doReturn(false).when(listMock).add("aaa";
ASSERTIONS
  • boolean added = listMock.add(randomAlphabetic(6));
  • assertThat(added, is(false));
  • assertThat(listMock.size(), equalTo(1))
  • assertThat(element, is(equalTo("Always the same")));
  • assertEquals(100, spyList.size());

THROW EXCEPTIONS
  • when(listMock.add("aaa")).theThrow(IllegalStateException.class)
  • doThrow(NPE.class).when()
MULTIPLE CALLS
when(listMock.add("aaa"))
  .thenReturn(false)
  .thenThrow(IllegalStateException.class); 
 CALL REAL METHOD

 SPY

MyList instance = new MyList();
MyList spy = Mockito.spy(instance); 
doThrow(NullPointerException.class).when(spy).size();
spy.size(); // will throw the exception

CUSTOM ANSWER

doAnswer(invocation -> "Always the same").when(listMock).get(anyInt()); 

VERIFY : IS JUST TO VERFIY THAT YOU DID TEST ACTION 
; IT GOT EXECUTED

List mockedList = mock(MyList.class);

verify(mockedList).size();
verify(mockedList, times(1)).size();
verifyZeroInteractions(mockedList);
verify(mockedList, times(0)).size();
verifyNoMoreInteractions(mockedList);
verify order of interactions
List mockedList = mock(MyList.class);
mockedList.size();
mockedList.add("a parameter");
mockedList.clear(); 
InOrder inOrder = Mockito.inOrder(mockedList);
inOrder.verify(mockedList).size();
inOrder.verify(mockedList).add("a parameter");
inOrder.verify(mockedList).clear();
verify(mockedList, never()).clear(); 
verify(mockedList, atLeast(1)).clear();
verify(mockedList, atMost(10)).clear();
verify interaction with exact argument
verify(mockedList).add("test");
mockedList.add("test");
verify(mockedList).add("test");//verify interaction with flexible/any argument
verify interaction using argument capture
List mockedList = mock(MyList.class);
mockedList.addAll(Lists. newArrayList("someElement"));
ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(List.class);
verify(mockedList).addAll(argumentCaptor.capture());
Mockito.verify(mockedList).add(argCaptor.capture());
List capturedArgument = argumentCaptor.> getValue();
assertThat(capturedArgument, hasItem("someElement"));


MOCKITO ANNOTATIONS

Configure
@RunsWith(MockitoJUnitRunner.class)//Mockito
@RunWith(EasyMockRunner.class)// EasyMock
@RunWith(JMockit.class)
or
@Before
public void init(){
MockitoAnnotations.initMocks(this);
}


____________________________________________________
WITH ANNOTATIONS
@Mock

List mockedList;
-----------------------------------------------------
WITHOUT ANNOTATIONS

ListMockito.mock
(List.class);
____________________________________________________
WITH ANNOTATIONS

@Spy
List spyList;
-----------------------------------------------------
WITHOUT ANNOTATIONS


ListMockito.spy
(List.class);____________________________________________________
WITH ANNOTATIONS

@Captor
ArgumentCaptor argCaptor;
Mockito.verify(mockedList).add(argCaptor.capture());
-----------------------------------------------------
WITHOUT ANNOTATIONS

 ArgumentCaptor arg = ArgumentCaptor.forClass(String.class);
mockList.add("one");

Mockito.verify(mockList).add(arg.capture());
____________________________________________________

WITH ANNOTATIONS

@InjectMocks

MyDictionary dic = new MyDictionary();
assertEquals("aMeaning", dic.getMeaning("aWord"));
____________________________________________________
RULES

    @Rule
    public VerificationCollector verificationCollector = MockitoJUnit.collector();
Spring

@ActiveProfiles("test")
@RunWith(SpringJUnit4ClassRunner.class)

@SpringApplicationConfiguration(classes = MocksApplication.class)

EASYMOCK
@RunWith(EasyMockRunner.class)
EasyMock.replay(loginService);
EasyMock.verify(loginService);
EasyMock.expect(userForm.getUsername()).andReturn("foo");
EasyMock.expect(loginService.login(userForm)).andReturn(true);
    loginService.setCurrentUser("foo");
EasyMock.replay(userForm);
EasyMock.replay(loginService);
Assert.assertEquals("OK", login);
EasyMock.verify(userForm);
EasyMock.verify(loginService);



LINUX                             

  • JSCH
  • JSFTP
  • LINUX COMMANDS
* * * * * command to execute │ │ │ │ │ │ │ │ │ └─── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0) │ │ │ └──────── month (1 - 12) │ │ └───────────── day of month (1 - 31) │ └────────────────── hour (0 - 23) └─────────────────────── min (0 - 59)


DATA STRUCTURES



ALGORITHMS
  • SEARCH 
  • SORTING 
  • SEQUENCE 
COLLECTION
Interface Implemented

  • RANDOM ACCESS TO TAKE SAME TIME TO ACCESS ELEMENTS
  • SERIALIZATION
  • CLONING INTERFACE
CONCURRENCY                      
  • BLOCKING QUEUE
  • ARRAY BQ
  • BLOCKING QUEUE : DS TO HOLD THREAD OBLECTS
  • ARRAY BQ
  • LINKED BQ:
  • SYNCHRNOUS BQ:
  • CYCLIC BARRIER: 
  • SEMAPHORE :
  • RENTRANT LOCK
  • FORK AND JOIN CALL 
  • PRODUCER CONSUMER
  • ATOMIC BOOLEAN 
  • ATOMIC INTEGER
  • ATOMIC LONG 
  • ATOMIC REFERENCE
  • READ WRITE LOCK
  • EXCHANGER : COMMUNICATION BETWEEN THREADS
  • COUNTDOWNLATCH:
  • CONCURRENTLINKEDQUEUE
  • DELAY BQ


FILE HANDLING                     


MAVEN                             

Archetype is a plugin that creates project structure

mvn archetype:generate

-DgroupId = com.companyname.automobile -DartifactId = trucks -DarchetypeArtifactId = maven-archetype-webapp -DinteractiveMode = false
  • GROUP ID
  • ARTIFACT ID
  • DEPENDENCIES
  • PLUGINS
  • GOALS

  • PREPARE-RESOURCES|VALIDATE|COMPILE|PACKAGE|INSTALL|DEPLOY
  • PRINT DATA ON CONSOLE|maven-antrun-plugin
  • CREATE JAR|maven-jar-plugin
  • CREATE WAR|maven-war-plugin
  • CREATE EAR| maven-ear-plugin
  • CREATE RAR|maven-rar-plugin
  • COMPILE CODE|maven-compiler-plugin
  • UNIT TESTING CODE||maven-surefire-plugin
  • CREATE PROJECT DOCUMENTATION
  • CREATE PROJECT REPORTS
  • INSTALL| maven-install-plugin
  • CREATE JAVADOC|maven-javadoc-plugin
  • JUNIT TEST CASES


No comments:

Post a Comment