Machibet777 Live<![CDATA[Stories by Yuresh Karunanayake on Medium]]> http://jeetwincasinos.com/@yureshcs?source=rss-a5b5c2db4ff6------2 http://cdn-images-1.jeetwincasinos.com/fit/c/150/150/1*QUwOtnImsCWakURFo-NXAA.jpeg Mcb777 Affiliate<![CDATA[Stories by Yuresh Karunanayake on Medium]]> http://jeetwincasinos.com/@yureshcs?source=rss-a5b5c2db4ff6------2 Medium Sun, 25 May 2025 21:48:08 GMT Mcb777 Bet<![CDATA[Stories by Yuresh Karunanayake on Medium]]> http://jeetwincasinos.com/@yureshcs/java-memory-management-with-collections-2e3c925edc07?source=rss-a5b5c2db4ff6------2 http://jeetwincasinos.com/p/2e3c925edc07 Sun, 28 Jan 2024 12:30:39 GMT 2024-01-28T14:26:54.456Z

Introduction to the Collection Framework

A collection is a container object that holds a collection of objects. The collection framework provides a unified interface to store, retrieve and manipulate the elements of a collection, regardless of the underlying actual implementation. This allows the programmers to program at the interface specification instead of the actual implementation.

Java’s data structures

  • Prior to JDK 1.2 - array, Vector, and Hashtable
  • After JDK 1.2 introduced the unified collection framework, and modify the legacy classes (Vector and Hashtable) to conform to this unified collection framework.
  • JDK 5 introduced Generics (which supports passing of types), Make collection framework to support generics.
Ref : Outline of the Collections Framework

Collection Sizing

Collection classes are designed to expand as necessary which could hold numerous data.

Although the data types provided by collection classes in Java are quite rich, at a basic level those classes must hold their data using only Java primitive data types: numbers (integers, doubles, and so on), object references, and arrays of those types.

Hence, an ArrayList contains an actual array

As items are added and removed from the ArrayList, they are stored at the desired location within the elementData array

Similarly, a HashMap contains an array of an internal data type called HashMap$Entry, which maps each key-value pair to a location in the array specified by the hashcode of the key.

Not all collections use an array to hold their elements. A LinkedList for example, holds each data element in an internally defined Node class.

Collection classes that do use an array to hold their elements are subject to special sizing considerations.

How to identify a particular class use an array to hold data ?
Look at its constructors. if it has a constructor that allows the initial size of the collection to be specified, then it is internally using some array to store the items.

In the ArrayList, the elementData array will (by default) start out with an initial size of 10. When the 11th item is inserted into an ArrayList, the list must expand the elementData array. This means allocating a new array, copying the original contents into that array, and then adding in the new item.

The ArrayList class chooses to resize the array by adding roughly half of the existing size, so the size of the elementData array will first be 10, then 15, then 22, then 33, and so on.

In the HashMap also the principle is the same. At some point, those internal structures must be resized.

Whatever algorithm is used to resize the array there has a wasted memory Additionally, each time the array must be resized, an expensive array copy operation must occur to transfer the contents from the old array to the new array. To minimize those performance penalties, make sure to construct the collection with as accurate an estimate of its ultimate size as possible.

For sparsely used collections, it can waste a large amount of memory if they are used extensively. One way to deal with that is to size the collection when it is created. Another way is to consider whether a collection is really needed in that case at all. When most developers are asked how to quickly sort any array, they will offer up quick‐ sort as the answer.

All implementations of the Set interface in Java 6 are based on an underlying Map. What ? Yeah Set’s values as Keys and ‘PRESENT’ as the value!
A wastage of memory is definitely there. Map cannot contain duplicate keys. May be to achieve collection without duplicates, they used Map backing for the Sets + more.

The HashSet’s starting capacity is 16 and it has a load factor of 0.75. The threshold for the HashSet to increase its capacity is when it reaches 75% of its initial capacity.

Example:

