Posts

Showing posts from 2019

C examples: simple input to output

Image
C programming language is one of the most used in the world. Actually by TIOBE index 2018 it is placed at the second stage of the most cited languages. In the series of posts C examples I will introduce different examples of C code. Today I start with first example. It is simple program that accepts input from stdin and returns it to stdout. /* Copy input to output */ #include int main(void) { int c; while ((c=getchar()) != EOF) putchar(c); return 0; }

Differences between abstract class and interface in Java

Image
One of the most frequently asked questions on Java job interview: " What the difference between abstract class and interface in Java? " And in this post I will try to answer that question. The differences are following: The number of extendings . An abstract class can extend only one typical Java class or one abstract class at a time. But an interface can extend any number of interfaces at a time. What can extend . An abstract class can extend concrete (regular) class or abstract class. But interface can extend another interface only. Keyword "abstract" for methods . Keyword "abstract" is mandatory for declaring a method as an abstract in abstract class. But in interface that keyword is optional, because methods abstract here by default. Access modifiers for methods . An abstract class can have protected and public abstract methods. But interface can have public abstract methods only. Variables . An abstract class can have static, final or static f...

Ways of creating threads in Java

Image
In this post I will tell you about how to create threads in Java. So, let's get started! Threads in Java are objects. They are instances of java.lang.Thread class or its subclasses. There are two ways of creating threads in Java: First . We can just create an instance of Thread class . Thread thread = new Thread(); // And start it thread.start(); But this is useless, because our thread has no code to execute. Instead we can extend Thread class and create our subclass of Thread with custom code to execute. public class CustomThread extends Thread { public void run(){ System.out.println("Our custom thread is running"); } } CustomThread customThread = new CustomThread(); customThread.start(); In method run we can put all necessary code to execute in our thread. Also we can create anonymous subclass of Thread class. Thread thread = new Thread(){ public void run(){ System.out.println("This is anonymous subclass of Thread. And it...

Get links to all articles from site with python

Image
Hi, everybody! In this post will tell you about one small python script. Recently I have met task to get all links to articles from my blog. I have made some Google search and find some points to this task. I used python and its package BeautifulSoup for html parsing. Also used re module and urllib3 for http request. Here is it, my script. I will be happy if you find it usefull. from bs4 import BeautifulSoup import urllib3 import re links = [] site = "https://alextech18.blogspot.com" pattern = "://alextech18.blogspot.com" def getLinks(url, pattern, html_only=True): http = urllib3.PoolManager() html_page = http.request('GET', url) soup = BeautifulSoup(html_page.data, features="html.parser") # Use separate pattern, because, blogspot for example, can use links leading with http and https for link in soup.findAll('a', attrs={'href': re.compile(pattern)}): if link.get('href') not in links...