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 Upto Java14

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

Image
Java: Java is a programming language, platform & technology. Java is called as programming language because by using Java, we can write programs. List of programming languages: C, C++, Java, Python, VC++, Visual Basic.Net, C#.Net, Small talk, Simula, Ada, .. etc., Top 5 programming languages are Java, C, Python, C++ & C# C & C++ are popular for developing system softwares Java popular for developing Internet Applications Python popular for developing Artificial Intelligence Applications C# popular for developing Graphical User Interface Applications Identifiers: Identifier is a word and it is used to identify variable, method, class, interface, package, .. etc., It can be a variable name, method name, class name, interface name, package name, .. etc., Rules to declare an identifier: 1) It can be formed by using alphabets(A to Z & a to z), digits (0 to 9), underscore symbol(_) and dollar symbol($). 2) It must begins with alphabet, underscore & d

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 object 2

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 of exceptions: 1)    Checked Exceptions 2)    Unchecked Exceptions Checked Exceptions: Ø   The exception classe

Java Streams & Serialization

Java Streams: A stream is a flow of data from source to destination. A source can be a keyboard, file, client, server, ... etc., A destination can be a monitor, file, client, server, .. etc., In Java, streams are divided into 3 categories: 1) Console Input/Output Streams 2) File Input/Output Streams 3) Network Input/Output Streams Predefined Streams: There are 3 predefined streams 1) in 2) out 3) err "in" is an object reference of java.io. InputStream class "out" & "err" are object reference of java.io.PrintStream  class. The above all predefined streams are static members of java.lang.System class. Differences between System.out & System.err System.out                                System.err 1) It is used to display           1) It is used to display       output messages.                   error messages. 2) This stream data can         2) This stream data cannot       be redirected to a file.            be redirected to