Posts

Showing posts with the label Blog

Java 8 – Iterate Over A HashMap

This quick tutorial is going to show how to iterate over a HashMap in Java 8 and prior version as well.1.  Iterate Over A HashMap in Java 8We can use foreach default method of the Map interface to iterate over a HashMap in Java 8, for example: public static void main(String args[]) { Map<Integer, String> itemsMap = new HashMap<>(); itemsMap.put(1, "One"); itemsMap.put(2, "Two"); itemsMap.put(3, "Three"); itemsMap.forEach((key, value) -> { System.out.println("Key : " + key + " Value : " + value); }); } Another way is to iterate indirectly over the Set view of the Map, for example: Set<Map.Entry<Integer, String>> itemsSet = itemsMap.entrySet(); itemsSet.forEach((entry)-> { System.out.println("Key is " + entry.getKey() + " Value is " + entry.getValue()); }); 2.  Iterate Over A HashMap Prior To Java 82.1. Iterate over entries using For-Each …

Java 8 – How to Format Date, LocalDate, LocalDateTime and ZonedDateTime

This quick tutorial is going to cover about format date in Java 8. We’ll get through how to format a Date, LocalDate, LocalDateTime and ZonedDateTime in Java 8.1. Format A Date Object in Java 8A quick way to format a java.util.Date object in Java is to use the SimpleDateFormat class. Let’s see some examples as follows: @Test public void testFormatDate() { //create a date object by using Calendar Calendar calendar = new GregorianCalendar(2020, Calendar.AUGUST, 9); Date date = calendar.getTime(); //create a pattern String pattern = "dd/MM/yyyy"; SimpleDateFormat dateFormatter = new SimpleDateFormat(pattern); // format the date String olympicDate = dateFormatter.format(date); //Validate assertEquals("09/08/2020", olympicDate); } Below are some examples of patterns:PatternsExamplesyyyy/MM/dd2020/08/09yyyy/MM/dd HH:mm:ss2020/08/09 23:59:59yyyy/MM/dd HH:mm:ss.SSS2020/08/09 23:59:59.000EEEEE MMMMM yyyy HH:mm:ss.SSSSunday Aug…

Java 8 – Convert LocalDate and LocalDateTime to Date and Vice Versa

This quick tutorial is going to cover how to convert LocalDate and LocalDateTime to Date and vice versa in Java 8. And note that the LocalDate, LocalDateTime and Instant classes used in this tutorial are new data types introduced from Java 8.1. Convert LocalDate to Date in Java 8To convert a LocalDate object to a java.util.Date object in Java 8, we can use the syntax as follows: Date date = Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); Note that we are using the default zone which should be changed to your desired ones.Let’s see the following example which we convert a LocalDate object to a java.util.Date object. @Test public void testConvertLocalDateToDate() { LocalDate localDate = LocalDate.of(2017, 8, 10); Date date = Date.from(localDate.atStartOfDay().atZone(ZoneId .systemDefault()).toInstant()); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); assertEquals(localDate.getYear(), calendar.get(…

Configure Basic Authentication on Unirest for Java

1. IntroductionThis short tutorial is going to cover how to configure basic authentication on Unirest for Java, a simplified, lightweight HTTP request library built and maintained by Mashape.2. Configure Basic Authentication on Unirest for Java2.1. Library dependency <dependency> <groupId>com.mashape.unirest</groupId> <artifactId>unirest-java</artifactId> <version>1.4.9</version> </dependency> The only one Maven dependency for this example is the unirest-java, version 1.4.9. There are dependencies for Unirest-Java such as Apache Httpclient, Json, we will find them included automatically in the classpath.
The sample source code and related can be found on my Github project.2.2. Basic Authentication with Native APIUnirest supports Basic Authentication natively. As as result, authenticating the request with basic authentication can be done simply by calling the basicAuth(username, password) function, for example: @Test public …

Making the web smoother with independent rendering

Image
Independent rendering allows the browser to selectively offload graphics processing to an additional CPU thread, so they can be rendered with minimal impact to the user interface thread and the overall visible performance characteristics page, such as silk-smooth scrolling, responsive interactions, and fluid animations. This technique was pioneered in Internet Explorer 11, and is key to providing a fluid experience.Today, we’re excited to share major improvements to the independent rendering pipeline in Microsoft Edge which will make pages significantly faster in EdgeHTML 16 and the Windows 10 Fall Creators Update.Independent rendering is transformative to the user experience — but historically there have been a few elements that could disable it entirely when present on a page.<select> control<canvas> elementcertain <svg> elementsStarting with EdgeHTML 16, we’ve enabled independent rendering on more sites by adding full support for the elements listed above. These i…

Vagrant – Copy Files and Folders From Host To Guest

Image
1. OverviewThis tutorial will show how to copy files and folders from host to guest in Vagrant.2. Copy Files and Folders from Host to Guest in Vagrant2.1. Using Synced Folders or Shared FoldersSynced folders or Shared folder enable Vagrant to sync a folder on the host machine to the guest machine, allowing you to continue working on your project’s files on your host machine but use the resources in the guest machine to compile or run your project.By default, Vagrant will share our project directory (the directory with the Vagrantfile) to /vagrant. Let’s see an example of the defaut shared folder created by Vagrant on VirtualBox:
Default Synced Folders In Vagrant To configure another synced folder, you can follow the below syntax: Vagrant.configure("2") do |config| # other config here config.vm.synced_folder "/home/data/", "/data/shared" end For more detail, you can read this basic usage page.In short, to copy files and folders from host to guest in Vag…

ES Modules in Node Today!

Where Does Vagrant Store Its Boxes After Downloading?

Image
This quick tutorial is going to cover about where does Vagrant store its boxes after downloading.1. Where does Vagrant store its boxes?By default, Vagrant stores its boxes after downloading in the directory defined by VAGRANT_HOME environment variable. As a result,On Mac OS X and Linux: ~/.vagrant.d/boxesOn Windows: C:/Users/USERNAME/.vagrant.d/boxes2. Change the directory where Vagrant stores its boxes?There are some situations that we may want to change the directory where Vagrant stores its boxes to other directories such as to backup the boxes, to reduce disk space on the main partition, etc. In such a case, we can change the VAGRANT_HOME variable to our desired location.Here is an example how we can change the VAGRANT_HOME environment to another location on Unix-like systems: export VAGRANT_HOME=/data/vagrant On Windows, we can use the “setx” command, for example: setx VAGRANT_HOME "D:\data\vagrant" Or you can:Open Control Panel –> System –> Advanced System Settin…

How To Install ActiveMQ on Ubuntu 16.04 LTS (Xenial Xerus)

Image
1. IntroductionApache ActiveMQ is a popular and powerful open source messaging and Integration Patterns server. In this guide, we’re going to install ActiveMQ on Ubuntu 16.04.2. PrerequisitesJava 1.7 or later.The JAVA_HOME environment variable is set correctly.3. Install ActiveMQ on Ubuntu 16.04 Manually3.1. Download the ActiveMQWe can download the ActiveMQ zipped tarball file from ActiveMQ website, using either a browser or a tool, i.e., wget, scp, ftp, etc. For example, the following command will download ActiveMQ version 5.15.0. http://ift.tt/2vjCSU6 3.2. Extract the files from the zipped tarball into a directory of your choice.For example, the following command will extract the downloaded file into /opt/apache-activemq-5.15.0/ sudo tar -xf apache-activemq-5.15.0-bin.tar.gz -C /opt/ 3.3. Start ActiveMQTo start ActiveMQ in foreground: sudo /opt/apache-activemq-5.15.0/bin/activemq console To start ActiveMQ in background: sudo /opt/apache-activemq-5.15.0/bin/activemq start 3.4. Verif…

Install Apache Kafka On Windows

This quick tutorial is going to cover how to install Apache Kafka on Windows.1. PrerequisitesInstall Java (The latest released version of JDK 1.8 is recommended)2. Download Apache Kafka DistributionDownload an Apache Kafka distribution from its website. The current version is 0.11.0.0. After downloading, extract it to any desired location, for example, D:\kafka_2.11-0.11.0.0. Then open Command Prompt (cmd) and go to that directory: cd D:\kafka_2.11-0.11.0.0 3. Start the server3.1. Start ZooKeeperKafka uses ZooKeeper so you will need to first start a ZooKeeper server first. You can use your own ZooKeeper or use the single-node ZooKeeper instance packaged with Apache Kafka. In this tutorial, we will use the ZooKeeper packaged with Kafka.Let’s start the ZooKeeper by running the below command: .\bin\windows\zookeeper-server-start.bat config\zookeeper.properties The successful start will output the logs to the command prompt similarly to below: INFO maxSessionTimeout set to -1 (org.apache.…

Node-ChakraCore Update: N-API, Node.js on iOS and more

Image
Today, we are happy to announce a new preview release of ChakraCore, based on Node.js 8, available for you to try on Windows, macOS, and Linux.We started our Node-ChakraCore journey with a focus on extending the reach of Node.js to a new platform, Windows 10 IoT Core. From the beginning, it’s been clear that in addition to growing the reach of Node.js ecosystem, there’s a need to address real problems facing developers and the Node.js ecosystem though innovation, openness and community collaboration.As we continue our journey to bring fresh new ideas and enable the community to imagine new scenarios, we want to take a moment to reflect on some key milestones we’ve achieved in the last year.Full cross-platform supportWhile ChakraCore was born on Windows, we’ve always aspired to make it cross-platform. At NodeSummit 2016, we announced experimental support for the Node-ChakraCore interpreter and runtime on Linux and macOS.In the year since that announcement, we’ve brought support for ful…

The End of an Era – Next Steps for Adobe Flash

Today, Adobe announced that Flash will no longer be supported after 2020. Microsoft will phase out support for Flash in Microsoft Edge and Internet Explorer ahead of this date.Flash led the way on the web for rich content, gaming, animations, and media of all kinds, and inspired many of the current web standards powering HTML5. Adobe has partnered with Microsoft, Google, Mozilla, Apple, and many others, to ensure that the open web could meet and exceed the experiences that Flash has traditionally provided. HTML5 standards, implemented across all modern browsers, provide these capabilities with improved performance, battery life, and increased security. We look forward to continuing to work with Adobe and our industry partners on enriching the open web without the need for plug-ins.We will phase out Flash from Microsoft Edge and Internet Explorer, culminating in the removal of Flash from Windows entirely by the end of 2020. This process began already for Microsoft Edge with Click-to-Ru…

Register now for Microsoft Edge Web Summit 2017

Image
Registration is now open for Microsoft Edge Web Summit 2017. Join the Microsoft Edge team in Seattle for a jam-packed day of energetic technical sessions looking at what’s new, and what’s next, for the web on Windows. Space is limited and reservations are on a first-come, first-served basis, so book your seat today!Microsoft Edge Web Summit is a free conference presented by the engineers building Microsoft Edge. The main track consists of 14 jam-packed technical sessions, covering everything from performance, accessibility, and test guidance, to brand-new tools and APIs for building Progressive Web Apps on Windows, adding payments and biometric authentication to your sites, and building modern layouts with new CSS features like CSS Grid.This year, we’re introducing a new Hallway Track, where you can meet with engineers from across Microsoft to solve real problems today, and build invaluable connections for the future. Looking to reduce a troublesome performance issue? Struggling with …

An update on disabling VBScript in Internet Explorer 11

Beginning in the Windows 10 Fall Creators Update, we intend to disable VBScript execution in IE 11 for websites in the Internet Zone and the Restricted Sites Zone by default, to provide a more secure experience. This change was initially announced in a blog post in April. The new default behavior can be previewed beginning with today’s Windows Insider Preview release, build 16237.For customers on previous versions of Windows, we intend to include this change in future cumulative security updates for Internet Explorer 11.The settings to enable, disable, or prompt for VBScript execution in Internet Explorer 11 will remain configurable per site security zone, via Registry, or via Group Policy, on released versions of Windows. We will continue to post updates here in advance of these changes to default settings for VBScript execution in Internet Explorer 11.To provide feedback on this change, or to report any issues resulting from this change in Windows Insider Preview, you can use the Fe…

Save the date: Microsoft Edge Web Summit 2017 comes to Seattle on September 13th

Image
We’re thrilled to announce that our third annual Microsoft Edge Web Summit is coming to Seattle on September 13th, 2017! Registration opens next month on dev.microsoftedge.com.Microsoft Edge Web Summit 2016 Microsoft Edge Web Summit is your one stop to see what’’s next for the web on Windows. Join us for a jam-packed day of energetic technical sessions, where we’ll take a closer look at what’s new and what’s next for Microsoft Edge. We’ll dive deep into what’s new in EdgeHTML, the Chakra JavaScript engine, and the user experience of Microsoft Edge.You’ll learn how to use exciting new web platform features like Service Worker, Web Authentication, and CSS Grid to build modern, performant experiences with native-like capabilities. And you’ll have an opportunity to try out next-generation experiences built with technologies like Progressive Web Apps, WebVR, and lots more.Best of all, you’ll find great opportunities for networking during and after the event. You’ll make new friends and valu…

Improved JavaScript performance, WebAssembly, and Shared Memory in Microsoft Edge

Image
JavaScript performance is an evergreentopic on the web. With each new release of Microsoft Edge, we look at user feedback and telemetry data to identify opportunities to improve the Chakra JavaScript engine and enable better performance on real sites.In this post, we’ll walk you through some new features coming to Chakra with the Windows 10 Creators Update that improve the day-to-day browsing experience in Microsoft Edge, as well as some new experimental features for developers: WebAssembly, and Shared Memory and Atomics.Under the hood: JavaScript performance improvementsSaving memory by re-deferring functionsBack in the days of Internet Explorer, Chakra introduced the ability to defer-parse functions, and more recently extended the capability to defer-parse event-handlers. For eligible functions, Chakra performs a lightweight pre-parsing phase where the engine checks for syntax errors at startup time, and delays the full parsing and bytecode generation until functions are called for …

Modernizing the DOM tree in Microsoft Edge

Image
The DOM is the foundation of the web platform programming model, and its design and performance impacts the rest of the browser pipeline. However, its history and evolution is far from a simple story.What we think of as “the DOM” is really the cooperation of several subsystems, such as JS binding, events, editing, spellchecking, HTML attributes, CSSOM, text, and others, all working together. Of these subsystems, the DOM “tree” is at the center.A diagram of the web platform pipeline. This post focuses on the DOM tree and cooperating components. Several years ago, we began a long journey to update to a modern DOM “tree” (node connectivity structures). By modernizing the core tree, which we completed in Microsoft Edge 14, we landed a new baseline and the scaffolding to deliver on our promise of a fast and reliable DOM. With Windows 10 Creators Update and Microsoft Edge 15, the journey we started is beginning to bear fruit.“The DOM” is really the cooperation of several subsystems that make…