Skip to main content

Posts

Use of Static Imports in Java with Example

The main reason behind the static import feature in java5 is to reduce the unnecessary reference of class name to call static methods/fields. package   import.static.test ; import   static   java.lang.Integer.MAX_VALUE ; import   static   java.lang.Integer.MIN_VALUE ; import   static   java.lang.System.out ; public   class  StaticImportExample  {      public   static   void  main ( String  args [])   {                //without Static import          System . out . println ( "Maximum value of int variable in Java without "  + "static import : "   +  Integer . MAX_VALUE ) ;          System . out . println ( "Minimum value of int variable in Java without "  + static import : "  +  Integer . MIN_VALUE ) ;                //after static import in Java 5          out . println ( "Maximum value of int variable using "  + static import : "  + MAX_VALUE ) ;          out . println ( "Minimum value of int variab
Recent posts

Why wait() method is in object class?

Reason behind wait method present in Object class: In the Java language, you  wait()  on a particular instance of an  Object  – a monitor assigned to that object to be precise. If you want to send a signal to one thread that is waiting on that specific object instance then you call  notify()  on that object. If you want to send a signal to all threads that are waiting on that object instance, you use  notifyAll()  on that object. If  wait()  and  notify()  were on the  Thread  instead then each thread would have to know the status of every other thread. How would thread1 know that thread2 was waiting for access to a particular resource? If thread1 needed to call  thread2.notify()  it would have to somehow find out that  thread2  was waiting. There would need to be some mechanism for threads to register the resources or actions that they need so others could signal them when stuff was ready or available. In Java, the object itself is the entity that is shared between thre

Java Interview Programs

Strings: 1.) Print Duplicates of an array with one Loop statement? package com.java.testing; import java.util.HashSet; import java.util.Set; class MyClass { public static Set<Integer> commonNumbers = new HashSet<>(); public Integer digits; public MyClass(Integer digits) { this.digits=digits; } @Override public int hashCode() { return 0; } @Override public boolean equals(Object obj) { if(obj instanceof MyClass) { if(this.digits.equals(((MyClass)obj).digits)) { commonNumbers.add(((MyClass)obj).digits); return true; } } return false; } } public class ObenStringQuestion { public static void main(String[] args){ int[] mobileno = new int[]{1,8,8,8,8,8,8,1,4,2,8,2,1,1,6,2}; Set<MyClass> xx = new HashSet<>(); for(int i=0;i<mobileno.length;i++) { xx.add(new MyClass(mobileno[i])); } for (MyClass object : xx) { System.out.println(object.digits);

TOPICS OF CORE AND ADVANCED JAVA

CORE JAVA Syllabus: 1. Core Java Programming Introduction of Java Introduction to Java; features of Java Comparison with C and C++ Download and install JDK/JRE (Environment variables set up) The JDK Directory Structure First Java Program through command prompt First Java Program through Eclipse 2. Data types and Operators Primitive Datatypes, Declarations, Ranges Variable Names Conventions Numeric Literals, Character Literals String Literals Arrays(One dimensional; two- dimensional) Array of Object References Accessing arrays, manipulating arrays Enumerated Data Types Non-Primitive Datatypes Defining a class, variable and method in Java Method Signature; method calls Expressions in Java; introduction to various operators Assignment Operator Arithmetic Operators Relational Operators Logical Operators Conditional Operators Operator Precedence Implicit Type Conversions Upcasting and downcasting Strict typing Type conversion