Posts

Showing posts from June, 2017

Use of java Class.forName

Class.forName use to load the class at run time. Which means its create instance of the class at run time, so that all static, block , variable ,class instance are available. Example: Class x=Class.forName("className");

Java class loader example

Java Classloader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. classes are only loaded on creation of an object. Three class loaders are used: Bootstrap class loader Extensions class loader System class loader The bootstrap class loader loads the core Java libraries located in the <JAVA_HOME>/jre/lib directory. This class loader, which is part of the core JVM, is written in native code. The extensions class loader loads the code in the extensions directories ( <JAVA_HOME>/jre/lib/ext , or any other directory specified by the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class. The system class loader loads code found on java.class.path, which maps to the CLASSPATH environment variable. This is implemented by the sun.misc.Launcher$AppClassLoader class.

convert string to int without parseint

Convert string to integer without using build in api Integer.parseInt()    Using this concept we can convert String to Number, String to Float, String to Double, String to short and long                                                         ASCII code of decimal number start form  48 public class ConvertStringToInt { public static void main(String[] args) { String str="-14545"; int total=0; boolean m=false; for(int i=0;i<str.length();i++){ if(str.charAt(i)=='-'){ m=true; continue; } if(str.charAt(i)=='+'){ continue; } total=(total*10)+(str.charAt(i)-48); } if(m){ total=0-total; } System.out.println(total); } }

Chance problems program

Generating Chance of getting 0 is 75% percent and 1 is 25% percent probability import java.util.Random; public class Chance { public static int getChance(){ Random randomNumber = new Random(); int randomGenerator = randomNumber.nextInt(100); System.out.println(randomGenerator); if(randomGenerator < 75) return 0; else  return 1; } public static void main(String[] args) { for(int i=0;i<10;i++){ System.out.println(Chance.getChance()); } } }

java : operator example

java : operator example public class Array2 { public static void main(String[] args) { int[] arr={1,2,3,4,5,0,0,1,3}; Outer:for(int i=0;i<arr.length;i++){ Innter: for(int j=i+1;j<arr.length;j++){ if(arr[i]==arr[j]){ System.out.println(arr[i]); break Outer; } } } /*String s="ffaghglklklh"; Outer:for(int i=0;i<s.length();i++){ Innter: for(int j=i+1;j<s.length();j++){ if(s.charAt(i)==s.charAt(j)){ System.out.println(s.charAt(i)); break Outer; } } }*/ } }

Java Outer and Inner loop example

Program to find or print first repeated/duplicate element public class Array { public static void main(String[] args) { int[] arr={1,2,3,4,5,0,0,1,3}; Outer:for(int i=0;i<arr.length;i++){ Innter: for(int j=i+1;j<arr.length;j++){ if(arr[i]==arr[j]){ System.out.println(arr[i]); break Outer; } } } /*String s="ffaghglklklh"; Outer:for(int i=0;i<s.length();i++){ Inner: for(int j=i+1;j<s.length();j++){ if(s.charAt(i)==s.charAt(j)){ System.out.println(s.charAt(i)); break Outer; } } }*/ } }

Web crawlers

Web crawlers (web spider)  is a search engines software use to traverse the Internet and to save each of the individual pages passed by along the way. Search engines then use additional software to index each of the saved pages, creating a database containing all the words in the pages. Internet search engines like Google, Yahoo and Bing can search the Internet on topic and return a list of results so quickly. Obviously it would be impossible to search all the Web pages for each request in real time. Search engine indexed Web pages into highly optimized databases and search matches the keyword each search.

java Interface

Interface An interface is similar to an abstract class. However, it can only include abstract methods and final fields (constants), and it can’t be used as a base class. Instead, a class implements an interface by providing an implementation for each method declared by the interface. Here’s a basic interface that defines a single method, named Playable, that includes a single method named play: public interface Playable { void play(); } This interface declares that any class that implements the Playable interface must provide an implementation for a method named play that accepts no parameters and doesn’t return a value. This interface has a few interesting details: ✦ The interface itself is declared as public so that it can be used by other classes. Like a public class, a public interface must be declared in a file with the same name. Thus, this interface must be in a file named Playable.java.

Java Abstract Classes

Using Abstract Classes Java lets you declare that a method or an entire class is abstract, which means that the method has no body. An abstract method is just a prototype for a method: a return type, a name, a list of parameters, and (optionally) a throws clause. To create an abstract method, you specify the modifier abstract and replace the method body with a semicolon: public abstract int hit(int batSpeed); Here, the method named hit is declared as an abstract method that returns an int value and accepts an int parameter. A class that contains at least one abstract method is called an abstract class, and must be declared with the abstract modifier on the class declaration. For example: public abstract class Ball { public abstract int hit(int batSpeed); } If you omit the abstract modifier from the class declaration, the Java compiler coughs up an error message to remind you that the class must be declared abstract.

Packages and Java Doc

PACKAGES  and JAVA DOC Packages enable you to keep your classes separate from classes in the Java API, allow you to reuse your classes in other applications, and even let you distribute your classes to others, assuming other people might be interested in your classes. If that’s the case, you probably won’t want to just send those people all your separate class files. Instead, you want to bundle them into a single file called a JAR file. Finally, you find out how to use a feature called JavaDocs that lets you add documentation comments to your classes. With JavaDocs, you can build professional looking documentation pages automatically. Your friends will think you’re a real Java guru when you post your JavaDoc pages to your Web site. Working with Packages A package is a group of classes that belong together. Without packages, the entire universe of Java classes would be a huge unorganized mess. Imagine the thousands of classes that are available in the Java API combined ...

understanding java bean with example and best explanation

Image
JAVA BEAN A JavaBean is a special type of Java class that you can use in several interesting ways to simplify program development. Some beans, such as Swing components, are designed to be visual components that you can use in a GUI editor to quickly build user interfaces. Other beans, known as Enterprise JavaBeans, are designed to run on special EJB servers and can run the data access and business logic for large Web applications. In this chapter, I look at a more modest type of JavaBean that’s designed to simplify the task of building Java Server Pages. In a nutshell, you can use the simple JavaBeans to build Java Server Pages without writing any Java code in the JSP itself. JavaBeans let you access Java classes by using special HTML-like tags in the JSP page. Features of Java Beans A JavaBean is any Java class that conforms to the following rules: ✦ It must have an empty constructor. That is, a constructor that accepts no parameters. If the class doesn’t have any constructo...

program to remove multiple white spaces from a string

Remove multiple extra white spaces from a string if in present in between a string public class WhiteSpace { public static String removeSpace(String string) { String str = ""; int length = string.length(); if (length <= 0) { return str; } boolean start = true; boolean first = false; for (int i = 0; i < length; i++) { char c = string.charAt(i); if (c == ' ') { if (start) { if(first) str += c; start = false; } }else { first=true; str += c; start = true; } } return str.trim(); } public static void main(String[] args) { String str="  g  fdf  dddd      dfd  g   sdfasdf      ff"; System.out.println(removeSpace(str)); } }

Robert bosch Interview questions

Robert Bosch Engineering and Business Solutions Koramangala Bangalore Other location: Electronic city, Bommanahalli, koramangala, adugodi, EcoSpace Bellandur, Marathahalli Interview Process:  There are Five round of interview Technical Interview 1 :  Around 1 hr                                      Self introduction                                       Explain about project roles and responsibility.                                       Some basic C,C++,Java question        ...

List of government mbbs medical entrance exams 2018

MBBS Entrance Exams – Medical Entrance Test 2018 All notification registration, last date, Exam Date. NEET (National Entrance cum Eligibility Test) Notification: Registration Date: Not yet announce Exam Date: Not yet announce Registration Link: Not yet announce  AIIMS MBBS( AIIMS MBBS entrance exam) Notification: Registration Date: Not yet announce Exam Date: Not yet announce Registration Link: Not yet announce 

How do i cancel all my pending friend requests on facebook

If you are not able to send friend request to any more. Which means you have send lots of friends request and it not yet accepted. You cant send any more request because it all pending for approval. If you cancel all pending request which are tot accepted, then you can send new request. Follow the step to cancel all pending request: Login to your Facebook account Go to your Profile Go to Activities  In activity screen you can see all your activities. here you can see friend request send  you can visit to the particular user  and you cancel send request