The starting size of HashSet is 16 . Once the load factor (0.75) or 16 * 0.75 = 12 is reached, and 12th is added, the size increases to doubled , also known as 32 .

What is called as the load factor ?
load factor determines the maximum occupancy of the hash table before its capacity increases automatically. Once the number of entries surpasses the product of the load factor and the current capacity, the hash table undergoes rehashing to rebuild its internal data structures. This results in an increased number of buckets, approximately double the original amount
Java collections only store Object References. so we need to box primitives to store. if you work with primitives and collections, whenever autoboxing happens, performance definitely takes a little bit !
Keep in mind : An Integer is not a substitute for an int. autoboxing and unboxing blur the distinction between primitive types and reference types.
Ref :

Memory consumption related with Collections

primitive data types

  • byte, Boolean — 1 byte.
  • short, char — 2 bytes.
  • int, float — 4bytes.
  • long, double — 8bytes.

Numeric wrappers

Numeric wrappers occupy 12 bytes + size of the underlying type:

  • Byte, Boolean — 12 bytes +1 byte Data type +3 bytes alignment = 16 bytes.
  • Short, Character — 12 bytes +2 bytes Data type +2 bytes alignment =16 bytes.
  • Integer, Float — 12 bytes +4 bytes Data type =16 bytes.
  • Long, Double — 12 bytes +8 bytes Data type +4 bytes alignment = 24bytes.

ArrayList

It has an Object[] for storage plus an int field for tracking the list size.
so 4 bytes (but may be more if ArrayList capacity is seriously more than its size).

LinkedList

Each LinkedList node contains references to the previous and next elements as well as a reference to the data value.
So 12 bytes header + 3*4 bytes for references, which is 6 times more than ArrayList in terms of per-node overhead.

HashMap, HashSet

Memory consumption of a HashSet is identical to HashMap.
It contains a key, a value, hash of a key and an int and a pointer to the next entry. So an entry occupies 32 bytes (12 bytes header + 16 bytes data + 4 bytes padding).

LinkedHashMap

LinkedHashMap consumes 40 * SIZE + 4 * CAPACITY bytes.

TreeMap , TreeSet

A tree contains exactly some nodes. Each tree node contains: key, value, pointers to the left and right children, pointer to a parent and a boolean ‘colour’ flag.
so a node occupies: 12 bytes for header + 20 bytes for 5 object fields : int key,int value,int left pointer,int right pointer,int parent pointer + 1 byte for flag
TreeMap memory consumption is identical: 40 * SIZE bytes.

Data Expansion in Non Collection Classes

Many non collection classes also store lots of data in an internal array.

For example, the ByteArrayOutputStream class must store all data written to the stream into an internal buffer.

The StringBuilder and StringBuffer classes must similarly store all their characters in an internal char array.

Most of these classes use the same algorithm to resize the internal array: it is doubled each time it needs to be resized. This means that, on average, the internal array will be 25% larger than the data it currently contains.

The performance considerations here are similar. The amount of memory used is larger than in the ArrayList , and the number of times data must be copied is less, but the principle is the same. Whenever you are given the option to size a object when it is constructed and it is feasible to estimate how much data the object will eventually hold, use the constructor that takes a size parameter.

]]>
Mcb777 Affiliate<![CDATA[Stories by Yuresh Karunanayake on Medium]]> http://jeetwincasinos.com/@yureshcs/simple-history-of-programming-languages-db299d16b8e4?source=rss-a5b5c2db4ff6------2 http://jeetwincasinos.com/p/db299d16b8e4 Fri, 24 Feb 2023 08:03:07 GMT 2024-01-28T15:47:37.234Z

1883: The first programming language was developed in 1883 when Ada Lovelace and Charles Babbage worked together on the Analytical Engine, which was a primitive mechanical computer. Lovelace was able to discern the importance of numbers, realizing that they could represent more than just numerical values of things. Lovelace wrote an algorithm for the Analytical Engine, the first computer program, to compute Bernoulli numbers.

