Skip to main content

Posts

Showing posts with the label Java

LinkedIn Skill Assessments | Java | Answers | #1

  Given the string "strawberries" saved in a variable called fruit, what would fruit.substring(2, 5) return ?  rawb  raw  awb  traw   Answer : raw Reasoning: The substring method is accepting two arguments. The first argument being the index to start(includes that char at 2) and the second the index of the string to end the substring(excludes the char at 5). Strings in Java are like arrays of chars. Therefore, the method will return "raw" as those are the chars in indexes 2,3, and 4. You can also take the ending index and subtract the beginning index from it, to determine how many chars will be included in the substring (5-2=3).

Junit

 JUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development, and is one of a family of unit testing frameworks which is collectively known as xUnit that originated with SUnit. JUnit is linked as a JAR at compile-time. The latest version of the framework, JUnit 5, resides under package org.junit.jupiter. Previous versions JUnit 4 and JUnit 3 were under packages org.junit and junit.framework, respectively. A JUnit test fixture is a Java object. Test methods must be annotated by the @Test annotation. If the situation requires it, it is also possible to define a method to execute before (or after) each (or all) of the test methods with the @BeforeEach (or @AfterEach) and @BeforeAll (or @AfterAll) annotations.

Find the number of negative integers from row wise or column wise from a sorted matrix

Find the number of negative integers from row wise or column wise from a sorted matrix This is a frequently asked question for a experienced interview. Here i am trying to solve this in two different ways, normal way and an optimised method. Main Class /** * */ package com . rakesh . matrix . bo ; /** * @author Rakesh KR * @since August 19th 13:15 2k17 */ public class RunMatrix { public static void main ( String [] args ) { MatrixUtils matrixUtils = new MatrixUtils (); try { System . out . println ( "------ Matrix ------" ); matrixUtils . makeMartix (); // matrixUtils.printMatrix(); matrixUtils . sortRowMatrix (); matrixUtils . transpose (); matrixUtils . sortRowMatrix (); matrixUtils . transpose (); // matrixUtils.printMatrix(); long t1 = System . currentTimeMillis (); System . out . println ( "NegativeNumbers Count Normal Way : " + matrixUtils . countNega...

Creating a new JavaFX application with NetBeans IDE

Step 1 : Open NetBeans IDE (Download from Here ) Step 2 : File - NewProject, then select JavaFx - > JavaFXML Application Step 3 : Give Project Name,  Location & Folder              Select JavaFX platform as JDK 8 Step 4 : Then a new project is created with following structure, Step 5 : Goto TestJavaFXApplication.java and Run & we will get following output. That's it... Go Ahead And Enjoy !!!  Learn More From Here Example Sample Calculator JavaFX Application   

JavaFX

JavaFX JavaFx is a set of graphics & media packages that enables developers to design rich client applications.  The look and feel of JavaFX applications can be customized. Cascading Style Sheets (CSS) separate appearance and style from implementation so that developers can concentrate on coding. Graphic designers can easily customize the appearance and style of the application through the CSS. If you have a web design background, or if you would like to separate the user interface (UI) and the back-end logic, then you can develop the presentation aspects of the UI in the FXML scripting language and use Java code for the application logic. KeyFeatures: Java API's FXML and Scene Builder WebView Swing interoperability Built-in UI controls and CSS Modena theme 3D Graphics Features Canvas API Printing API Rich Text Support Multitouch Support Hi-DPI support Hardware-accelerated graphics pipeline High-performance media engine Self-contained appli...

Java Dequeue

Problem In computer science, a double-ended queue (dequeue, often abbreviated to deque, pronounced deck) is an abstract data type that generalizes a queue, for which elements can be added to or removed from either the front (head) or back (tail). Deque interfaces can be implemented using various types of collections such as LinkedList or ArrayDeque classes. For example, deque can be declared as: Deque deque = new LinkedList<>(); or Deque deque = new ArrayDeque<>(); In this problem, you are given NN integers. You need to find the maximum number of unique integers among all the possible contiguous subarrays of size MM. Note: Time limit is 33 second for this problem. Input Format The first line of input contains two integers NN and MM: representing the total number of integers and the size of the subarray, respectively. The next line contains NN space separated integers. Constraints 1≤N≤1000001≤N≤100000 1≤M≤1000001≤M≤100000 M≤NM≤N The numbers in the arra...

Java String Token

Problem    Given a string, find number of words in that string.     For this problem a word is defined by a string of one or more english alphabets. Input Format   A string not more than 400000 characters long.    The string can be defined by following regular expression:       [A-Za-z !,?.\_'@]+   That means the string will only contain english alphabets,    blank spaces and this characters: "!,?._'@". Output Format   In the first line, print number of words nn in the string.    The words don't need to be unique. In the next nn lines,    print all the words you found in the order they appeared in the input. Sample Input   He is a very very good boy, isn't he? Sample Output 10 He is a very very good boy isn t he Solution import java.io.* ; import java.util.* ; public class Solution { ...

Abstract Class In Java

An abstract class is a class which cannot be instantiated. An abstract class is used by creating an inheriting subclass that  can  be instantiated. An abstract class does a few things for the inheriting subclass: Define methods which can be used by the inheriting subclass. Define abstract methods which the inheriting subclass must implement. Provide a common interface which allows the subclass to be interchanged with all other subclasses. Here's an example: package com . codetalk . abstractclass ; /** * @author Rakesh KR * */ abstract public class AbstractClass { abstract public void abstractMethod (); public void implementedMethod (){ System . out . println ( "Implemented Method" ); } final void finalMethod (){ System . out . println ( "Final Method" ); } } Here's a correct  ImplementingClass package com . codetalk . abstractclass ; /** * @author Rakesh KR * */ public ...