mirror of https://github.com/deavmi/JavaOCP
Compare commits
4 Commits
49a81d95c3
...
2c05882c3a
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | 2c05882c3a | |
Tristan B. Velloza Kildaire | 7c8becec3b | |
Tristan B. Velloza Kildaire | 7e5320d360 | |
Tristan B. Velloza Kildaire | 8de71e4c8c |
|
@ -0,0 +1 @@
|
|||
/target/
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ocp.practice.basics</groupId>
|
||||
<artifactId>Operators</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<name>Operators</name>
|
||||
<description>A simple Operators.</description>
|
||||
<!-- FIXME change it to the project's website -->
|
||||
<url>http://www.example.com</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</project>
|
|
@ -0,0 +1,57 @@
|
|||
package ocp.practice.basics.Operators;
|
||||
|
||||
/**
|
||||
* Practicing operators
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
/**
|
||||
* Practice post and pre-increment
|
||||
*/
|
||||
// postIncrementAndPreIncrement();
|
||||
|
||||
/**
|
||||
* Practice the stuff below
|
||||
*/
|
||||
int a = 2; //...00010]
|
||||
int b = ~0; // 1...11]
|
||||
int c = a^b;// 1..101] // Pretty big (and negative, I'd say -3)
|
||||
System.out.println(c);
|
||||
}
|
||||
|
||||
public static void postIncrementAndPreIncrement()
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
/**
|
||||
* This is the POST-INCREMENT
|
||||
* meaning the integer is
|
||||
* increased but the value
|
||||
* returned is PRIOR to
|
||||
* incrementation
|
||||
*
|
||||
* i++
|
||||
*/
|
||||
System.out.println(i++); // 0
|
||||
|
||||
/**
|
||||
* This is the PRE-INCREMENT
|
||||
* meaning the integer is increased
|
||||
* but the value returned is,
|
||||
* is AFTER the incrementation
|
||||
*
|
||||
* ++i
|
||||
*/
|
||||
System.out.println(++i); // 2
|
||||
|
||||
/**
|
||||
* Remember it like this:
|
||||
*
|
||||
* i (then) ++ In other words, give me i, THEN increment it
|
||||
* ++ (then) i In other words, increment i, THEN give me it
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project name="Operators" xmlns="http://maven.apache.org/DECORATION/1.8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.0 http://maven.apache.org/xsd/decoration-1.8.0.xsd">
|
||||
<bannerLeft>
|
||||
<name>Operators</name>
|
||||
<src>https://maven.apache.org/images/apache-maven-project.png</src>
|
||||
<href>https://www.apache.org/</href>
|
||||
</bannerLeft>
|
||||
|
||||
<bannerRight>
|
||||
<src>https://maven.apache.org/images/maven-logo-black-on-white.png</src>
|
||||
<href>https://maven.apache.org/</href>
|
||||
</bannerRight>
|
||||
|
||||
<skin>
|
||||
<groupId>org.apache.maven.skins</groupId>
|
||||
<artifactId>maven-fluido-skin</artifactId>
|
||||
<version>1.7</version>
|
||||
</skin>
|
||||
|
||||
<body>
|
||||
<menu ref="parent" />
|
||||
<menu ref="reports" />
|
||||
</body>
|
||||
</project>
|
|
@ -0,0 +1,38 @@
|
|||
package ocp.practice.basics.Operators;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import java.io.IOException;
|
|||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringReader;
|
||||
import java.util.Arrays;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -91,5 +92,47 @@ public class App
|
|||
* Close it
|
||||
*/
|
||||
reader.close();
|
||||
|
||||
/**
|
||||
* The below is to revise a question that was asked in the
|
||||
* Java OCP exam (round 1)
|
||||
*
|
||||
* It was a loop that read into an array, a request of 8
|
||||
* bytes each time and prints out the final array or
|
||||
* something akin to that. It also loop whilst
|
||||
* the read call did not yet reach the end of file.
|
||||
*
|
||||
* Given a file in `text.txt` containing solely
|
||||
* `0123456789` (10 bytes), this should do one
|
||||
* read, then another and then stop
|
||||
*/
|
||||
File testFile = new File("text.txt");
|
||||
FileInputStream fileStream = new FileInputStream(testFile);
|
||||
reader = new BufferedReader(new InputStreamReader(fileStream));
|
||||
|
||||
/**
|
||||
* I believe they'd then print the string
|
||||
* of this array of characters each loop
|
||||
*
|
||||
* The below would print:
|
||||
*
|
||||
* 01234567 (followed by) 8901234567
|
||||
*
|
||||
* So it would print out: 012345678901234567
|
||||
*/
|
||||
char[] dataOut = new char[8];
|
||||
while(reader.read(dataOut) != -1)
|
||||
{
|
||||
System.out.print(new String(dataOut));
|
||||
}
|
||||
|
||||
// Final data will be `89234567`
|
||||
System.out.println("\nFinal data: "+Arrays.toString(dataOut));
|
||||
|
||||
/**
|
||||
* Close it all
|
||||
*/
|
||||
reader.close();
|
||||
fileStream.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
0123456789
|
|
@ -1,5 +1,7 @@
|
|||
package ocp.OOP.oop;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Playing around with enums
|
||||
*
|
||||
|
@ -52,6 +54,8 @@ public class EnumTests
|
|||
*/
|
||||
public static void go()
|
||||
{
|
||||
System.out.println("\n\n<<< begin enum tests >>>\n\n");
|
||||
|
||||
/**
|
||||
* An enum is a class-type hence every
|
||||
* instance if a reference and the constants
|
||||
|
@ -74,5 +78,11 @@ public class EnumTests
|
|||
System.out.println(b1 == b3); //false
|
||||
System.out.println(b1);
|
||||
|
||||
|
||||
BodyType[] values = BodyType.values();
|
||||
System.out.println("BodyType values: "+Arrays.toString(values));
|
||||
System.out.println("Value of: "+BodyType.valueOf("SLIM") +(BodyType.valueOf("SLIM") == BodyType.SLIM));
|
||||
|
||||
System.out.println("\n\n<<< end enum tests >>>\n\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@ package ocp.OOP.oop;
|
|||
public record SchoolGrade(Person person, int finalMark)
|
||||
{
|
||||
|
||||
// The below is NOT allowed
|
||||
// int j = 100;
|
||||
|
||||
record Thing(int i)
|
||||
{
|
||||
|
||||
|
@ -63,7 +66,7 @@ public record SchoolGrade(Person person, int finalMark)
|
|||
// {
|
||||
// person = null;
|
||||
// }
|
||||
|
||||
//
|
||||
// finalMark = 69;
|
||||
|
||||
/**
|
||||
|
@ -71,6 +74,9 @@ public record SchoolGrade(Person person, int finalMark)
|
|||
*
|
||||
* this.person = person;
|
||||
* this.finalMark = finalMark;
|
||||
*
|
||||
* NOTE: You CANNOT specify it
|
||||
* yourself if you do this!
|
||||
*/
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue