Posts

Click Here To View Contents

Home Page Java Fundamentals Object Oriented Programming Part-1 Object Oriented Programming Part-2 String Handling & Wrapper Classes Exception Handling Java Streams & Serialization Network Programming Collections Framwork & Generics Multithreading & Synchronization New Features From JDK 1.1 to JDK 25

String Handling & Wrapper Classes

StringTokenizer: It allows an application to break a string into tokens(words). Example: "Welcome to Java" is a one string and it has 3 tokens(words). java.util.StringTokenizer  Constructor:   public StringTokenizer(String); Methods:   public boolean hasMoreTokens(); =>It returns true if the token is present, otherwise returns false   public String nextToken(); =>It returns current token and moves the cursor to next token.   public int countTokens(); =>It returns no. of tokens. Program to count the no. of words: import java.util.*; class Demo { public static void main(String args[]) { String s="Welcome to Sathya Technologies"; StringTokenizer st=new StringTokenizer(s); int n=st.countTokens(); System.out.println(n); } } Program to iterate word by word in a given string: import java.util.*; class Demo { public static void main(String args[]) { String s="Welcome to Sathya Technologies"; St...

Java Fundamentals

Java Fundamentals Java: Java is a programming language, platform & technology. Java is called as programming language because by using Java we can write programs. Platform: It can be a software or hardware environment in which program runs. C compiler converts unicode into bit code whereas Java compiler converts unicode into byte code. JVM: JVM stands for Java Virtual Machine. It contains interpreter which converts byte code into bit code. Both compiler & interpreter are called translation softwares. Differences between compiler & interpreter: Compiler converts the whole program at a time whereas interpreter converts line by line. Compiler will produce the file whereas interpreter does not produce the file. C is a platform dependent whereas Java is a platform independent. Java is called as platform independent because programs written in Java language can be executed on any platform. Java Virtual Machine(JVM) is not a platform independent becau...

Object Oriented Programming Part-1

Image
Java is an object oriented programming language.  Object Oriented Programming Language: A language that supports all principles of an object oriented programming is known as an object oriented programming language. Object Oriented Principles: 1) Encapsulation 2) Abstraction 3) Inheritance 4) Polymorphism To use the above principles in a Java programming, we need the following language constructs: 1) Class 2) Object Class: A class is a collection of variables and methods. Object: An object is an instance of a class. Variables: A variable is a container that contains data. There are three types of variables in Java: 1) Instance Variables 2) Class Variables 3) Local Variables 1) Instance Variables: A variable that defined as a member of a class is called as an instance variable. Memory allocated to instance variables whenever an object is created. Instance variables are stored in heap area. There are two ways to access an instance variable. 1) By using obje...

Exception Handling

Errors: A program mistake is said to be an error. There are three types of errors: 1)    Compile time errors(Syntax errors) 2)    Runtime errors(Exceptions) 3)    Logical errors Runtime errors handling mechanism is called as exception handling. In exception handling we use the following keywords. 1)    try 2) catch 3) throw 4) throws 5) finally The syntax of try and catch blocks: try {          ============= => Task code }catch(ExceptionClassName ObjectReference) {          ============= => Error Message } try block must be associated with at least one catch block or finally block. All exceptions are classes in Java. Whenever exception occurs in a Java program, then the related exception class object is created by JVM, passed to exception handler(catch block) and exception handler code is executed. There are two types o...