1949: Assembly language was first used as a type of computer programming language that was able to simplify machine code language, which is necessary for telling a computer what to do.

1952: Alick Glennie developed Autocode, which some consider to be the first compiled computer programming language. This means it could be translated directly into machine code.

1957: John Backus created FORTRAN, which is a computer programming language for working with scientific, mathematical, and statistical projects.

1958: Algol was created as an algorithmic language. It was also a precursor to programming languages such as Java and C.

1959: COBOL was created by Dr. Grace Murray Hopper to be a language that could operate on all types of computers.

1959: John McCarthy created LISP, which is still used today. This programming language was designed for use in artificial intelligence research, and today, it can be used with Python and Ruby.

1964: John G. Kemeny and Thomas E. Kurtz developed BASIC for students without a strong background in technology and math, enabling them to still use computers.

1970: Niklaus Wirth developed Pascal, naming it after Blaise Pascal. This language is easy to learn and was the main language used by Apple for early software development.

1972: Alan Kay, Adele Goldberg, and Dan Ingalls developed Smalltalk, which enabled computer programmers to change code quickly.

1972: Dennis Ritchie developed C, generally regarded as the first high-level programming language. This means that it’s closer to human language and less like machine code.

1972: Donald D. Chamberlin and Raymond F. Boyce developed SQL for IBM. This language was used for viewing and changing data stored in databases.

1978: Cleve Moler developed MATLAB for writing math programs. This language is used for research and education.

1983: Brad Cox and Tom Love created Objective-C as the main language used for writing Apple software.

1983: Bjarne Stroustrup created C++, which is an extension of the C programming language. This is one of the most used languages in the world.

1987: Larry Wall developed Perl as a scripting language, used for text editing to simplify report processing.

1990: Haskell was developed as a functional computer programming language used to process complicated math calculations.

1991: Guido Van Rossum developed Python, which is a simplified computer language that is easy to read.

1991: Microsoft developed Visual Basic, which enabled programmers to select and change specific chunks of code with a drag-and-drop process.

1993: Ross Ihaka and Robert Gentleman developed R for statisticians who needed to perform data analysis.

1995: Sun Microsystems developed Java, originally intended to be used with hand-held devices.

1995: Rasmus Lerdorf developed PHP, mainly for Web development. PHP continues to be widely used in Web development today.

1995: Yukihiro Matsumoto developed Ruby as an all-purpose programming language, ideal for many programming jobs. Ruby is widely used in the development of Web applications.

1995: Brendan Eich developed JavaScript to enhance interactions.

2000: Microsoft developed C# as a combination of C++ and Visual Basic. C# is similar to Java in some ways.

2003: Martin Odersky created Scala as a programing language that combines aspects of functional programming.

2003: James Strachan and Bob McWhirter developed Groovy as an offshoot of Java.

2009: Google developed Go to solve issues that commonly occur with large software systems.

2014: Apple developed Swift to replace C, C++, and Objective-C.

More on Programming Languages

  • : Initially, programming languages consisted of a series of steps required to wire a computer program.
  • : Java and C are two of the most popular programming languages used today.
  • : Programming languages have simplified computer processes significantly over the past several decades.
  • : The 1950s saw a number of significant developments in computer programming progress.
  • : Programming languages actually date back more than 150 years to the first language developed to make a machine perform tasks.
  • : During the 1970s, programming languages began to get simpler and easier to use.
  • : FORTRAN was the first computer programming language that was widely used.
  • : Computer code is the foundation of computers, enabling them to do the tasks humans need them to do.
  • : Review a fascinating timeline of computer history with key events noted and explained.
  • : Programming languages continue to evolve as computers and applications change.
]]>
Machibet777 Casino<![CDATA[Stories by Yuresh Karunanayake on Medium]]> http://jeetwincasinos.com/@yureshcs/why-you-should-learn-java-bacffaf966bf?source=rss-a5b5c2db4ff6------2 http://jeetwincasinos.com/p/bacffaf966bf Tue, 07 Feb 2023 20:21:12 GMT 2023-02-07T20:21:12.115Z Java is a programming language that has been around since 1995 . Since 95 it has received lots of upgrades and new features .From 2009 it send new upgrades to the language every six months.

