OCP

Java NIO.2

Posted on

Non blocking IO in Java, released with Java 7. Path Path represents a path on the storage system to a directory or file. Conceptually it is a replacement for the java.io.File class. Path path = Paths.get(/bla/bli/blu/blue.txt); Paths is the factory class for the interface Path. The  Paths class contains static factory methods that return a Path. […]

OCP

Java IO

Posted on

Yes, there are so many different Stream classes. (Now I am talking about IO Streaming) Here are some tips to keep them apart: All these classes inherit (in)directly from on of the following four abstract Classes InputStream OutputStream Reader Writer ! You cannot instantiate one of the above classes since they are all abstract If […]

OCP

Concurrency: threats or Threads

Posted on

In this post I go over the basis of concurrent execution in Java. I advise you to run the code snippets yourself to get the most out of it. This is an overview, not a tutorial. If you are able to explain the working of the example on the bottom yourself, you have a good […]

OCP

All is good.. except for Exceptions

Posted on

Point Out The Mistakes public class Mistakes { public static void main(String[] args) { try { throwException(); } catch (MissingResourceException e){ } catch (InputMismatchException e | FileNotFoundException e){ } catch (ParseException | ArrayIndexOutOfBoundsException e){ } catch (MissingResourceException | IllegalArgumentException e){ } catch (Throwable e){ } catch (IOException e){ } } private static void throwException() throws […]

OCP

It’s time..

Posted on

Did you know: Month.JANUARY is the same as Month.of(1) Month is an enum Month.JANUARY == 1 does not compile since Month is an enum and enums cannot be compared to an int Month.JANUARY.getValue() returns 1 because getValue is implemented as return ordinal() + 1 ZonedDateTimes can be created from a LocalDate, LocalTime and a ZoneId: LocalDate […]

OCP

Trick Question

Posted on

What is the output of the following code snippet: import java.time.*; public class DaylightSaving { public static void main(String[] args) { LocalDate date = LocalDate.of(2019, Month.MARCH, 31); LocalTime time = LocalTime.of(2,30); LocalDateTime dateTime = LocalDateTime.of(date, time); ZoneId zone = ZoneId.of(“Europe/Paris”); ZonedDateTime zonedDateTime = ZonedDateTime.of(dateTime, zone); System.out.println(zonedDateTime); } } Scroll down..           […]