Below you will find pages that utilize the taxonomy term “Tech”
Posts
Kafka With Spring
In the last blog we learned how to implement kafka consumer-publisher using plain kotlin. In this blog we’ll walk through some code to implement the same using Spring.
Spring makes the implementation rather simple. We need to create a configuration class and then we can add all our code there.
Setting up the configuration class We need two annotations for this Configuration and EnableKafka. We can also take some time to pick the value for bootstrapAddress and topic name from application.
Posts
Kafka With Kotlin
In this blog we’ll learn how to interact with a kafka broker using plain kotlin.
Generating a kafka project. For this we’re going to generate a spring project using spring initializer. Select the dependency Spring for Apache Kafka. We are adding this dependency so later on we can start using spring for our kafka interactions.
Spinning up kafka and zookeeper. Once you’ve generated your project you’ll need to spin up an instance of kafka and zookeeper.
Posts
Basics of Kafka
Kafka is a distributed event logging system. It’s widely used in event event driven system as framework of choice.
Events We learned about these the last time in Event Driven Systems. In kafka an event is represented by a key-value pair. A key can be null as well. Topics A topic is an ordered log A new event is appended to end of a topic. A topic is not a queue it’s a proper Log.
Posts
Event Driven Systems
A system which does something on the basis of a consumed event is considered an event driven system.
Event An event is defined as a “significant change in state”.
for sale -> sold interviewed -> hired low battery -> charging We can build a system that performs certain operation on basis of these state changes. Any and all state changes can be considered an event.
An event shouldn’t be confused with the message/data that we send with it.
Posts
Create your react component
Creating your own react component is supereasy.
Syntax class MyElement extends React.Component { constructor(props) { super(props); } render() { return react.createElement('p',null,'This is some text'); } } Or const myElement = (props) =>{ return react.createElement('p',null,'This is some text') } Here we have seen two ways to create a react component one using classes the other using simple arrow function.
How to use it const myElement = react.createElement(MyElement); root.render(myElement); Two important things happen here.
Posts
Intro to react
React is a frontend javascript framework which allows us to decouple the logic and rederning of an element in DOM.
Creating an React Element React.createElement('Element name', props, ...children) Mounting a React Elment After creating an element you will need a place to mount the element until then the element you created will not be present in HTML DOM.
The element you will mount your react element to is called root.
Posts
Generics in java
Generics in java are used to specify a type which would be known only when the code is ran or called not when it is written.
Generic also helps you to write code that can work with wide variety of types. So you don’t need to overload a function uneccesarily.
Syntax for classes class Box<T> { } class Pencil { } // Class creation Box<Pencil> = new Box<Pencil>(); In the example above we are creating a generic class and we are telling a type T will be given at call time in the example above we created a class Box and at call time we provided a class Pencil.
Posts
Inheritance in java
In english inherit means to derive qualities from your ancestors genetically.
Just like this in java also, one class can inherit properties and methods of another class using inheritance.
Child extends Parent { } This is the basic syntax for inheritance, We use extends keyword to inherit a class. The class that inherits is also called the subclass and the class which was inherited is called superclass.
To refer to parent class from child class we use super keyword and we need to construct parent in the child class before we intialize any of our properties in our constructor.
Posts
Strings and Arrays
Strings Strings are immutable and they don’t change once defined. String is a class in java which allows you to initialize a string literal. String can be initialize in two different ways
Declaring strings like a normal data type
String name = "some name"; Initialializing a new class method.
String name = new String("some name"); String comes with various different methods like charAt, contains, replace, replaceAll, trim, split. We cannot use indecies to access chars in a string because they are not iterable.
Posts
Packages in Java
Package A package is a grouping of related types providing access protection and name space management.
Advantages Easy to determine how types are related. Makes sure that your names don’t conflict with the names used in the package. Creating a package import mypackage; Naming Convention Packages solve the naming problem but what if two programmers create packages with the same name. That’s why we have naming convention for packages.
Package names are written in all lowercase.
Posts
Method overloading in java
Method overloading is the process of having mulitple method defination with a single name. The complier knows which one to call on the basis of the signature of the method which ever signature matches the call that method is invoked.
By default while overloading if the contract doesn’t match it tries to type convert and see if any siganture match like you can have a method to add two ints and if you try to call it with chars it will get invoked.
Posts
Data types in java
Java is a very strict language when it comes to types. If you want to do anything remotely complex you need to know what types are available.
For simply declaring a function you need to know what type you’ll return and what types you’ll accept beforehand which makes your life simple and complex at the same time.
It makes your life simple when you’re writing the method but When you’re trying to come up with it’s signature you need to spend time to ensure you’re defining it correctly.
Posts
Starting With Java
Java is a type specific language which is a lot stricter than javascript.
Let’s follow the journey of java code.
First Java code is compiled into byte code by a compiler. Byte code is highly optimised so the code can be run quickly by JVM Java Virtual Machine. JVM combined with some System Library make a JRE Java Run Time Environment. The compiler and the JRE together make JDK Java Development Kit.
Posts
Hosting Hugo on GitHub
Hosting your static site on Git Hub. This post assumes that you followed this tutorial to create your hugo static site on local machine.
Create a repo on GitHub To host your site on github you need to create your repo with a particular name
<username>.github.io You should push your repo here.
Add this file to automate github actions name: github pages on: push: branches: - main # Set a branch to deploy pull_request: jobs: deploy: runs-on: ubuntu-20.
Posts
Hugo
Hugo Hugo is a static site creator which allows you to write md files and converts them to beautiful html pages.
This tutorial is about developing a static site server on you local machine. We will see how you can install hugo in you machine we will create a site, we will add a theme and we will add a post to that site.
Installation Hugo is very easy to install and start working with it will get you writing really quickly.
Posts
Static Methods
Static Methods in JavaScript To understand static methods first we need to know what are normal methods of a class.
Normal Methods All methods are defined and their reference is stored only once inside a class.
So how do all instances of class have access to that method?
What happens is that each instance first looks for which class it belongs to then it goes and looks for the method reference that was called upon and then we can think that the instance is sent as the first argument to that method but in reality it is bound to that method so nobody needs to send it as an argument.