Does Java is dying ?
all of these Tech Giants Google matter Facebook(meta) Microsoft Twitter and a bunch of other Tech Giants are using Java to power their critical systems and open source projects

On research performed by stack Overflow across the world you can see that the programming and script and markup languages right here Java is number six on this list and professional developers also in sixth position.

people that are learning how to code it’s also oh actually it’s number four

as a beginner I feel like you should learn . why?

Java is a language that teaches you a bunch

of fundamentals that other programming languages

the good thing is if you learn Java than learning JavaScript or python then

those languages would be a piece of cake trust me !

it would be a piece of cake now if you reverse so

if You Learn Python for example or you learn JavaScript for example and then try and move
to Java it’s going to be really difficult
But it is easy to shift to any other language after you lear java well.

Java is an
object-oriented programming language and that means that you kind of that create a bunch of
classes and you create objects and connect them to each other
SO you can create well-structured large-scale applications

Java has large active community of developers with that you’ve got great tooling

Has Frameworks so spring Boot quarkers and other libraries that you know

companies such as Google they’re behind it there’s plenty of tools and Frameworks available to you in


should you learn Java ecosystem ?

absolutely yes and do me a favor remember that don’t stick with just one language so I always say

this because a language is just a tool yes you can have a preferred language but just remember that

if you have to pick a different language then you will be able to do right because it’s just a tool

to solve a problem l

]]>
Machibet Live<![CDATA[Stories by Yuresh Karunanayake on Medium]]> http://jeetwincasinos.com/@yureshcs/services-and-service-provider-with-java-9-modules-ddd0170749b0?source=rss-a5b5c2db4ff6------2 http://jeetwincasinos.com/p/ddd0170749b0 Sun, 08 Aug 2021 17:36:07 GMT 2021-08-09T06:11:54.658Z

Before we start Java SPI with modules, you must have a general understanding of java modules which was introduced in Java 9. It's good if you have an idea on creating a Multi-Module Maven Project in Eclipse.

Java Service & Service Provider used to do something like a plug-in to the core application (pluggable application architecture).

Service Interface: It is an interface or abstract class that a Service defines.
Service Provider: Has specific implementations of a service interface. A Service could have zero, one, or many service providers.
ServiceLoader: The main class used to discover and load a service implementation.

ServiceLoader

ServiceLoader is a generic class packaged in java.util package. Service providers are loaded by the load( ) method.

public static <S> ServiceLoader<S> load(Class <S> serviceType)

‘S’ specifies the service type which specifies the Class object for the desired service type.

ServiceLoader.load(serviceType) returns an instance of ServiceLoader, which itself implements Iterable. So we can iterate over the result.

How Does ServiceLoader Find a Class?

Before Java 9, ServiceLoader finds the implementations for a Service from the file in META-INF/services which has a fully qualified name same as the Service interface. It contains a list of fully qualified names of the implementations.

Java 9 changes Service Loader works, from the META-INF/services folder to a module-specific implementation.
From the module declaration, we can define the service and their implementation that a ServiceLoader could load.

The Service-Based keywords in module declaration

1) provides … with

A module can specify that it provides a service with a specific type of service provider. It is declared using ‘provides’ and `with` keyword.
So the implementation of that interface will expose for the ServiceLoaders.
Can specify multiple implementations types as a comma-separated list.

syntax : provides serviceType with implementationTypes;

module greeting.messages { 
requires greeting.api;
provides greeting.api.MessageService with
greeting.messages.FriendlyMessage,
greeting.messages.AngryMessage,
greeting.messages.EmotionalMessage ;
}

‘provides’ does not equal ‘exports’. So any other modules that requires ‘greeting.messages’ can not access FriendlyMessage , AngryMessage and EmotionalMessage if they doesn't exports.

2) uses

A module can indicate that it requires a service with ‘uses’ keyword

syntax: uses serviceType

module greeting.client { 
requires greeting.api;
uses greeting.api.MessageService;
}

The types inside the ‘greeting.client’ module’s packages , can use the instances of ‘MessageService’ implementations via the ‘ServiceLoader’.

NOTE : The keywords exports, module, open, opens, provides, requires, uses, with, to, and transitive, which we introduced with Java 9, are restricted keywords. These keywords are only in module declarations and can use as identifiers anywhere else in the code.

A sample project

You can download the multi-module Maven project from

Overview of the Maven Project

The Maven root project (greetings) contains all the following sub-modules.
greeter.api: Contains the Service Interface which is MessageService.
greeter.message: The providers for the Message Service.
greeter.client: An application to put all together and create a working example.

The Structure of the code is as follows

The Service Interface Module — greeter.api

package greeting.api;
public interface MessageService {
String getMessage();
}
  • module declaration
module greeting.api {
exports greeting.api;
}

The Service Provider Module — greeter.messages

package greeting.messages;
import greeting.api.MessageService;
public class FriendlyMessage implements MessageService  {
   @Override
public String getMessage() {
return "Hi Friend";
}
}
  • module declaration
module greeting.messages { 
requires greeting.api;
provides greeting.api.MessageService with
greeting.messages.FriendlyMessage,
greeting.messages.AngryMessage,
greeting.messages.EmotionalMessage ;
}

The Service Loader Module — greeter.client

package greeting.client;
import java.util.ServiceLoader;
import greeting.api.MessageService;
public class TestClient {
   public static void main(String[] args) {
ServiceLoader<MessageService> ms =
ServiceLoader.load(MessageService.class);

for (MessageService m : ms) {
System.out.println(m.getMessage());
}
}
}
  • module declaration
module greeting.client {
requires greeting.api;
uses greeting.api.MessageService;
}
ServiceLoader<MessageService> m=ServiceLoader.load(MessageService.class);

From ServiceLoader.load() ,
 — Return all instances that have implemented ‘MessageService’
 — Could be 0, 1, or more instances

Here, ServiceLoader gets the instances of the implementation of ‘MessageService’ Type.

Can get the return Strings from getMessage() when iterating over it.

]]>
Machibet APP<![CDATA[Stories by Yuresh Karunanayake on Medium]]> http://jeetwincasinos.com/@yureshcs/git-github-gitlab-bitbucket-38e5706b08ef?source=rss-a5b5c2db4ff6------2 http://jeetwincasinos.com/p/38e5706b08ef Wed, 20 Nov 2019 04:55:35 GMT 2019-11-20T04:55:35.637Z Confusing? Let starts . . .

Version Control System — Numbering the changes made in a computer program or document. In professional development, version control is associated with an incremental number than the previous version, This helps in comparison with the past versions.

Git —a Version Control System ( others ex : SVN , Mercurial).

GitHub — to host Git projects (others ex: BitBucket, GitLab). It is a command-line based software.

This repository is the central repository for your files. After creating a repository, you will have a copy version of central, in your local system (synonyms: Local Repo, Working directory). You can add changes to Local Repo and then transfer(Push) those changes to central.

GitKraken — GUI frontend for Git (Others ex : GitHub Desktop). You don’t really need a GUI to get things going.

Extra points

You can use Git , with both GitHub and BitBucket.

GitHub, BitBucket and GitLab are all services that can host Git repositories.

A branch represents an independent line of development for your repository

Commands

git status — Show your changes that done to the local Repo. Another term, how your project is progressing in comparison to your Bitbucket repository.

git pull — merges the file from your remote repository into your local repository.

]]>
Mcb777 Login<![CDATA[Stories by Yuresh Karunanayake on Medium]]> http://jeetwincasinos.com/@yureshcs/string-class-in-java-951237a6ad49?source=rss-a5b5c2db4ff6------2 http://jeetwincasinos.com/p/951237a6ad49 Wed, 06 Feb 2019 12:38:30 GMT 2019-02-06T19:39:01.484Z String str_1 = new String(“ABC”);
String str_2 = “ABC” ;

Are these two same ? or not ? doubt ? Lest Continue !

String is a sequence of characters. A java string is an object of the java.lang.String class .So when we creating strings in java , actually they implemented as instances of String class. String pool is a pool of Strings that are stored in Heap memory. String cannot be changed after they are created (immutable) ? what ? I have changed them ? Lets see !

Creating Strings

String str_1 = new String(“ABC”);

“ABC” is stored in string pool and using new operator , new String object is created in the heap space. Two objects are created ! . str_2 is points to that object. (str_2 reference address is stored in the stack memory).

String str_2 = “DEF” ;

JVM looks for “DEF” in the String pool if not “DEF” stored in the string pool and returns the reference. If it found string with same name in string pool , JVM just returns the reference. So both their addresses are same.(pointing to a one object).

Let's Explore if they created collectively

Procedures — 1

String str_1 = "ABC";
String str_2 = new String("ABC");

Only two objects will created. One in the Stringpool and other is in the Heap.

Procedures — 2

String str_1 = new String("ABC");
String str_2 = "ABC";

Only two objects will created. One in the Stringpool and other is in the Heap.

str_1.equals(str_2); //true

str_1 == str_2 ; // false

Procedures — 3

String str_1 = "ABC";
String str_2 = "ABC";

String object “ABC” created for str_1, when str_2 executing , JVM see that their is already a String object with same value. So the str_2 points to that object without creating new string object.

String cannot be changed after they are created (immutable) ?

String str = “Male”; //we want to change this ‘male’ into ‘female’

str = “Female” ; // Changed ?

Yes its value changed but what happen is , new string object with value “Female “ is created and ‘str’ point to it while the ‘male’ valued object remain in the memory until the programme ends.

How to check whether two or more objects have the same values.

Every object in Java includes an equal() and a hashcode() methods, but they must overridden to check whether multiple objects have the same values.

equal() → check whether the current instance is same as the previously passed object. ( Here we use it to compare two strings objects and determine whether they are equal )

public boolean equals(Object obj) {
return (this == obj);
}

hashcode() → help to identify objects uniquely.just to check whether two objects are the same or not. If hashcode() same, execute the equal() method to determine whether the values and fields are same.

public int hashCode() {
int h = hash;
int len = count;
if (h == 0 && len > 0) {
int off = offset;
char val[] = value;

for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
hash = h;
}
return h;
}

Example : boolean hashCheck = Str_1.hashCode() == Str_2.hashCode();

== Operator → It compares whether two object references are point to the same object.

Str_1 == Str_2 ; // true

QUIZ

  1. What is difference between String and StringBuilder and the pros and cons of using ?
]]>
Machibet777 Affiliate<![CDATA[Stories by Yuresh Karunanayake on Medium]]> http://jeetwincasinos.com/@yureshcs/what-is-a-wrapper-class-in-java-a5cddd37ff3d?source=rss-a5b5c2db4ff6------2 http://jeetwincasinos.com/p/a5cddd37ff3d Sat, 02 Feb 2019 19:12:17 GMT 2019-02-02T19:50:46.179Z

Wrapper class are the Object representation of primitive data types in java.

Integer obj= Integer(100);

int num = obj.intValue();

Have you experienced with these ? boxing unboxing ? No ? Let Start !

What is primitive data type ? There are most basic data types in java that serve as the building blocks of data manipulation. They are predefined by the language. The eight primitive data types supported by the Java programming language are boolean, byte, char, short, int, long, float and double.

In java programming we need to bind those primitive data types into Object. Hey Newton 3rd law ! There should have a way to take primitive data type out from object also.Lets see !

Corresponding wrapper classes for each primitive types

Wrapper class used to convert primitive data types into object. How ?

  1. Using wrapper class constructor → Integer obj= Integer(100);
  2. Using ‘valueOf()’ method → Integer obj= Integer.valueOf(100);

Bind primitive data types into Object in this manner is called as Boxing or wrapping.

So you can understand, taking primitive data type out from object is the Unboxing.

→ int num = obj.intValue();

Got some idea ? Let’s Jump into further !

BOXING

Byte / Short / Integer / Double / Boolean / Long Have two constructors that help to boxing(wrapping).

  1. To bind its data into the object → Double obj = new Double(20.51d);
  2. To bind its data in form of String → Double obj = new Double(“20.51”);

Float have three constructors for boxing

  1. To bind its data into the object → Float obj = new Float(50.28f);
  2. To bind its data in form of String → Float obj = new Float (“50.28”);
  3. To bind its data in form of Double → Float obj = new Float(50.28);

Character have only one constructor for boxing

  1. To bind its data into the object → Character obj = new Character (‘a’);
UNBOXING

Every wrapper class have its own unboxing(unwrapping) method.

Example → int num = obj.intValue();

We Bind string into primitive. We have to unwrap them also. For that we use ToString() method (Since every class in Java is a sub-class of Object and Object has toString() method, every class has a default toString() method.)

→Integer num = new Integer(“123”); // Bind the data in form of string

→ String numAsString = obj.ToString();

— — — — — — — — — — —EXPLORE — — — — — — — — — — — — — — — —

  1. What is a Object Oriented Language ?
  2. Is Java a pure Object oriented language ?
  3. What is the use of Boxing and Unboxing ?
  4. Why java collections can not store primitive types directly ?
  5. What is autoboxing in Java ?

— — — — — — — — — — — — NOTE— — — — — — — — — — — — — — — — Do not mix up boxing with the parsing.Parsing is just converting one data type to another data type.

String num = “123” ;
int y = Integer.parseInt(num);

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

This blog not include the entire stuff, I just tried to give you clear and basic understanding about wrapper class, boxing and unboxing. Practice it , read java documentation , gain further knowledge and help others to learn as you can !

]]>
Machibet777 APP<![CDATA[Stories by Yuresh Karunanayake on Medium]]> http://jeetwincasinos.com/@yureshcs/first-experience-with-opencv-870a7d736299?source=rss-a5b5c2db4ff6------2 http://jeetwincasinos.com/p/870a7d736299 Thu, 31 Jan 2019 19:08:56 GMT 2019-01-31T19:11:21.235Z

OpenCV is a computer vision and machine learning software library . It has C++, Python and Java interfaces.(Python-OpenCV is just a wrapper around the original C/C++ code. Python is slower than C/C++ because Python is written in C 👐 )

USES

  1. Read , Write , Analyse , Converting Colors , modifying Images.
  2. Detection of faces and its features. (eye , nose etc )
  3. Detection of objects , text , shapes in a image and many more . .

(Have more than 2500 optimized algorithms to do many crazy stuff .Considering learning speed than performance python is used here)

First Application with openCV

import cv2
img = cv2.imread(‘Hello.jpg’) #or full address“E:/CVimages/image.jpg”
cv2.imshow('Text at top',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
  1. Load image using imread().
  2. Display image using imshow().
  3. Wait for keyboard button press using waitKey().
  4. Destroys all the windows we created using cv2.destroyAllWindows().

Here include all basic stuff. After you finished above code , Search more about openCV and find extra knowledge. Keep in mind “ Different does not mean difficult ”

Jump ! Second Application with openCV

import cv2
face_cascade = cv2.CascadeClassifier(“C:\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml”)
cap = cv2.VideoCapture(0)
while 1:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
cv2.imshow(“img”,img)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()

Amazing ! your simple app track your face and draw a square around it .Nooo it is not . Just like you wrote your first “hello world” print.

  1. What is haarcascade ? Haar cascade algorithm ?
  2. What is Gray scale image ? what is a value of a pixel ?

Search and Learn by yourself !

Welcome to Computer Vision world ! See you soon with another

]]>